예제 #1
0
 def test_saveJson(self):
     ProjectsDAO.save_projects(self.create_projects_obj(), db_path=test_db)
     with open(test_db, "r") as db:
         obj = json.load(db)
         self.assertEquals(obj["project1"], {"path": "/home/tests/project1", "type": "mvn_project"})
         self.assertEquals(obj["project2"], {"path": "/home/tests/project2", "type": "mvn_project"})
         self.assertEquals(obj["project3"], {"path": "/home/tests/project3", "type": "mvn_project"})
예제 #2
0
    def test_add(self):
        ProjectsDAO.save_projects(self.create_projects_obj(), db_path=test_db)

        ProjectsDAO.add_project("append", "/home/append", "mvn_project", db_path=test_db)

        read = ProjectsDAO.get_projects(db_path=test_db)
        self.assertEquals(read["project1"], {"path": "/home/tests/project1", "type": "mvn_project"})
        self.assertEquals(read["project2"], {"path": "/home/tests/project2", "type": "mvn_project"})
        self.assertEquals(read["project3"], {"path": "/home/tests/project3", "type": "mvn_project"})
        self.assertEquals(read["append"], {"path": "/home/append", "type": "mvn_project"})
예제 #3
0
def get_project_path_and_type(module_name):
    try:
        projects = ProjectsDAO.get_projects()
        return projects[module_name]["path"], projects[module_name]["type"]
    except KeyError:
        msg = "Path not found for project [%s]" % module_name
        raise Exception(msg)
예제 #4
0
def validate_modules_exists(commands):
    projects = ProjectsDAO.get_projects()

    wrong_modules_names = filter(lambda command: command.target_module not in projects.keys(), commands)
    if len(wrong_modules_names):
        msg = "Unknown modules keys=%s" % str(map(lambda cmd: cmd.target_module, wrong_modules_names))
        raise Exception(msg)
예제 #5
0
    def get_actions(self):
        actions = []
        last_used_mods = []
        if 'ordered_args' not in dir(self.parsed):
            self.arg_parser.parse_args(['-h'])
            return
        for (action_key, modules) in self.parsed.ordered_args:
            arguments = map(lambda arg: arg[1:], filter(lambda arg: arg[0] == '@', modules))
            action_modules = filter(lambda mod: mod[0] != '@', modules)
            if len(action_modules) == 0:
                if len(last_used_mods) == 0:
                    raise Exception("None module pressed")
                action_modules = last_used_mods
            else:
                if "all" in action_modules:
                    action_modules = [x[0] for x in ProjectsDAO.get_projects().items() if x[1]['type'] == 'mvn_project']
                last_used_mods = action_modules

            for module in action_modules:
                actions.append(Action(target_module=module, action=action_key, arguments=arguments))
        return actions
def run(parsed_args):
    # print parsed_args

    if 'ordered_args' not in dir(parsed_args):
        return False

    provided_special_cmds = [x[0] for x in parsed_args.ordered_args]

    if 'show-projects' in provided_special_cmds:
        ProjectsDAO.print_available_projects()
        return True

    if 'search-projects' in provided_special_cmds:
        entry = __get_entry_for_argument__(parsed_args,'search-projects')
        __check_args_available__(entry, ['project_key'])
        key = entry[1][0]
        for (p_key, p_path, p_type)  in ProjectsDAO.search_matching_projects(key):
            print "%25s [%s]" % ("[" + p_key + "](" + p_type + ")", p_path)
        return True

    if 'autoscan' in provided_special_cmds:
        entry = __get_entry_for_argument__(parsed_args,'autoscan')
        __check_args_available__(entry, ['path'])
        ProjectsDAO.autodetect_and_save_projects(__get_full_path__(entry[1][0]))
        return True

    if 'add-mvn-project' in provided_special_cmds:
        entry = __get_entry_for_argument__(parsed_args, 'add-mvn-project')
        __check_args_available__(entry, ['project_key', 'path'])
        ProjectsDAO.add_mvn_project(project_key=entry[1][0], project_path=__get_full_path__(entry[1][1]))
        return True

    if 'add-script' in provided_special_cmds:
        entry = __get_entry_for_argument__(parsed_args, 'add-script')
        __check_args_available__(entry, ['project_key', 'path_to_exec'])
        ProjectsDAO.add_script(project_key=entry[1][0], project_path=__get_full_path__(entry[1][1]))
        return True

    if 'remove-project' in provided_special_cmds:
        entry = __get_entry_for_argument__(parsed_args, 'remove-project')
        __check_args_available__(entry, ['project_key'])
        ProjectsDAO.remove_project(project_key=entry[1][0])
        return True

    return False