def execute(context): try: twister_runner = os.path.join(get_twister_directory(), "twister.sh") commands.execute("ln -s %s %s" % (twister_runner, os.path.join(context.args.dest, context.args.name)), output=context.args.verbose, error_text="Failed to add shortcut") commands.execute("chmod 744 %s" % twister_runner) return True except CalledProcessError: return False
def list_modules(): """ Returns the list of all modules available """ twister_directory = get_twister_directory() files = os.listdir(twister_directory) modules = [] for child_file in files: path = os.path.join(twister_directory, child_file) if not os.path.isdir(path): continue commands = os.path.join(path, COMMANDS) if os.path.exists(commands) and os.path.isfile(commands): modules.append(child_file) return modules
def load_commands_from_module(module_name): """ load commands from specified module """ twister_directory = get_twister_directory() module_path = os.path.join(twister_directory, module_name) module_commands_file_path = os.path.join(module_path, COMMANDS) module = load_py_module('%s_commands' % module_name, module_commands_file_path) commands = {} if module: for command_name, command_module_name in module.commands.items(): command_module_path = os.path.join(module_name, command_module_name) command_module_path = os.path.join(twister_directory, command_module_path) # TODO - prefer to use module loader... module = load_py_module(command_name, command_module_path) commands[command_name] = Command(module, module_name, command_name, command_module_path) return commands
def build_command_context(command, args): parser = argparse.ArgumentParser(add_help=False) parser.add_argument(TWISTED_PATH_ARG) parser.add_argument(PROJECT_PATH_ARG) parser.add_argument("--verbose", action="store_true") parsed_args, unknown = parser.parse_known_args() # use use-project-path and use-twisted-path to specify value, but remove from parsed args project_path = parsed_args.use_project_path twisted_path = parsed_args.use_twisted_path twister_directory = get_twister_directory() if not project_path: # use the $PROJECT_PATH env var project_path = os.environ.get('PROJECT_PATH') if not project_path: # the default one is parent directory project_path = os.path.dirname(twister_directory) if not twisted_path: # use the $TWISTED_PATH env var twisted_path = os.environ.get("TWISTED_PATH") if not twisted_path: # the default one is twisted directory in parent directory twisted_path = os.path.join(os.path.dirname(twister_directory), "twisted") if not os.path.exists(twisted_path): os.mkdir(twisted_path) print "Created twisted directory: %s" % twisted_path elif not os.path.isdir(twisted_path): print "%s is not directory" % twisted_path exit(-1) if parsed_args.verbose: log.info("Detected command: %s" % str(command)) log.info("Use project at %s" % project_path) log.info("Use twisted at %s" % twisted_path) command_args = get_command_arguments(args) parsed_args = command.get_arg_parser().parse_args(command_args) return Context(command=command, twisted_path=twisted_path, project_path=project_path, args=parsed_args)
# -*- coding: utf8 -*- import os from twister import get_twister_directory ALIAS = "alias" ALIASES = os.path.join(get_twister_directory(), ALIAS) def load_aliases(): """ Loads the list of available aliases from special file """ alias_file = open(ALIASES, 'r') aliases = {} for line in alias_file.readlines(): line = line.strip() if line.startswith("#") or len(line) == 0: # skip comments and empty lines continue # read alias info = line.split("=", 1) if len(info) == 2: aliases[info[0]] = info[1] alias_file.close() return aliases