Example #1
0
File: git.py Project: kball/ambry
    def dependencies(self):
        '''Return a set of dependencies for the source packages'''
        from collections import defaultdict
        import os
        from ambry.identity import Identity
        from ambry.run import import_file

        if not self._dependencies:

            depset = defaultdict(set)

            for root, _, files in os.walk(self.dir_):
                if 'bundle.yaml' in files:

                    rp = os.path.realpath(os.path.join(root, 'bundle.py'))
                    mod = import_file(rp)

                    bundle = mod.Bundle(root)
                    deps = bundle.library.dependencies

                    for _, v in deps.items():
                        ident = Identity.parse_name(v) # Remove revision
                        #print "XXX {:50s} {:30s} {}".format(v, ident.name, ident.to_dict())
                        depset[bundle.identity.name].add(ident.name)

            self._dependencies = depset

        return dict(self._dependencies.items())
Example #2
0
def load_bundle(bundle_dir):
    from ambry.run import import_file

    rp = os.path.realpath(os.path.join(bundle_dir, 'bundle.py'))
    mod = import_file(rp)

    return mod.Bundle
Example #3
0
def load_bundle(bundle_dir):
    from ambry.run import import_file

    rp = os.path.realpath(os.path.join(bundle_dir, 'bundle.py'))
    mod = import_file(rp)

    return mod.Bundle
Example #4
0
    def dependencies(self):
        """Return a set of dependencies for the source packages."""
        from collections import defaultdict
        import os
        from ambry.identity import Identity
        from ambry.run import import_file

        if not self._dependencies:

            depset = defaultdict(set)

            for root, _, files in os.walk(self.dir_):
                if 'bundle.yaml' in files:

                    rp = os.path.realpath(os.path.join(root, 'bundle.py'))
                    mod = import_file(rp)

                    bundle = mod.Bundle(root)
                    deps = bundle.library.dependencies

                    for _, v in deps.items():
                        ident = Identity.parse_name(v)  # Remove revision
                        # print "XXX {:50s} {:30s} {}".format(v, ident.name,
                        # ident.to_dict())
                        depset[bundle.identity.name].add(ident.name)

            self._dependencies = depset

        return dict(self._dependencies.items())
Example #5
0
File: git.py Project: kball/ambry
    def bundle_dir(self, bundle_dir):
        self._bundle_dir = bundle_dir

        # Import the bundle file from the directory
        from ambry.run import import_file
        import os
        rp = os.path.realpath(os.path.join(bundle_dir, 'bundle.py'))
        mod = import_file(rp)

        dir_ = os.path.dirname(rp)
        self.bundle = mod.Bundle(dir_)
Example #6
0
    def bundle_dir(self, bundle_dir):
        self._bundle_dir = bundle_dir

        # Import the bundle file from the directory
        from ambry.run import import_file
        import os
        rp = os.path.realpath(os.path.join(bundle_dir, 'bundle.py'))
        mod = import_file(rp)

        dir_ = os.path.dirname(rp)
        self.bundle = mod.Bundle(dir_)
Example #7
0
    def setUp(self):
        import testbundle.bundle, shutil, os

        self.bundle_dir = os.path.dirname(testbundle.bundle.__file__)
        self.rc = get_runconfig(
            (os.path.join(self.bundle_dir, 'source-test-config.yaml'),
             os.path.join(self.bundle_dir,
                          'bundle.yaml'), RunConfig.USER_ACCOUNTS))

        self.copy_or_build_bundle()

        bundle = Bundle()

        self.source_save_dir = str(
            self.rc.group('filesystem').root) + '-source'

        self.setup_source_dir()

        print "Deleting: {}".format(self.rc.group('filesystem').root)
        ambry.util.rm_rf(self.rc.group('filesystem').root)

        bdir = os.path.join(self.rc.sourcerepo.dir, 'testbundle')

        pats = shutil.ignore_patterns('build', 'build-save', '*.pyc', '.git',
                                      '.gitignore', '.ignore', '__init__.py')

        print "Copying test dir tree to ", bdir
        shutil.copytree(bundle.bundle_dir, bdir, ignore=pats)

        # Import the bundle file from the directory
        from ambry.run import import_file
        import imp

        rp = os.path.realpath(os.path.join(bdir, 'bundle.py'))
        mod = import_file(rp)

        dir_ = os.path.dirname(rp)
        self.bundle = mod.Bundle(dir_)

        print self.bundle.bundle_dir
Example #8
0
    def setUp(self):
        import testbundle.bundle
        import shutil
        import os

        self.bundle_dir = os.path.dirname(testbundle.bundle.__file__)
        self.rc = get_runconfig((os.path.join(self.bundle_dir, 'source-test-config.yaml'),
                                 os.path.join(self.bundle_dir, 'bundle.yaml'),
                                 RunConfig.USER_ACCOUNTS))

        self.copy_or_build_bundle()

        bundle = Bundle()

        self.source_save_dir = str(self.rc.group('filesystem').root) + '-source'

        self.setup_source_dir()

        print "Deleting: {}".format(self.rc.group('filesystem').root)
        ambry.util.rm_rf(self.rc.group('filesystem').root)

        bdir = os.path.join(self.rc.sourcerepo.dir, 'testbundle')

        pats = shutil.ignore_patterns('build', 'build-save', '*.pyc', '.git', '.gitignore', '.ignore', '__init__.py')

        print "Copying test dir tree to ", bdir
        shutil.copytree(bundle.bundle_dir, bdir, ignore=pats)

        # Import the bundle file from the directory
        from ambry.run import import_file

        rp = os.path.realpath(os.path.join(bdir, 'bundle.py'))
        mod = import_file(rp)

        dir_ = os.path.dirname(rp)
        self.bundle = mod.Bundle(dir_)

        print self.bundle.bundle_dir
Example #9
0
def do_source_run(ident, args, l, st, rc):
    from ambry.run import import_file
    from ambry.source.repository.git import GitRepository

    root = ident.bundle_path

    if args.python:

        import inspect

        try:
            mod = import_file(args.python)
        except ImportError:
            import ambry.cli.source_run as sr

            f = os.path.join(os.path.dirname(sr.__file__), args.python + ".py")
            try:
                mod = import_file(f)
            except ImportError:
                raise
                fatal(
                    "Could not get python file neither '{}', nor '{}'".format(
                        args.python,
                        f))

        run_args = inspect.getargspec(mod.run)

        a = {}

        if 'bundle_dir' in run_args.args:
            a['bundle_dir'] = root

        if 'args' in run_args.args:
            a['args'] = args.terms

        if 'bundle' in run_args.args:
            rp = os.path.join(root, 'bundle.py')
            bundle_mod = import_file(rp)
            dir_ = os.path.dirname(rp)
            try:
                a['bundle'] = bundle_mod.Bundle(dir_)
            except Exception as e:
                warn("Failed to load bundle from dir: {}: {}", dir_, str(e))
                raise

        mod.run(**a)

    elif args.repo_command == 'install':
        prt("--- {} {}", args.repo_command, root)
        bundle_class = load_bundle(root)
        bundle = bundle_class(root)

        bundle.run_install()

    elif args.repo_command == 'shell':

        cmd = ' '.join(args.terms)

        saved_path = os.getcwd()
        os.chdir(root)
        prt('----- {}', root)
        prt('----- {}', cmd)

        os.system(cmd)
        prt('')
        os.chdir(saved_path)
Example #10
0
def do_source_run(ident, args, l, st, rc):
    from ambry.run import import_file
    from ambry.source.repository.git import GitRepository

    root = ident.bundle_path

    if args.python:

        import inspect

        try:
            mod = import_file(args.python)
        except ImportError:
            import ambry.cli.source_run as sr

            f = os.path.join(os.path.dirname(sr.__file__), args.python + ".py")
            try:
                mod = import_file(f)
            except ImportError:
                raise
                fatal(
                    "Could not get python file neither '{}', nor '{}'".format(
                        args.python, f))

        run_args = inspect.getargspec(mod.run)

        a = {}

        if 'bundle_dir' in run_args.args:
            a['bundle_dir'] = root

        if 'args' in run_args.args:
            a['args'] = args.terms

        if 'bundle' in run_args.args:
            rp = os.path.join(root, 'bundle.py')
            bundle_mod = import_file(rp)
            dir_ = os.path.dirname(rp)
            try:
                a['bundle'] = bundle_mod.Bundle(dir_)
            except Exception as e:
                warn("Failed to load bundle from dir: {}: {}", dir_, str(e))
                raise

        mod.run(**a)

    elif args.repo_command == 'install':
        prt("--- {} {}", args.repo_command, root)
        bundle_class = load_bundle(root)
        bundle = bundle_class(root)

        bundle.run_install()

    elif args.repo_command == 'shell':

        cmd = ' '.join(args.terms)

        saved_path = os.getcwd()
        os.chdir(root)
        prt('----- {}', root)
        prt('----- {}', cmd)

        os.system(cmd)
        prt('')
        os.chdir(saved_path)