Skip to content
This repository was archived by the owner on Feb 21, 2019. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
os:
- linux
language: python
python:
# - "2.6"
# - "2.7"
# - "3.3"
- "3.4"
- "3.5"
- "3.5-dev" # 3.5 development branch
- "3.6"
- "3.6-dev" # 3.6 development branch
# - "3.7-dev" # 3.7 development branch
# command to install dependencies
install:
- pip install --upgrade pip
- pip install coverage
- pip install python-coveralls
- pip install pytest
- pip install pytest-cov
- pip install pytest-pep8
- pip install -r requirements.txt
script:
- python setup.py install
- pytest -v --cov-report term-missing --pep8 # or py.test for Python versions 3.5 and below
after_success:
# - coveralls
22 changes: 14 additions & 8 deletions deploy/deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
cli_root_dir = os.path.dirname(this_dir)
module_json = os.path.join(cli_root_dir, 'module.json')


def main():
'''
This script updates, versions, and builds new versions of the Kubos CLI.
Expand Down Expand Up @@ -68,10 +69,11 @@ def get_module_version():
def bump_and_write_version(version):
version_fields = version.split('.')

if len(version_fields) == 4: #Add a patch number
version_fields[3] = str(int(version_fields[3]) + 1) #bump the version number by 1 and store it as a string
if len(version_fields) == 4: # Add a patch number
# bump the version number by 1 and store it as a string
version_fields[3] = str(int(version_fields[3]) + 1)
version = '.'.join(version_fields)
elif len(version_fields) == 3:# bump the version number
elif len(version_fields) == 3: # bump the version number
version = version + '.1'

with open(module_json, 'r') as module_file:
Expand All @@ -84,19 +86,23 @@ def bump_and_write_version(version):
sort_keys=True,
indent=4,
separators=(',', ': '))
)
)
return version


def commit_and_push(version_number):
run_cmd('git', 'config', '--global', 'user.name', os.environ['GITHUB_USERNAME'])
run_cmd('git', 'config', '--global', 'user.email', os.environ['GITHUB_EMAIL'])
run_cmd('git', 'config', '--global', 'user.name',
os.environ['GITHUB_USERNAME'])
run_cmd('git', 'config', '--global',
'user.email', os.environ['GITHUB_EMAIL'])
run_cmd('git', 'add', 'module.json')
print 'Committing the version update...'
run_cmd('git', 'commit', '-m', '"Bump version to %s. [ci skip]"' % version_number) #we want ci to skip to prevent an infinite release cycle.
# we want ci to skip to prevent an infinite release cycle.
run_cmd('git', 'commit', '-m',
'"Bump version to %s. [ci skip]"' % version_number)

print 'Pushing the commit to origin...'
run_cmd('git', 'push', 'origin', 'master') #push the commit
run_cmd('git', 'push', 'origin', 'master') # push the commit


def build_wheel():
Expand Down
33 changes: 17 additions & 16 deletions deploy/release.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,20 +43,21 @@ def create_release(version):
This function returns the URI template for uploading a release asset
'''
headers = {
'Content-type': 'application/json',
'Accept': 'application/json'
}

data = {
'tag_name': version,
'target_commitish': 'master',
'name': version,
'body': '',
'Content-type': 'application/json',
'Accept': 'application/json'
}

data = {
'tag_name': version,
'target_commitish': 'master',
'name': version,
'body': '',
'draft': False,
'prerelease': False
}
}

res = requests.post(release_endpoint, auth=auth, headers=headers, data=json.dumps(data))
res = requests.post(release_endpoint, auth=auth,
headers=headers, data=json.dumps(data))
res.raise_for_status()
return res.json()['upload_url']

Expand All @@ -67,9 +68,9 @@ def upload_wheel(version, uri_template):
'''
print 'Uploading the wheel build...'
headers = {
'Content-type': 'application/octet-stream',
'Accept': 'application/json'
}
'Content-type': 'application/octet-stream',
'Accept': 'application/json'
}

template = URITemplate(uri_template)
wheel_path = get_wheel_file_path()
Expand All @@ -84,7 +85,8 @@ def get_wheel_file_path():
dist_dir = os.path.join(this_dir, '..', 'dist')
if os.path.isdir(dist_dir):
for _file in os.listdir(dist_dir):
if _file.endswith('.whl'): #Running in a CD environment, there will only be a single wheel build in the dist/ folder
# Running in a CD environment, there will only be a single wheel build in the dist/ folder
if _file.endswith('.whl'):
return os.path.join(dist_dir, _file)
print 'Unable to find the wheel build under directory %s.. Aborting.' % dist_dir
sys.exit(1)
Expand All @@ -93,4 +95,3 @@ def get_wheel_file_path():
def github_release(version):
uri_template = create_release(version)
upload_wheel(version, uri_template)

52 changes: 23 additions & 29 deletions kubos/completion/complete.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import sys
import os


def main():
'''
This script works by coming up with a list of possible completions and printing
Expand All @@ -19,19 +20,20 @@ def main():


class Completer(object):
JSON_FILE = os.path.join(os.path.expanduser('~'), '.kubos', 'completion', 'options.json')
JSON_FILE = os.path.join(os.path.expanduser(
'~'), '.kubos', 'completion', 'options.json')

def __init__(self):
if os.path.isfile(self.JSON_FILE):
with open(self.JSON_FILE, 'r') as _fil:
self.arg_data = json.loads(_fil.read())
else:
self.arg_data = None
self.args = sys.argv[2:] #chop off the initial 'python kubos' arguments
# chop off the initial 'python kubos' arguments
self.args = sys.argv[2:]
self.subcommands = self.get_current_subcommands()
self.load_targets()


def load_targets(self):
'''
Load the available targets, based on the current project's platform type
Expand All @@ -40,13 +42,11 @@ def load_targets(self):
targets = self.load_target_list(platform)
self.arg_data['subcommands']['target']['set_target']['choices'] = targets


def get_completions(self):
# Only completing the subcommands and their args is supported right now.
# Completing the global options (--config, --target, etc.) should be supported in the future.
return self.eval_subcommands()


def eval_subcommands(self):
'''
Returns list of possible subcommand, and subcommand specific arguments based
Expand All @@ -57,27 +57,29 @@ def eval_subcommands(self):
'''
num_args = len(self.args)
if num_args == 0:
#nothing has been entered - return every subcommand
# nothing has been entered - return every subcommand
return self.subcommands
else:
possible_arguments = []
#get all the possible subcommand completions for the entered text
# get all the possible subcommand completions for the entered text
possible_subcommands = self.get_current_subcommand_completion()
subcommand = self.get_current_subcommand()
if subcommand is not None:
#gets all possible argument values for the subcommand
possible_arguments = self.get_valid_subcommand_argument_list(subcommand)
#try to get an argument following the subcommand
# gets all possible argument values for the subcommand
possible_arguments = self.get_valid_subcommand_argument_list(
subcommand)
# try to get an argument following the subcommand
arg = self.get_next_arg()
if arg is not None:
#drop other subcommand completions - they're already typing an argument for the subcommand
# drop other subcommand completions - they're already typing an argument for the subcommand
possible_subcommands = []
possible_arguments = self.get_completions_from_list(arg, possible_arguments)
possible_arguments = self.get_completions_from_list(
arg, possible_arguments)
if self.is_valid_subcommand_arg(subcommand, arg):
return [] #if we've already completed a complete and valid argument, stop suggesting it.
# if we've already completed a complete and valid argument, stop suggesting it.
return []
return possible_arguments + possible_subcommands


def get_completions_from_list(self, val, option_list):
'''
Generic function for returning all values from option_list that start with
Expand All @@ -89,15 +91,13 @@ def get_completions_from_list(self, val, option_list):
ret_list.append(option)
return ret_list


def get_current_subcommand_completion(self):
'''
Returns all possible subcommand name completions for the next argument
'''
arg_val = self.args[0] #we should get the subcommand name first
arg_val = self.args[0] # we should get the subcommand name first
return self.get_completions_from_list(arg_val, self.subcommands)


def get_next_arg(self):
'''
pop the next arg off the front of the provided arguments and return it
Expand All @@ -106,7 +106,6 @@ def get_next_arg(self):
return self.args.pop(0)
return None


def get_current_subcommand(self):
'''
Returns the subcommand name if next argument is a valid subcommand or None if it isn't
Expand All @@ -117,7 +116,6 @@ def get_current_subcommand(self):
else:
return None


def is_valid_subcommand_arg(self, subcommand, arg):
'''
Returns True if arg is a valid argument for subcommand, otherwise it returns False
Expand All @@ -127,7 +125,6 @@ def is_valid_subcommand_arg(self, subcommand, arg):
return True
return False


def get_valid_subcommand_argument_list(self, subcommand):
'''
Returns a list of the valid argument completions for subcommand.
Expand All @@ -144,7 +141,6 @@ def get_valid_subcommand_argument_list(self, subcommand):
choices += args[arg]['choices']
return choices


def get_current_subcommands(self):
'''
This function contains the try/except because it's the first function
Expand All @@ -157,7 +153,6 @@ def get_current_subcommands(self):
except TypeError:
sys.exit(1)


################################################################
# CLI DUPLICATED FUNCTIONS
################################################################
Expand All @@ -178,22 +173,22 @@ def get_platform(self):
else:
return 'linux'
else:
#This project doesn't have a dependencies field. This is most likely running in a unit testing context
# This project doesn't have a dependencies field. This is most likely running in a unit testing context
return None
else:
#There is no module.json
# There is no module.json
return None


def load_target_list(self, platform):
KUBOS_TARGET_CACHE_FILE = os.path.join(os.path.expanduser('~'), '.kubos', 'targets.json')
KUBOS_TARGET_CACHE_FILE = os.path.join(
os.path.expanduser('~'), '.kubos', 'targets.json')
if not os.path.isfile(KUBOS_TARGET_CACHE_FILE):
return None
with open(KUBOS_TARGET_CACHE_FILE, 'r') as json_file:
data = json.loads(json_file.read())
linux_targets = data['linux-targets']
rt_targets = data['rt-targets']
if platform == None: #if no platform is listed in the module.json, dont restrict the target type
rt_targets = data['rt-targets']
if platform == None: # if no platform is listed in the module.json, dont restrict the target type
return linux_targets + rt_targets
elif platform == 'linux':
return linux_targets
Expand All @@ -203,4 +198,3 @@ def load_target_list(self, platform):

if __name__ == '__main__':
main()

34 changes: 21 additions & 13 deletions kubos/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,32 +27,40 @@
from kubos.utils.constants import KUBOS_RT_EXAMPLE_DIR, KUBOS_LINUX_EXAMPLE_DIR, KUBOS_SRC_DIR
from kubos.utils import sdk_utils


def addOptions(parser):
parser.add_argument('proj_name', nargs=1, help='specify the project name')
group = parser.add_mutually_exclusive_group()
group.add_argument('-l', '--linux', action='store_true', help='Initialize Kubos SDK project for KubOS Linux')
group.add_argument('-r', '--rt', action='store_true', default=True, help='Initialize Kubos SDK project for KubOS RT')
group.add_argument('-l', '--linux', action='store_true',
help='Initialize Kubos SDK project for KubOS Linux')
group.add_argument('-r', '--rt', action='store_true', default=True,
help='Initialize Kubos SDK project for KubOS RT')


def execCommand(args, following_args):
proj_name = vars(args)['proj_name'][0] #vars returns a dict of args. proj_name is a list since nargs=1
# vars returns a dict of args. proj_name is a list since nargs=1
proj_name = vars(args)['proj_name'][0]
logging.info('Initializing project: %s ...' % proj_name)
proj_name_dir = os.path.join(os.getcwd(), proj_name)

if os.path.isdir(proj_name_dir):
logging.warning('The project directory %s already exists. Not overwritting the current directory' % proj_name_dir)
logging.warning(
'The project directory %s already exists. Not overwritting the current directory' % proj_name_dir)
sys.exit(1)

#Copy in the correct example directory based on the desired OS
# Copy in the correct example directory based on the desired OS
example_dir = KUBOS_LINUX_EXAMPLE_DIR if args.linux else KUBOS_RT_EXAMPLE_DIR
shutil.copytree(example_dir, proj_name_dir, ignore=shutil.ignore_patterns('.git'))
shutil.copytree(example_dir, proj_name_dir,
ignore=shutil.ignore_patterns('.git'))

#change project name in module.json
# change project name in module.json
module_json = os.path.join(proj_name_dir, 'module.json')
with open(module_json, 'r') as init_module_json:
module_data = json.load(init_module_json)
module_data['name'] = proj_name
module_data['repository']['url'] = 'git://<repository_url>' #These fields print warnings if they're
module_data['homepage'] = 'https://<homepage>' #left empty
# These fields print warnings if they're
module_data['repository']['url'] = 'git://<repository_url>'
module_data['homepage'] = 'https://<homepage>' # left empty
with open(module_json, 'w') as final_module_json:
str_module_data = json.dumps(module_data,
indent=4,
Expand All @@ -61,7 +69,7 @@ def execCommand(args, following_args):
os.chdir(proj_name_dir)
sdk_utils.link_global_cache_to_project(proj_name_dir)

#remove the troublesome rt dependencies if needed
# remove the troublesome rt dependencies if needed
proj_type = sdk_utils.get_project_type()
if proj_type == 'rt':
remove_unruly_rt_dependencies()
Expand All @@ -75,13 +83,15 @@ def remove_unruly_rt_dependencies():
are initialized.
'''

dependency_list = ['cmocka'] #add new module names to the list if new build issues are found in the future.
# add new module names to the list if new build issues are found in the future.
dependency_list = ['cmocka']

for dep in dependency_list:
path = os.path.join(os.getcwd(), 'yotta_modules', dep)
if os.path.islink(path):
os.unlink(path)


def get_target_list():
'''
This is a helper function for getting a list of all the globally linked
Expand All @@ -97,5 +107,3 @@ def get_target_list():
data = json.load(json_file)
available_target_list.append(data['name'])
return available_target_list


Loading