Пример #1
0
def new_user_setup(
    user: str,
    authorized_keys: List[str],
    groups: List[str],
) -> None:
    log(f"setting up a new user: {user}")

    if not has_user(user):
        useradd = find_program("useradd", "/usr/sbin")
        shell = find_program("bash", "/bin")
        assert user is not None
        assert useradd is not None
        assert shell is not None
        cmd = [
            useradd, user, "--user-group", "--shell", shell, "--create-home"
        ]
        check(cmd)

    for key_line in authorized_keys:
        authorized_key(user, key_line)

    delete_password(user)

    for group in groups:
        add_user_to_group(user, group)
Пример #2
0
def run_rates(command):
    global _tiger_binary
    if _tiger_binary is None:
        _tiger_binary = util.find_program(_binary_name)

    try:
        util.run_program(_tiger_binary, command)
    except util.ExternalProgramError:
        log.error("fast_TIGER did not execute successfully")
        log.error("fast_TIGER output follows, in case it's helpful for \
            finding the problem")
        log.error("You probably just need to recompile the fast_TIGER \
            code for your system. But please note that this is an \
            unsupported option. For empirical work we recommend using \
            entropy calculations for site rates, which is the default \
            behaviour for the kmeans algorithm in PF2.")
        raise
Пример #3
0
 def finalize_options(self):
     build_ext.finalize_options(self)
     self.web_ext_modules = self.distribution.web_ext_modules
     if self.pyjspath is None:
         try:
             import pyjs
             self.pyjspath = os.path.dirname(pyjs.__file__)
         except:
             pass
     else:
         sys.path.insert(0, os.path.join(self.pyjspath, 'build', 'lib'))
     if self.pyjscompiler is None:
         try:
             self.pyjscompiler = util.find_program('pyjsbuild',
                                                   [self.pyjspath])
         except:
             pass
Пример #4
0
def _build(name: str, repo: str, commit: str):
    # This is responsible for creating a build/ directory and building in it

    exe = find_program("git", "/usr/bin")

    def git(cmd):
        log(f"{exe} {cmd}")
        return check_call([exe] + cmd.split())

    git_home = os.path.expanduser("~/git")
    ensure_dir(git_home, 0o700)

    dst = repo.split("/")[-1]

    with cd(git_home):
        local_repo = os.path.abspath(dst)

        if not os.path.exists(dst):
            git(f"init -q --bare {dst}")
        with cd(dst):
            git("config --local uploadpack.allowreachablesha1inwant true")
            rc, existing_repo = subprocess.getstatusoutput(f"{exe} remote get-url origin")
            if rc != 0:
                git(f"remote add origin {repo}")
            elif existing_repo.strip() != repo:
                git(f"remote set-url origin {repo}")

            with timeit("remote fetch"):
                git("fetch")

    cmd = f"init -q build"
    git(cmd)

    with cd("build"):
        git(f"remote add origin {local_repo}")
        with timeit("local fetch"):
            git(f"fetch -q origin {commit} --depth 1")
        git(f"reset -q --hard {commit}")
        with timeit("build"):
            subprocess.check_call(f"./services/{name}/build.sh", stdout=sys.stderr)
Пример #5
0
def run_raxml_pthreads(command, cpus):
    global _raxml_pthreads_binary
    if _raxml_pthreads_binary is None:
        _raxml_pthreads_binary = util.find_program(_binary_name_pthreads)
    command = " ".join([command, "-T", str(cpus), " "])
    util.run_program(_raxml_pthreads_binary, command)
Пример #6
0
def run_raxml(command):
    global _raxml_binary
    if _raxml_binary is None:
        _raxml_binary = util.find_program(_binary_name)
    util.run_program(_raxml_binary, command)
Пример #7
0
def run_raxml_pthreads(command, cpus):
    global _raxml_pthreads_binary
    if _raxml_pthreads_binary is None:
        _raxml_pthreads_binary = util.find_program(_binary_name_pthreads)
    command = " ".join([command, "-T", str(cpus), " "])
    util.run_program(_raxml_pthreads_binary, command)
Пример #8
0
def run_raxml(command):
    global _raxml_binary
    if _raxml_binary is None:
        _raxml_binary = util.find_program(_binary_name)
    util.run_program(_raxml_binary, command)
Пример #9
0
    def run(self):
        if not self.distribution.doc_modules:
            return

        ## Make sure that sources are complete in build_lib.
        self.run_command('build_src')
        ## Ditto extensions
        self.run_command('build_ext')

        build = self.get_finalized_command('build')
        buildpy = self.get_finalized_command('build_py')
        target = os.path.abspath(os.path.join(build.build_base, 'http'))
        util.mkdir(target)
        build_verbose = self.distribution.verbose
        environ = self.distribution.environment

        for dext in self.distribution.doc_modules:
            if self.distribution.verbose:
                print 'building documentation "' + dext.name + '" sources'

            doc_dir = os.path.abspath(dext.source_directory)
            extra_dirs = dext.extra_directories
            working_dir = os.path.abspath(os.path.join(self.build_temp,
                                                       dext.source_directory))
            here = os.getcwd()

            reprocess = True
            ref = os.path.join(target, dext.name + '.html')
            root_dir = dext.name
            if os.path.exists(ref) and not self.force:
                reprocess = False
                docbase = os.path.join(doc_dir, 'modules')
                for root, dirnames, filenames in os.walk(docbase):
                    for fn in fnmatch.filter(filenames, '*.rst'):
                        doc = os.path.join(root, fn)
                        if os.path.getmtime(ref) < os.path.getmtime(doc):
                            reprocess = True
                            break
                        src = os.path.join(root_dir, root[len(docbase)+1:],
                                            fn[:-3] + 'py')
                        if os.path.exists(src):
                            if os.path.getmtime(ref) < os.path.getmtime(src):
                                reprocess = True
                                break
            if reprocess:
                src_dirs = []
                for package in buildpy.packages:
                    # Locate package source directory
                    src_dirs.append(os.path.abspath(buildpy.get_package_dir(package)))
                #FIXME rst files in package sources (mutiple packages)
                #src_dir = src_dirs[0]
                src_dir = os.path.abspath('.')
                bld_dir = os.path.abspath(self.build_lib)
                doc_bld_dir = os.path.join(bld_dir,
                                           os.path.relpath(doc_dir, src_dir))
                environ['BUILD_DIR'] = bld_dir
                environ['SOURCE_DIR'] = src_dir
                environ['RELATIVE_SOURCE_DIR'] = os.path.relpath(src_dir,
                                                                 doc_bld_dir)

                util.copy_tree(doc_dir, working_dir, True,
                                excludes=['.svn', 'CVS', '.git', '.hg*'])
                for d in extra_dirs:
                    subdir = os.path.basename(os.path.normpath(d))
                    util.copy_tree(d, os.path.join(target, subdir), True,
                                   excludes=['.svn', 'CVS', '.git', '.hg*'])

                ## Configure rst files
                util.configure_files(environ, src_dir, '*.rst', working_dir)

                if os.path.exists(os.path.join(doc_dir, dext.doxygen_cfg)):
                    ## Doxygen + breathe
                    'Config ' + os.path.join(doc_dir, dext.doxygen_cfg)
                    util.configure_file(environ,
                                        os.path.join(doc_dir, dext.doxygen_cfg),
                                        os.path.join(working_dir,
                                                     dext.doxygen_cfg),
                                        style=dext.style)
                    for s in dext.doxygen_srcs:
                        util.configure_file(environ,
                                            os.path.join(doc_dir, s),
                                            os.path.join(working_dir, s),
                                            style=dext.style)
                    try:
                        doxygen_exe = util.find_program('doxygen')
                    except:
                        sys.stderr.write('ERROR: Doxygen not installed ' +
                                         '(required for documentation).\n')
                        return

                    reprocess = True
                    ref = os.path.join(working_dir, 'html', 'index.html')
                    if os.path.exists(ref) and not self.force:
                        reprocess = False
                        for d in environ['C_SOURCE_DIRS'].split(' '):
                            for orig in glob.glob(os.path.join(d, '*.h*')):
                               if os.path.getmtime(ref) < \
                                        os.path.getmtime(orig):
                                    reprocess = True
                                    break
                    if reprocess:
                        if self.distribution.verbose:
                            out = sys.stdout
                            err = sys.stderr
                        else:
                            out = err = open('doxygen.log', 'w')
                        os.chdir(working_dir)
                        cmd_line = [doxygen_exe, dext.doxygen_cfg]
                        status = subprocess.call(cmd_line,
                                                 stdout=out, stderr=err)
                        if status != 0:
                            raise Exception("Command '" + str(cmd_line) +
                                            "' returned non-zero exit status "
                                            + str(status))

                        if not self.distribution.verbose:
                            out.close()
                        util.copy_tree('html', os.path.join(target, 'html'), True,
                                       excludes=['.svn', 'CVS', '.git', '.hg*'])
                        os.chdir(here)
                        create_breathe_stylesheet(target)

                for f in dext.extra_docs:
                    shutil.copy(os.path.join(doc_dir, f), target)

                ## Sphinx
                if dext.without_sphinx:
                    return
                if dext.sphinx_config is None:
                    dext.sphinx_config = os.path.join(os.path.dirname(__file__),
                                                      'sphinx_conf.py.in')
                elif os.path.dirname(dext.sphinx_config) == '':
                    dext.sphinx_config =  os.path.join(doc_dir,
                                                       dext.sphinx_config)
                util.configure_file(environ, dext.sphinx_config,
                                    os.path.join(working_dir, 'conf.py'))
                import warnings
                try:
                    import sphinx
                    from sphinx.application import Sphinx
                    if 'windows' in platform.system().lower() or \
                            not build_verbose:
                        from sphinx.util.console import nocolor
                except:
                    sys.stderr.write('ERROR: Sphinx not installed ' +
                                     '(required for documentation).\n')
                    return
                warnings.filterwarnings("ignore",
                                        category=PendingDeprecationWarning)
                warnings.filterwarnings("ignore", category=UserWarning)

                status = sys.stdout
                if not build_verbose:
                    status = open('sphinx.log', 'w')
                if 'windows' in platform.system().lower() or not build_verbose:
                    nocolor()
                try:
                    sphinx_app = Sphinx(working_dir, working_dir, target,
                                        os.path.join(target, '.doctrees'),
                                        'html', None, status)
                    sphinx_app.build(True)
                except Exception, e:
                    if build_verbose:
                        print 'ERROR: ' + str(e)
                    else:
                        pass
                if not build_verbose:
                    status.close()
                warnings.resetwarnings()