Beispiel #1
0
def cmd(cmd, cmd_dir='.', fail=True, verbose=False):
    '''
    Run a shell (dos cmd.exe) command

    @param cmd: the command to run
    @type cmd: str
    @param cmd_dir: directory where the command will be run
    @param cmd_dir: str
    @param fail: whether or not to raise an exception if the command fails
    @type fail: bool
    '''
    try:
        if LOGFILE is None:
            if verbose:
                m.message("Running command '%s'" % cmd)
        else:
            LOGFILE.write("Running command '%s'\n" % cmd)
            LOGFILE.flush()
        shell = True
        stream = LOGFILE or sys.stdout
        if DRY_RUN:
            # write to sdterr so it's filtered more easilly
            m.error("cd %s && %s && cd %s" % (cmd_dir, cmd, os.getcwd()))
            ret = 0
        else:
            ret = subprocess.check_call(cmd, cwd=cmd_dir,
                                       stderr=subprocess.STDOUT,
                                       stdout=StdOut(stream),
                                       env=os.environ.copy(), shell=shell)
    except subprocess.CalledProcessError:
        if fail:
            raise FatalError(_("Error running command: %s") % cmd)
        else:
            ret = 0
    return ret
Beispiel #2
0
def call(cmd, cmd_dir='.', fail=True, verbose=False, logfile=None, env=None):
    '''
    Run a shell command
    DEPRECATED: Use new_call and a cmd array wherever possible

    @param cmd: the command to run
    @type cmd: str
    @param cmd_dir: directory where the command will be run
    @param cmd_dir: str
    @param fail: whether or not to raise an exception if the command fails
    @type fail: bool
    '''
    try:
        if logfile is None:
            if verbose:
                m.message("Running command '%s'" % cmd)
            stream = None
        else:
            logfile.write("Running command '%s'\n" % cmd)
            logfile.flush()
            stream = logfile
        shell = True
        if PLATFORM == Platform.WINDOWS:
            # windows do not understand ./
            if cmd.startswith('./'):
                cmd = cmd[2:]
            # run all processes through sh.exe to get scripts working
            cmd = '%s "%s"' % ('sh -c', cmd)
            # fix paths with backslashes
            cmd = _fix_mingw_cmd(cmd)
            # Disable shell which uses cmd.exe
            shell = False
        if DRY_RUN:
            # write to sdterr so it's filtered more easilly
            m.error("cd %s && %s && cd %s" % (cmd_dir, cmd, os.getcwd()))
            ret = 0
        else:
            if env is not None:
                env = env.copy()
            else:
                env = os.environ.copy()

            # Force python scripts to print their output on newlines instead
            # of on exit. Ensures that we get continuous output in log files.
            env['PYTHONUNBUFFERED'] = '1'
            ret = subprocess.check_call(cmd,
                                        cwd=cmd_dir,
                                        bufsize=1,
                                        stderr=subprocess.STDOUT,
                                        stdout=stream,
                                        universal_newlines=True,
                                        env=env,
                                        shell=shell)
    except subprocess.CalledProcessError:
        if fail:
            raise FatalError(_("Error running command: %s") % cmd)
        else:
            ret = 0
    return ret
 def log_error(self, msg, print_usage=False, command=None):
     ''' Log an error and exit '''
     if command is not None:
         m.error("***** Error running '%s' command:" % command)
     m.error('%s' % msg)
     if print_usage:
         self.parser.print_usage()
     sys.exit(1)
Beispiel #4
0
 def log_error(self, msg, print_usage=False, command=None):
     ''' Log an error and exit '''
     if command is not None:
         m.error("***** Error running '%s' command:" % command)
     m.error('%s' % msg)
     if print_usage:
         self.parser.print_usage()
     sys.exit(1)
Beispiel #5
0
    def run(self, config, args):
        cookbook = CookBook(config)
        recipe_name = args.recipe[0]

        recipes = cookbook.list_recipe_reverse_deps(recipe_name)
        if len(recipes) == 0:
            m.error(_('%s has 0 reverse dependencies') % recipe_name)
            return
        for recipe in recipes:
            m.message(recipe.name)
Beispiel #6
0
    def run(self, config, args):
        if args.bootstrap:
            config.cache_file = config.build_tools_cache
        cookbook = CookBook(config)

        is_modifying = False or args.touch or args.reset
        if not is_modifying:
            for attr in self.recipe_attributes:
                if getattr(args, attr) is not None:
                    is_modifying = True
                    break

        global_status = cookbook.status
        recipes = args.recipe or list(global_status.keys())

        m.message('{} cache values for recipes: {}'.format(
            'Showing' if not is_modifying else 'Modifying',
            ', '.join(recipes)))

        for recipe in recipes:
            if recipe not in global_status.keys():
                m.error('Recipe {} not in cookbook'.format(recipe))
                continue
            status = global_status[recipe]
            print('[{}]'.format(recipe))
            text = ''
            if is_modifying:
                text = 'Before\n'
            print('{}{}\n'.format(text, status))
            if is_modifying:
                if args.reset:
                    cookbook.reset_recipe_status(recipe)
                    m.message('Recipe {} reset'.format(recipe))
                else:
                    if args.touch:
                        status.touch()

                    for attr in self.recipe_attributes:
                        var = getattr(args, attr)
                        if var is not None:
                            if isinstance(getattr(self.recipe_status, attr),
                                          bool):
                                if var.lower() == 'true':
                                    var = True
                                elif var.lower() == 'false':
                                    var = False
                                else:
                                    m.error(
                                        'Error: Attribute "{}" needs to be either "True" or "False"'
                                        .format(attr))
                                    return
                            setattr(status, attr, var)

                    cookbook.save()
                    print('After\n{}\n'.format(status))
Beispiel #7
0
def call(cmd, cmd_dir='.', fail=True, verbose=False):
    '''
    Run a shell command

    @param cmd: the command to run
    @type cmd: str
    @param cmd_dir: directory where the command will be run
    @param cmd_dir: str
    @param fail: whether or not to raise an exception if the command fails
    @type fail: bool
    '''
    global CALL_ENV
    try:
        if LOGFILE is None:
            if verbose:
                m.message("Running command '%s'" % cmd)
        else:
            LOGFILE.write("Running command '%s'\n" % cmd)
            LOGFILE.flush()
        shell = True
        if PLATFORM == Platform.WINDOWS:
            # windows do not understand ./
            if cmd.startswith('./'):
                cmd = cmd[2:]
            # run all processes through sh.exe to get scripts working
            cmd = '%s "%s"' % ('sh -c', cmd)
            # fix paths with backslashes
            cmd = _fix_mingw_cmd(cmd)
            # Disable shell which uses cmd.exe
            shell = False
        stream = LOGFILE or sys.stdout
        if DRY_RUN:
            # write to sdterr so it's filtered more easilly
            m.error("cd %s && %s && cd %s" % (cmd_dir, cmd, os.getcwd()))
            ret = 0
        else:
            if CALL_ENV is not None:
                env = CALL_ENV.copy()
            else:
                env = os.environ.copy()
            ret = subprocess.check_call(cmd,
                                        cwd=cmd_dir,
                                        stderr=subprocess.STDOUT,
                                        stdout=StdOut(stream),
                                        env=env,
                                        shell=shell)
    except subprocess.CalledProcessError:
        if fail:
            raise FatalError(_("Error running command: %s") % cmd)
        else:
            ret = 0
    return ret
Beispiel #8
0
async def async_call(cmd,
                     cmd_dir='.',
                     fail=True,
                     logfile=None,
                     cpu_bound=True,
                     env=None):
    '''
    Run a shell command

    @param cmd: the command to run
    @type cmd: str
    @param cmd_dir: directory where the command will be run
    @param cmd_dir: str
    '''
    global CPU_BOUND_SEMAPHORE, NON_CPU_BOUND_SEMAPHORE
    semaphore = CPU_BOUND_SEMAPHORE if cpu_bound else NON_CPU_BOUND_SEMAPHORE

    async with semaphore:
        cmd = _cmd_string_to_array(cmd, env)

        if logfile is None:
            stream = None
        else:
            logfile.write("Running command '%s'\n" %
                          ' '.join([shlex.quote(c) for c in cmd]))
            logfile.flush()
            stream = logfile

        if DRY_RUN:
            # write to sdterr so it's filtered more easilly
            m.error("cd %s && %s && cd %s" % (cmd_dir, cmd, os.getcwd()))
            return

        env = os.environ.copy() if env is None else env.copy()
        # Force python scripts to print their output on newlines instead
        # of on exit. Ensures that we get continuous output in log files.
        env['PYTHONUNBUFFERED'] = '1'
        proc = await asyncio.create_subprocess_exec(*cmd,
                                                    cwd=cmd_dir,
                                                    stderr=subprocess.STDOUT,
                                                    stdout=stream,
                                                    stdin=subprocess.DEVNULL,
                                                    env=env)
        await proc.wait()
        if proc.returncode != 0 and fail:
            msg = ''
            if stream:
                msg = 'Output in logfile {}'.format(logfile.name)
            raise CommandError(msg, cmd, proc.returncode)

        return proc.returncode
    def _unpack(self, name, cats=['devel', 'runtime'], version=None):
        profile = self.profile[name]
        #ppath = profile.get('__file__',None)
        #if ppath is None or not os.path.exists( ppath ):
        #    m.error('package <%s> not exists!'%name)
        #    raise FatalError('install package failed')

        path = profile.get('__file__', None)
        if path:
            if not os.path.exists(path):
                m.error('package <%s> not exists!' % name)
                raise FatalError('install package failed')
            d = os.path.dirname(profile['__file__'])
        else:
            d = profile.get('__dir__', None)
        assert d, '!!!!!!!'

        prefix = self.args.prefix
        if prefix is None:
            if name == 'build-tools':
                prefix = self.config.build_tools_prefix
            else:
                prefix = self.config.prefix

        #profile path
        ip = os.path.join(prefix, name + '.yaml')
        if os.path.exists(ip):
            pro = yaml.load(open(ip))
            if version:
                m.error(
                    'installed package %s version %s not consistent with require %s'
                    % (name, pro['version'], version))
                raise FatalError("install package failed.")
            else:
                m.message('package %s (%s) already installed.' %
                          (name, pro['version']))
                return

        for cat, info in profile['tarball'].viewitems():

            filename = info['filename']
            url = os.path.join(d, filename)
            path = cache(url, self.args.cache_dir)
            assert os.path.exists(path)

            shell.unpack(path, prefix)

        yaml.dump(profile, open(ip, 'w'), default_flow_style=False)
        m.message('package <%s> installation done.' % name)
Beispiel #10
0
    def dump(self, name, output_dir='.'):
        sdk = self.sdk(name)
        desc = {
            'name': name,
            'version': sdk.version,
            'platform': self.config.target_platform,
            'arch': self.config.target_arch,
            'recipes': {},
            'commit': self.commit()
        }

        for rname in self.recipes_of_sdk(name):
            recipe = self.recipe(rname)
            desc['recipes'][rname] = recipe.version

        tarball = DistTarball(self.config, sdk, self.store)

        files = []
        for ptype in [PackageType.DEVEL, PackageType.RUNTIME]:
            TNAME = {
                PackageType.DEVEL: 'devel',
                PackageType.RUNTIME: 'runtime'
            }

            filename = tarball._get_name(ptype)
            path = os.path.join(output_dir, filename)
            if os.path.exists(path):
                files.append(
                    {filename: {
                        'type': TNAME[ptype],
                        'MD5Sum': MD5(path)
                    }})
            else:
                if (name == 'build-tools') and (ptype == PackageType.DEVEL):
                    continue  # build-tools has no devel package

                reason = "abstract %s, but no %s package at %s" % (
                    name, TNAME[ptype], path)
                m.error(reason)
                raise FatalError(reason)

        desc['packages'] = files
        if name == 'build-tools':
            desc['prefix'] = self.config.build_tools_prefix
        else:
            desc['prefix'] = self.config.prefix

        return desc
    def run(self, config, args):
        self.config = config
        self.args = args
        self.profile = {}

        self._load_release()
        for name in args.name:
            if self.profile.get(name,None) is None \
               and  not self.args.deps_only:
                m.error("can not find package of %s from profiles." % name)
                raise FatalError("can not find package of %s from profiles." %
                                 name)
            if name == 'build-tools':
                self._build_tools()
            else:
                self._package(name)
Beispiel #12
0
def call(cmd, cmd_dir='.', fail=True, env=None, verbose=False):
    '''
    Run a shell command

    @param cmd: the command to run
    @type cmd: str
    @param cmd_dir: directory where the command will be run
    @param cmd_dir: str
    @param fail: whether or not to raise an exception if the command fails
    @type fail: bool
    '''
    try:
        if LOGFILE is None:
            if verbose:
                m.message("Running command '%s'" % cmd)
        else:
            LOGFILE.write("Running command '%s'\n" % cmd)
        shell = True
        if PLATFORM == Platform.WINDOWS:
            # windows do not understand ./
            if cmd.startswith('./'):
                cmd = cmd[2:]
            # run all processes through sh.exe to get scripts working
            cmd = '%s "%s"' % ('sh -c', cmd)
            # fix paths with backslashes
            cmd = _fix_mingw_cmd(cmd)
            # Disable shell which uses cmd.exe
            shell = False
        stream = LOGFILE or sys.stdout
        if DRY_RUN:
            # write to sdterr so it's filtered more easilly
            m.error("cd %s && %s && cd %s" % (cmd_dir, cmd, os.getcwd()))
            ret = 0
        else:
            if not env:
                env = os.environ.copy()
            ret = subprocess.check_call(cmd, cwd=cmd_dir,
                                       stderr=subprocess.STDOUT,
                                       stdout=StdOut(stream),
                                       env=env, shell=shell)
    except subprocess.CalledProcessError:
        if fail:
            raise FatalError(_("Error running command: %s") % cmd)
        else:
            ret = 0
    return ret
Beispiel #13
0
 def _find_deps(self, recipe, state={}, ordered=[]):
     if state.get(recipe, 'clean') == 'processed':
         return
     if state.get(recipe, 'clean') == 'in-progress':
         raise FatalError(_("Dependency Cycle: {0}".format(recipe.name)))
     state[recipe] = 'in-progress'
     recipe_deps = recipe.list_deps()
     if not recipe.runtime_dep:
         recipe_deps = self._runtime_deps () + recipe_deps
     for recipe_name in recipe_deps:
         try:
             recipedep = self.get_recipe(recipe_name)
         except RecipeNotFoundError as e:
             raise FatalError(_("Recipe %s has a unknown dependency %s"
                              % (recipe.name, recipe_name)))
         try:
             self._find_deps(recipedep, state, ordered)
         except FatalError:
             m.error('Error finding deps of "{0}"'.format(recipe.name))
             raise
     state[recipe] = 'processed'
     ordered.append(recipe)
     return ordered
Beispiel #14
0
 def _find_deps(self, recipe, state={}, ordered=[]):
     if state.get(recipe, 'clean') == 'processed':
         return
     if state.get(recipe, 'clean') == 'in-progress':
         raise FatalError(_("Dependency Cycle: {0}".format(recipe.name)))
     state[recipe] = 'in-progress'
     recipe_deps = recipe.list_deps()
     if not recipe.runtime_dep:
         recipe_deps = self._runtime_deps () + recipe_deps
     for recipe_name in recipe_deps:
         try:
             recipedep = self.get_recipe(recipe_name)
         except RecipeNotFoundError as e:
             raise FatalError(_("Recipe %s has a unknown dependency %s"
                              % (recipe.name, recipe_name)))
         try:
             self._find_deps(recipedep, state, ordered)
         except FatalError:
             m.error('Error finding deps of "{0}"'.format(recipe.name))
             raise
     state[recipe] = 'processed'
     ordered.append(recipe)
     return ordered
Beispiel #15
0
async def async_call(cmd, cmd_dir='.', logfile=None, env=None):
    '''
    Run a shell command

    @param cmd: the command to run
    @type cmd: str
    @param cmd_dir: directory where the command will be run
    @param cmd_dir: str
    '''
    cmd = _cmd_string_to_array(cmd)

    if logfile is None:
        stream = None
    else:
        logfile.write("Running command '%s'\n" %
                      ' '.join([shlex.quote(c) for c in cmd]))
        logfile.flush()
        stream = logfile

    if DRY_RUN:
        # write to sdterr so it's filtered more easilly
        m.error("cd %s && %s && cd %s" % (cmd_dir, cmd, os.getcwd()))
        return

    env = os.environ.copy() if env is None else env.copy()
    # Force python scripts to print their output on newlines instead
    # of on exit. Ensures that we get continuous output in log files.
    env['PYTHONUNBUFFERED'] = '1'
    proc = await asyncio.create_subprocess_exec(*cmd,
                                                cwd=cmd_dir,
                                                stderr=subprocess.STDOUT,
                                                stdout=stream,
                                                env=env)
    await proc.wait()
    if proc.returncode != 0:
        raise FatalError('Running {!r}, returncode {}'.format(
            cmd, proc.returncode))
Beispiel #16
0
    def run(self, config, args):
        if args.recipe + args.package + args.package_recipes == 0:
            m.error(
                'Error: You need to specify either recipe, package or package-recipes '
                'mode to generate the dependency graph')
            return

        if args.recipe + args.package + args.package_recipes > 1:
            m.error(
                'Error: You can only specify recipe, package or package-recipes but not more than one'
            )
            return

        if not shutil.which('dot'):
            m.error(
                'Error: dot command not found. Please install graphviz it using '
                'your package manager. e.g. apt/dnf/brew install graphviz')
            return

        label = ''
        if args.recipe:
            self.graph_type = GraphType.RECIPE
            label = 'recipe'
        elif args.package:
            self.graph_type = GraphType.PACKAGE
            label = 'package'
        elif args.package_recipes:
            self.graph_type = GraphType.PACKAGE_RECIPES
            label = 'package\'s recipes'

        if self.graph_type == GraphType.RECIPE or self.graph_type == GraphType.PACKAGE_RECIPES:
            self.cookbook = CookBook(config)
        if self.graph_type == GraphType.PACKAGE or self.graph_type == GraphType.PACKAGE_RECIPES:
            self.package_store = PackagesStore(config)

        name = args.name[0]
        output = args.output[0] if args.output else name + '.svg'

        tmp = tempfile.NamedTemporaryFile()
        dot = 'digraph {{\n\tlabel="{} {}";\n{}}}\n'.format(
            name, label, self._dot_gen(name, self.graph_type))
        with open(tmp.name, 'w') as f:
            f.write(dot)

        shell.new_call(['dot', '-Tsvg', tmp.name, '-o', output])
        m.message("Dependency graph for %s generated at %s" % (name, output))
Beispiel #17
0
    def run(self, config, args):
        packages = []
        recipes = []
        bundle_recipes = []
        bundle_dirs = []
        setup_args = ['sdist']

        if not config.uninstalled:
            m.error("Can only be run on cerbero-uninstalled")

        store = PackagesStore(config)
        cookbook = CookBook(config)

        packages = list(args.bundlepackages)

        for p in packages:
            package = store.get_package(p)
            if hasattr(package, 'list_packages'):
                packages += package.list_packages()
        packages = remove_list_duplicates(packages)

        for p in packages:
            package = store.get_package(p)
            if hasattr(package, 'deps'):
                packages += package.deps
        packages = remove_list_duplicates(packages)

        for p in packages:
            package = store.get_package(p)
            recipes += package.recipes_dependencies()
        recipes += args.add_recipe

        for r in recipes:
            bundle_recipes += cookbook.list_recipe_deps(r)
        bundle_recipes = remove_list_duplicates(bundle_recipes)

        for p in packages:
            setup_args.append('--package=' + p)

        for r in bundle_recipes:
            setup_args.append('--recipe=' + r.name)
            if r.stype != SourceType.CUSTOM:
                bundle_dirs.append(r.repo_dir)

        if not args.no_bootstrap:
            build_tools = BuildTools(config)
            bs_recipes = build_tools.BUILD_TOOLS + \
                         build_tools.PLAT_BUILD_TOOLS.get(config.platform, [])
            b_recipes = []
            for r in bs_recipes:
                b_recipes += cookbook.list_recipe_deps(r)
            b_recipes = remove_list_duplicates(b_recipes)

            for r in b_recipes:
                if r.stype != SourceType.CUSTOM:
                    bundle_dirs.append(r.repo_dir)

        setup_args.append('--source-dirs=' + ','.join(bundle_dirs))

        command = str(config._relative_path('setup.py'))
        run_setup(command, setup_args)
        libraries_dirs = pkgconfig.libraries_dirs()

        libs = pkgconfig.libraries()
        if None not in [prefix_replacement, prefix]:
            libraries_dirs = [x.replace(prefix, prefix_replacement) for x in libraries_dirs]
            include_dirs = [x.replace(prefix, prefix_replacement) for x in include_dirs]
        self.vsprops = self.generators[target](libname, requires, include_dirs, libraries_dirs, libs, inherit_common)

    def create(self, outdir):
        self.vsprops.create(outdir)


if __name__ == "__main__":
    parser = argparse.ArgumentParser(description="Creates VS property " "sheets with pkg-config")
    parser.add_argument("library", help="Library name")
    parser.add_argument("-o", type=str, default=".", help="Output directory for generated files")
    parser.add_argument("-c", type=str, default="vs2010", help="Target version (vs2008 or vs2010) name")

    generators = {"vs2008": VSProps, "vs2010": Props}
    args = parser.parse_args(sys.argv[1:])
    try:
        p2v = PkgConfig2VSProps(args.library, args.c)
        p2v.create(args.o)
    except Exception, e:
        import traceback

        traceback.print_exc()
        m.error(str(e))
        exit(1)
    exit(0)
Beispiel #19
0
    def run(self, config, args):
        packages = []
        recipes = []
        bundle_recipes = []
        bundle_dirs = []
        setup_args = ['sdist']

        if not config.uninstalled:
            m.error("Can only be run on cerbero-uninstalled")

        store = PackagesStore(config)
        cookbook = CookBook(config)

        packages = list(args.bundlepackages)

        for p in packages:
            package = store.get_package(p)
            if hasattr(package, 'list_packages'):
                packages += package.list_packages()
        packages = remove_list_duplicates(packages)

        for p in packages:
            package = store.get_package(p)
            if hasattr(package, 'deps'):
                packages += package.deps
        packages = remove_list_duplicates(packages)

        for p in packages:
            package = store.get_package(p)
            recipes += package.recipes_dependencies()
        recipes += args.add_recipe

        for r in recipes:
            bundle_recipes += cookbook.list_recipe_deps(r)
        bundle_recipes = remove_list_duplicates(bundle_recipes)

        for p in packages:
            setup_args.append('--package=' + p)

        for r in bundle_recipes:
            setup_args.append('--recipe=' + r.name)
            if r.stype != SourceType.CUSTOM:
                bundle_dirs.append(r.repo_dir)

        if not args.no_bootstrap:
            build_tools = BuildTools(config)
            bs_recipes = build_tools.BUILD_TOOLS + \
                         build_tools.PLAT_BUILD_TOOLS.get(config.platform, [])
            b_recipes = []
            for r in bs_recipes:
                b_recipes += cookbook.list_recipe_deps(r)
            b_recipes = remove_list_duplicates(b_recipes)

            for r in b_recipes:
                if r.stype != SourceType.CUSTOM:
                    bundle_dirs.append(r.repo_dir)

        setup_args.append('--source-dirs=' + ','.join(bundle_dirs))

        command = str(config._relative_path('setup.py'))
        run_setup(command, setup_args)
Beispiel #20
0
                                               inherit_common)

    def create(self, outdir):
        self.vsprops.create(outdir)


if __name__ == "__main__":
    parser = argparse.ArgumentParser(description='Creates VS property '
                                     'sheets with pkg-config')
    parser.add_argument('library', help='Library name')
    parser.add_argument('-o',
                        type=str,
                        default='.',
                        help='Output directory for generated files')
    parser.add_argument('-c',
                        type=str,
                        default='vs2010',
                        help='Target version (vs2008 or vs2010) name')

    generators = {'vs2008': VSProps, 'vs2010': Props}
    args = parser.parse_args(sys.argv[1:])
    try:
        p2v = PkgConfig2VSProps(args.library, args.c)
        p2v.create(args.o)
    except Exception as e:
        import traceback
        traceback.print_exc()
        m.error(str(e))
        exit(1)
    exit(0)