def run(self):
     common.print_info("Running " + self.name + " action")
     for dir in self.list_of_package_dirs():
         common.print_verbose("Uploading package from " + dir)
         common.run_command([
             which('python3'), '-m', 'twine', 'upload', '--repository',
             'testpypi', dir + '/dist/*'
         ])
     return 0, ""
Exemplo n.º 2
0
def add_to_git(d):
  os.chdir(d)
  git_path = shutil.which('git')
  git_add_command = [git_path, 'add', '.']
  common.run_command(git_add_command)

  git_commit_command = [git_path, 'commit', '-m', 'Initialized with power_daps template ' + common.meta_model()]
  common.run_command(git_commit_command)

  return 0, ""
Exemplo n.º 3
0
 def metadata_file(self):
     metadata_file = self.metadata_local_location()
     if os.path.exists(metadata_file):
         return metadata_file
     else:
         common.run_command(
             ["mkdir", "-p", self.metadata_local_directory()])
         fetch(self.metadata_remote_location(),
               self.metadata_local_location())
         return metadata_file
Exemplo n.º 4
0
def copy_template_files_to(destination, source_action_name):
    common.print_verbose("Looking for files to copy in: " + str(
        pathlib.Path(
            MetaModel(common.meta_model()).template_for_action(
                source_action_name))))
    files_to_copy = [
        str(p) for p in pathlib.Path(
            MetaModel(common.meta_model()).template_for_action(
                source_action_name)).glob("*")
    ]
    common.print_verbose("Found " + str(len(files_to_copy)) +
                         " files to copy.")
    command_to_run = ['/bin/cp', "-R", *files_to_copy, destination]
    common.run_command(command_to_run)
Exemplo n.º 5
0
 def install_file(self, name, version, details, extension):
     remote_loc = self.remote_location(details["group_id"], name, version,
                                       extension)
     local_lib_dir = self.local_lib_directory(details["group_id"], name,
                                              version)
     local_loc = self.local_location(details["group_id"], name, version,
                                     extension)
     if not self.has_already_been_downloaded(details["group_id"], name,
                                             version, extension):
         common.print_info("Downloading " + remote_loc + " to " + local_loc)
         common.run_command(["mkdir", "-p", local_lib_dir])
         self.fetch(remote_loc, local_loc)
     else:
         common.print_verbose("Dependency found at " + local_loc)
     return 0, ""
Exemplo n.º 6
0
    def run(self):
        common.print_info("Running " + self.name + " action")
        exit_code = 0
        for test_dir in glob.iglob('**/test', recursive=True):
            original_working_directory = os.getcwd()

            run_directory = os.path.join(original_working_directory,
                                         str(test_dir))
            common.print_info("Running tests in " + str(run_directory))
            common.print_verbose("Changing directory to " + str(run_directory))
            os.chdir(run_directory)

            tests = []
            for filename in glob.iglob('**/*.py', recursive=True):
                tests.append(filename)
            command = [which('python3'), '-m', 'unittest']
            command.extend(tests)
            subprocess_exit_code, output = common.run_command(command)
            if subprocess_exit_code != common.SUCCESS:
                exit_code = common.FAILED
            common.print_verbose(output)
            common.continue_if_failed(subprocess_exit_code, output)

            common.print_verbose("Changing directory to " +
                                 str(original_working_directory))
            os.chdir(original_working_directory)

        return exit_code, ""
Exemplo n.º 7
0
 def install(self, dep_name, dep_version="latest", details={}):
     if details and details['env_vars']:
         for env_var_name, env_var_value in details['env_vars'].items():
             os.environ[env_var_name] = str(env_var_value)
             common.print_verbose("set " + str(env_var_name) + "=" +
                                  str(env_var_value))
     install_command = [
         self.installer(), "install",
         self.dependency_with_version(dep_name, dep_version,
                                      self.installer())
     ]
     common.print_verbose(install_command)
     return common.run_command(install_command)
Exemplo n.º 8
0
def find_and_replace_in_file_names_and_content(dir, find_and_replace_dict):
    current_dir = os.getcwd()

    for str_to_find, str_to_replace_with in find_and_replace_dict.items():
        dirs = sorted(common.dirs_in(
            dir, ["__pycache__", "dist", "build", "egg-info", ".git"]) + ["."],
                      key=len,
                      reverse=True)

        for d in dirs:
            os.chdir(current_dir + "/" + d)

            files_to_rename = [
                str(p) for p in pathlib.Path(".").glob("*" + str_to_find + "*")
            ]

            for f in files_to_rename:
                common.print_verbose(
                    "Renaming " + f + " to " +
                    f.replace(str_to_find, str_to_replace_with))
                rename_command = [
                    '/bin/mv', f,
                    f.replace(str_to_find, str_to_replace_with)
                ]
                common.run_command(rename_command)

        grep_files_command = [
            shutil.which('find'), ".", "!", "-name", '*.pyc', "!", "-path",
            '*.git*', "-type", "f", "-exec",
            shutil.which("grep"), "-l", str_to_find, '{}', ";", "-print"
        ]
        files_to_search_and_replace_within = common.run_command(
            grep_files_command)[1].splitlines()
        for f in files_to_search_and_replace_within:
            sed_command = sed_find_and_replace_command(str_to_find,
                                                       str_to_replace_with, f)
            common.run_command(sed_command)

    os.chdir(current_dir)
Exemplo n.º 9
0
    def install(self, dep_name, dep_version="latest", details={}):
        package_name = dep_name
        if not dep_version == "latest":
            package_name = dep_name + "==" + str(dep_version)

        status = self.is_already_installed(dep_name, dep_version)
        if status == PipInstaller.NOT_INSTALLED:
            common.print_verbose(dep_name + " not installed. Installing.")
            command_to_run = [which('pip3'), '-q', 'install', package_name]
            exit_code, output = common.run_command(command_to_run)
            common.stop_if_failed(exit_code, output)

        elif status == PipInstaller.OLDER_VERSION_INSTALLED:
            common.print_verbose(dep_name +
                                 " is already installed. Upgrading to " +
                                 dep_version + " version.")

            command_to_run = [
                which('pip3'), '-q', 'install', '--upgrade', package_name
            ]
            exit_code, output = common.run_command(command_to_run)
            common.stop_if_failed(exit_code, output)

        elif status == PipInstaller.NEWER_VERSION_INSTALLED:
            common.print_verbose("Newer version of " + dep_name +
                                 " installed. Uninstalling and installing " +
                                 dep_version + " version.")

            command_to_run = [which('pip3'), '-q', 'uninstall', package_name]
            exit_code, output = common.run_command(command_to_run)
            common.stop_if_failed(exit_code, output)

            command_to_run = [which('pip3'), '-q', 'install', package_name]
            exit_code, output = common.run_command(command_to_run)
            common.stop_if_failed(exit_code, output)
        else:
            common.print_verbose(dep_name + ", " + dep_version +
                                 " is already installed. Doing nothing.")
Exemplo n.º 10
0
 def run(self):
     common.print_verbose("Running " + self.name + " action")
     common.stop_if_failed(*common.run_command(["/bin/rm", "-rf", "dist"]))
     return common.run_command(["npx", "webpack-cli"])
Exemplo n.º 11
0
 def install(self, dep_name, dep_version, details):
     exit_code, output = common.run_command(self.command_base + [dep_name])
     common.stop_if_failed(exit_code, output)
Exemplo n.º 12
0
 def linux_distribution(self):
     exit_code, output = common.run_command(
         [which('grep'), 'ID_LIKE', '/etc/os-release'])
     return output.split("=")[1].rstrip()
Exemplo n.º 13
0
  def delete_dir_named(self, dir_name):
    common.print_verbose("Found " + str(len(self.dirs_named(dir_name))) + " dirs named " + dir_name)

    for d in self.dirs_named(dir_name):
      common.print_verbose("Deleting dir " + d)
      common.stop_if_failed(*common.run_command(["/bin/rm", "-rf", d]))
Exemplo n.º 14
0
def git_init(d):
  os.chdir(d)
  git_path = shutil.which('git')
  git_init_command = [git_path, 'init']
  common.run_command(git_init_command)
Exemplo n.º 15
0
 def install(self, base_url):
     if not self.has_been_installed():
         common.run_command(["mkdir", "-p", self.local_lib_directory()])
         fetch(base_url + self.relative_remote_location(),
               self.local_location(), self.error_callback)