Example #1
0
 def run_command(self, command):
     recipe = self._get_recipe(command)
     if len(recipe) == 0:
         raise PykeError("{0}: Invalid command \"{1}\"".format(
             t.make_project_name(self.name), t.make_command(command.name)))
     for step in recipe:
         step_name = "{0}.{1}.{2}".format(t.make_project_name(self.name),
                                          t.make_command(command.name),
                                          t.make_step(step))
         step_name_nc = "{0}.{1}.{2}".format(self.name, command.name, step)
         print("Running {0}:".format(t.make_step(step_name)))
         try:
             self._run_op(command, step)
         finally:
             timer.mark("Run '{}'".format(step_name_nc))
Example #2
0
    def _run_op_config(self, command):
        if 'configurations' not in self.json_data:
            raise ValueError("No configurations defined in {0}.".format(t.make_project_name(self.name)))

        for config_cmds in command.children:
            name = config_cmds.name
            self._apply_config(name)
Example #3
0
 def _run_op_config(self, command):
     for name, proj in self.depends_on.items():
         print ("Running {} on dependent project {}".format(
             t.make_command(command.name),
             t.make_project_name(name)))
         proj.run_command(command)
     super()._run_op_config(command)
Example #4
0
            def downward_recurse(path):
                if self.all_projects_found or self.exhausted:
                    return


#                print ("Searching {0}".format(path))

# if we ended a search here, we don't want to re-process this pyke.json
                skip_this_file = False
                if path in self.past_dirs:
                    skip_this_file = True
                else:
                    self.past_dirs.add(path)

                file_path = os.path.join(path, "pyke.json")
                json_data = None

                # look for pyke.json, unless we ended a previous search here
                if os.path.exists(file_path):
                    with open(file_path) as f:
                        json_data = json.loads(f.read())
                        #                        print ("Found JSON:\n{0}".format(json_data))

                        # we would skip earlier, but we want the json data to get depends-on
                        if "projects" in json_data and skip_this_file == False:
                            for proj_json in json_data["projects"]:
                                print("Loading project - {0}".format(
                                    t.make_project_name(proj_json["name"])))
                                np = self.make_new_project(path, proj_json)
                                timer.mark("Load project '{}'".format(np.name))
                                key = "{0}/{1}".format(path, np.name)

                                self.projects_in_order.append((key, np))
                                self.projects_by_path[key] = np
                                if np.name not in self.projects_by_name:
                                    self.projects_by_name[np.name] = list()
                                self.projects_by_name[np.name].append(np)

                                if np.name in target_names:
                                    #                                    print ("Found target: {0}".format(np.name))
                                    target_names.remove(np.name)

                                    if "depends-on" in proj_json:
                                        for dep in proj_json["depends-on"]:
                                            if dep not in self.projects_by_name:
                                                #                                                print ("New target from {1}: {0}".format(dep, np.name))
                                                target_names.add(dep)

                                if len(target_names) == 0:
                                    self.all_projects_found = True

                # look down the hierarchy if we have dependencies
                if self.all_projects_found == False:
                    if json_data != None and "depends-on" in json_data:
                        for subdir in json_data["depends-on"]:
                            down_path = os.path.join(path, subdir)
                            if down_path not in self.past_dirs:
                                downward_recurse(os.path.join(path, subdir))
                                if self.all_projects_found:
                                    break
Example #5
0
 def _apply_config(self, name):
     if name not in self.json_data['configurations']:
         raise ValueError(
             "No configuration named {0} defined in {1}.".format(
                 t.make_configuration(name),
                 t.make_project_name(self.name)))
     print("Applying configuration {}.".format(t.make_configuration(name)))
     self._apply_json_additive(self.json_data['configurations'][name])
Example #6
0
    def _run_op_config(self, command):
        if 'configurations' not in self.json_data:
            raise ValueError("No configurations defined in {0}.".format(
                t.make_project_name(self.name)))

        for config_cmds in command.children:
            name = config_cmds.name
            self._apply_config(name)
Example #7
0
 def run_command(self, command):
     recipe = self._get_recipe(command)
     if len(recipe) == 0:
         raise PykeError("{0}: Invalid command \"{1}\"".format(
             t.make_project_name(self.name),
             t.make_command(command.name)))
     for step in recipe:
         step_name = "{0}.{1}.{2}".format(
             t.make_project_name(self.name),
             t.make_command(command.name),
             t.make_step(step))
         step_name_nc = "{0}.{1}.{2}".format(self.name, command.name, step)
         print ("Running {0}:".format(t.make_step(step_name)))
         try:
             self._run_op(command, step)
         finally:
             timer.mark("Run '{}'".format(step_name_nc))
Example #8
0
 def _apply_config(self, name):
     if name not in self.json_data['configurations']:
         raise ValueError("No configuration named {0} defined in {1}.".format(
             t.make_configuration(name),
             t.make_project_name(self.name)))
     print ("Applying configuration {}.".format(
         t.make_configuration(name)))
     self._apply_json_additive(self.json_data['configurations'][name])
Example #9
0
            def downward_recurse(path):
                if self.all_projects_found or self.exhausted:
                    return
                
#                print ("Searching {0}".format(path))

                # if we ended a search here, we don't want to re-process this pyke.json
                skip_this_file = False
                if path in self.past_dirs:
                    skip_this_file = True
                else:
                    self.past_dirs.add(path)

                file_path = os.path.join(path, "pyke.json")
                json_data = None

                # look for pyke.json, unless we ended a previous search here
                if os.path.exists(file_path):
                    with open(file_path) as f:
                        json_data = json.loads(f.read())
#                        print ("Found JSON:\n{0}".format(json_data))
                        
                        # we would skip earlier, but we want the json data to get depends-on
                        if "projects" in json_data and skip_this_file == False:
                            for proj_json in json_data["projects"]:
                                print ("Loading project - {0}".format(t.make_project_name(proj_json["name"])))
                                np = self.make_new_project(path, proj_json)
                                timer.mark("Load project '{}'".format(np.name))
                                key = "{0}/{1}".format(path, np.name)
                                
                                self.projects_in_order.append((key, np))
                                self.projects_by_path[key] = np
                                if np.name not in self.projects_by_name:
                                    self.projects_by_name[np.name] = list()
                                self.projects_by_name[np.name].append(np)
                                
                                if np.name in target_names:
#                                    print ("Found target: {0}".format(np.name))
                                    target_names.remove(np.name)

                                    if "depends-on" in proj_json:
                                        for dep in proj_json["depends-on"]:
                                            if dep not in self.projects_by_name:
#                                                print ("New target from {1}: {0}".format(dep, np.name))
                                                target_names.add(dep)

                                if len(target_names) == 0:
                                    self.all_projects_found = True
                
                # look down the hierarchy if we have dependencies
                if self.all_projects_found == False:
                    if json_data != None and "depends-on" in json_data:
                        for subdir in json_data["depends-on"]:
                            down_path = os.path.join(path, subdir)
                            if down_path not in self.past_dirs:
                                downward_recurse(os.path.join(path, subdir))
                                if self.all_projects_found:
                                    break
Example #10
0
    def _run_op_build(self, command):
        for name, proj in self.depends_on.items():
            print("Running {} on dependent project {}".format(
                t.make_command(command.name), t.make_project_name(name)))
            proj.run_command(command)

        data = cpp_data(self, self.json_data)
        self.tool.set_cpp_data(data)
        self.tool.build_project()
Example #11
0
    def _run_op_build(self, command):
        for name, proj in self.depends_on.items():
            print ("Running {} on dependent project {}".format(
                t.make_command(command.name),
                t.make_project_name(name)))
            proj.run_command(command)

        data = cpp_data(self, self.json_data)
        self.tool.set_cpp_data(data)
        self.tool.build_project()
Example #12
0
    def _run_op_describe(self, command):
        verbose = False
        for switch in command.children:
            if switch.name == "verbose":
                verbose = True
            if switch.name == "terse":
                verbose = False

        print ("")
        if verbose:
            print ('=' * 60)
        print ("Project {0}\nat {1}\nType: {2}\nVersion: {3}\n".format(
            t.make_project_name(self.name),
            t.make_project_path(self.path),
            t.make_project_type(self.project_type),
            self.json_data['version']))
        
        print (self.json_data['doc']['short'])

        print ("\nAvailable commands:")

        if 'commands' in self.json_data:
            for cmd in self.json_data['commands']:
                cmd_name = cmd['name']
                print ("\t{0}: {1}".format(
                    t.make_command(cmd_name),
                    cmd['doc']['short']))
                for arg in cmd['doc']['args']:
                    arg_name = arg['name']
                    print ("\t\t{0}: {1}".format(
                        t.make_command_arg(arg_name), 
                        arg['short']))
                    if verbose and 'long' in arg:
                        print ("\t\t{0}".format(
                        t.make_command_arg_doc(arg['long'])))

                if verbose and 'long' in cmd['doc']:
                    print ("\t{0}\n".format(
                    t.make_command_doc(cmd['doc']['long'])))
        
        if verbose and 'long' in self.json_data['doc']:
            print (self.json_data['doc']['long'])
            
        if verbose:
            print ('=' * 60)
        print ("")
Example #13
0
    def _run_op_describe(self, command):
        verbose = False
        for switch in command.children:
            if switch.name == "verbose":
                verbose = True
            if switch.name == "terse":
                verbose = False

        print("")
        if verbose:
            print('=' * 60)
        print("Project {0}\nat {1}\nType: {2}\nVersion: {3}\n".format(
            t.make_project_name(self.name), t.make_project_path(self.path),
            t.make_project_type(self.project_type), self.json_data['version']))

        print(self.json_data['doc']['short'])

        print("\nAvailable commands:")

        if 'commands' in self.json_data:
            for cmd in self.json_data['commands']:
                cmd_name = cmd['name']
                print("\t{0}: {1}".format(t.make_command(cmd_name),
                                          cmd['doc']['short']))
                for arg in cmd['doc']['args']:
                    arg_name = arg['name']
                    print("\t\t{0}: {1}".format(t.make_command_arg(arg_name),
                                                arg['short']))
                    if verbose and 'long' in arg:
                        print("\t\t{0}".format(
                            t.make_command_arg_doc(arg['long'])))

                if verbose and 'long' in cmd['doc']:
                    print("\t{0}\n".format(
                        t.make_command_doc(cmd['doc']['long'])))

        if verbose and 'long' in self.json_data['doc']:
            print(self.json_data['doc']['long'])

        if verbose:
            print('=' * 60)
        print("")
Example #14
0
def run_project(command):
#    print ("Finding project {0}:".format(command.name))
    projects.load_until(command.name)

    if command.name in projects.projects_by_name:
        proj = projects.projects_by_name[command.name][0]
#        print ("Using {0}".format(proj.name))

        if len(command.children) > 0:
            for cmd in command.children:
                try:
                    proj.run_command(cmd)
                except PykeError as ve:
                    print ("{0}: {1}".format(t.make_error('Error'), ve))
                    break
        else:
            c = com.command("describe", command)
            command.children.append(c)
            proj.run_command(c)
    else:
        raise PykeError("Unable to find project \"{0}\".".format(t.make_project_name(command.name)))
Example #15
0
    def load_until(self, target_proj_name):
        target_names = set()
        
        def check_depends(proj):
            for dname in proj.depends_on:
                if dname not in self.projects_by_name:
                    target_names.add(dname)
                else:
                    # Just reference the first one.
                    proj_dep = self.projects_by_name[dname][0]
                    check_depends(proj_dep)
        if target_proj_name in self.projects_by_name:
            for proj in self.projects_by_name[target_proj_name]:
                check_depends(proj)
        else:
            target_names.add(target_proj_name)
            
#        print ("targets: {0}".format(" ".join(target_names)))
        
        self.all_projects_found = False
        if len(target_names) == 0:
            self.all_projects_found = True

        json_path = self.current_dir
        
        def upward_recurse(path):
            def downward_recurse(path):
                if self.all_projects_found or self.exhausted:
                    return
                
#                print ("Searching {0}".format(path))

                # if we ended a search here, we don't want to re-process this pyke.json
                skip_this_file = False
                if path in self.past_dirs:
                    skip_this_file = True
                else:
                    self.past_dirs.add(path)

                file_path = os.path.join(path, "pyke.json")
                json_data = None

                # look for pyke.json, unless we ended a previous search here
                if os.path.exists(file_path):
                    with open(file_path) as f:
                        json_data = json.loads(f.read())
#                        print ("Found JSON:\n{0}".format(json_data))
                        
                        # we would skip earlier, but we want the json data to get depends-on
                        if "projects" in json_data and skip_this_file == False:
                            for proj_json in json_data["projects"]:
                                print ("Loading project - {0}".format(t.make_project_name(proj_json["name"])))
                                np = self.make_new_project(path, proj_json)
                                timer.mark("Load project '{}'".format(np.name))
                                key = "{0}/{1}".format(path, np.name)
                                
                                self.projects_in_order.append((key, np))
                                self.projects_by_path[key] = np
                                if np.name not in self.projects_by_name:
                                    self.projects_by_name[np.name] = list()
                                self.projects_by_name[np.name].append(np)
                                
                                if np.name in target_names:
#                                    print ("Found target: {0}".format(np.name))
                                    target_names.remove(np.name)

                                    if "depends-on" in proj_json:
                                        for dep in proj_json["depends-on"]:
                                            if dep not in self.projects_by_name:
#                                                print ("New target from {1}: {0}".format(dep, np.name))
                                                target_names.add(dep)

                                if len(target_names) == 0:
                                    self.all_projects_found = True
                
                # look down the hierarchy if we have dependencies
                if self.all_projects_found == False:
                    if json_data != None and "depends-on" in json_data:
                        for subdir in json_data["depends-on"]:
                            down_path = os.path.join(path, subdir)
                            if down_path not in self.past_dirs:
                                downward_recurse(os.path.join(path, subdir))
                                if self.all_projects_found:
                                    break
                
            downward_recurse(path)

            if self.all_projects_found == False and not self.exhausted:
                (_, basepath) = os.path.splitdrive(path)
                if basepath != "/":
                    path = os.path.normpath(os.path.join(path, ".."))
                    upward_recurse(path)
                else:
                    self.exhausted = True

        upward_recurse(json_path)

        if target_proj_name in self.projects_by_name:
            def load_deps(parent_proj):
                for name, proj in parent_proj.depends_on.items():
                    if proj == None:
                        self.load_until(name)
                        proj = self.projects_by_name[name][0]
                        #print (proj)
                        parent_proj.depends_on[name] = proj
                        load_deps(proj)
            load_deps(self.projects_by_name[target_proj_name][0])
        else:
            raise PykeError("Project {} not found.".format(t.make_project_name(target_proj_name)))
Example #16
0
 def _run_op_config(self, command):
     for name, proj in self.depends_on.items():
         print("Running {} on dependent project {}".format(
             t.make_command(command.name), t.make_project_name(name)))
         proj.run_command(command)
     super()._run_op_config(command)
Example #17
0
    def load_until(self, target_proj_name):
        target_names = set()

        def check_depends(proj):
            for dname in proj.depends_on:
                if dname not in self.projects_by_name:
                    target_names.add(dname)
                else:
                    # Just reference the first one.
                    proj_dep = self.projects_by_name[dname][0]
                    check_depends(proj_dep)

        if target_proj_name in self.projects_by_name:
            for proj in self.projects_by_name[target_proj_name]:
                check_depends(proj)
        else:
            target_names.add(target_proj_name)

#        print ("targets: {0}".format(" ".join(target_names)))

        self.all_projects_found = False
        if len(target_names) == 0:
            self.all_projects_found = True

        json_path = self.current_dir

        def upward_recurse(path):
            def downward_recurse(path):
                if self.all_projects_found or self.exhausted:
                    return


#                print ("Searching {0}".format(path))

# if we ended a search here, we don't want to re-process this pyke.json
                skip_this_file = False
                if path in self.past_dirs:
                    skip_this_file = True
                else:
                    self.past_dirs.add(path)

                file_path = os.path.join(path, "pyke.json")
                json_data = None

                # look for pyke.json, unless we ended a previous search here
                if os.path.exists(file_path):
                    with open(file_path) as f:
                        json_data = json.loads(f.read())
                        #                        print ("Found JSON:\n{0}".format(json_data))

                        # we would skip earlier, but we want the json data to get depends-on
                        if "projects" in json_data and skip_this_file == False:
                            for proj_json in json_data["projects"]:
                                print("Loading project - {0}".format(
                                    t.make_project_name(proj_json["name"])))
                                np = self.make_new_project(path, proj_json)
                                timer.mark("Load project '{}'".format(np.name))
                                key = "{0}/{1}".format(path, np.name)

                                self.projects_in_order.append((key, np))
                                self.projects_by_path[key] = np
                                if np.name not in self.projects_by_name:
                                    self.projects_by_name[np.name] = list()
                                self.projects_by_name[np.name].append(np)

                                if np.name in target_names:
                                    #                                    print ("Found target: {0}".format(np.name))
                                    target_names.remove(np.name)

                                    if "depends-on" in proj_json:
                                        for dep in proj_json["depends-on"]:
                                            if dep not in self.projects_by_name:
                                                #                                                print ("New target from {1}: {0}".format(dep, np.name))
                                                target_names.add(dep)

                                if len(target_names) == 0:
                                    self.all_projects_found = True

                # look down the hierarchy if we have dependencies
                if self.all_projects_found == False:
                    if json_data != None and "depends-on" in json_data:
                        for subdir in json_data["depends-on"]:
                            down_path = os.path.join(path, subdir)
                            if down_path not in self.past_dirs:
                                downward_recurse(os.path.join(path, subdir))
                                if self.all_projects_found:
                                    break

            downward_recurse(path)

            if self.all_projects_found == False and not self.exhausted:
                (_, basepath) = os.path.splitdrive(path)
                if basepath != "/":
                    path = os.path.normpath(os.path.join(path, ".."))
                    upward_recurse(path)
                else:
                    self.exhausted = True

        upward_recurse(json_path)

        if target_proj_name in self.projects_by_name:

            def load_deps(parent_proj):
                for name, proj in parent_proj.depends_on.items():
                    if proj == None:
                        self.load_until(name)
                        proj = self.projects_by_name[name][0]
                        #print (proj)
                        parent_proj.depends_on[name] = proj
                        load_deps(proj)

            load_deps(self.projects_by_name[target_proj_name][0])
        else:
            raise PykeError("Project {} not found.".format(
                t.make_project_name(target_proj_name)))