Exemple #1
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())
Exemple #2
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())
Exemple #3
0
    def bundle_deps(self,name, reverse=False):
        '''Dependencies for a particular bundle'''
        from ambry.identity import Identity
        
        ident = Identity.parse_name(name)
        name = ident.name

        out = []
        all_deps = self.dependencies

        if reverse:

            out = set()
            
            def reverse_set(name):
                o = set()
                for k,v in all_deps.items():
                    if name in v:
                        o.add(k)
                return o
            
            deps = reverse_set(name)
            while len(deps):

                out.update(deps)
                
                next_deps = set()
                for name in deps:
                    next_deps.update(reverse_set(name))

                deps = next_deps

            out = list(out)
             
        else:
            
            deps = all_deps.get(ident.name,[])
            while len(deps) > 0:
                out += deps
                next_deps = []
                for d in deps:
                    if d in all_deps:
                        next_deps += all_deps[d]
                        
                deps = next_deps
                
        final = []
        
        for n in reversed(out):
            if not n in final:
                final.append(n) 
                
        return final
Exemple #4
0
    def bundle_deps(self, name, reverse=False):
        """Dependencies for a particular bundle."""
        from ambry.identity import Identity

        ident = Identity.parse_name(name)
        name = ident.name

        out = []
        all_deps = self.dependencies

        if reverse:

            out = set()

            def reverse_set(name):
                o = set()
                for k, v in all_deps.items():
                    if name in v:
                        o.add(k)
                return o

            deps = reverse_set(name)
            while len(deps):

                out.update(deps)

                next_deps = set()
                for name in deps:
                    next_deps.update(reverse_set(name))

                deps = next_deps

            out = list(out)

        else:

            deps = all_deps.get(ident.name, [])
            while len(deps) > 0:
                out += deps
                next_deps = []
                for d in deps:
                    if d in all_deps:
                        next_deps += all_deps[d]

                deps = next_deps

        final = []

        for n in reversed(out):
            if not n in final:
                final.append(n)

        return final
Exemple #5
0
def source_build(args, l, st, rc):
    """Build a single bundle, or a set of bundles in a directory.

    The build process will build all dependencies for each bundle before
    buildng the bundle.

    """

    from ambry.identity import Identity
    from ..source.repository import new_repository

    repo = new_repository(rc.sourcerepo(args.name))

    dir_ = None
    name = None

    if args.dir:
        if os.path.exists(args.dir):
            dir_ = args.dir
            name = None
        else:
            name = args.dir
            try:
                Identity.parse_name(name)
            except:
                fatal(
                    "Argument '{}' must be either a bundle name or a directory".format(name))
                return

    if not dir_:
        dir_ = rc.sourcerepo.dir

    def build(bundle_dir):
        from ambry.library import new_library

        # Import the bundle file from the directory

        bundle_class = load_bundle(bundle_dir)
        bundle = bundle_class(bundle_dir)

        l = new_library(rc.library(args.library_name))

        if l.get(bundle.identity.vid) and not args.force:
            prt("{} Bundle is already in library", bundle.identity.name)
            return
        elif bundle.is_built and not args.force and not args.clean:
            prt("{} Bundle is already built", bundle.identity.name)
            return
        else:

            if args.dryrun:
                prt("{} Would build but in dry run ", bundle.identity.name)
                return

            repo.bundle = bundle

            if args.clean:
                bundle.clean()

            # Re-create after cleaning is important for something ...

            bundle = bundle_class(bundle_dir)

            prt("{} Building ", bundle.identity.name)

            if not bundle.run_prepare():
                fatal("{} Prepare failed", bundle.identity.name)

            if not bundle.run_build():
                fatal("{} Build failed", bundle.identity.name)

        if args.install and not args.dryrun:
            if not bundle.run_install(force=True):
                fatal('{} Install failed', bundle.identity.name)

    build_dirs = {}

    # Find all of the dependencies for the named bundle, and make those first.
    for root, _, files in os.walk(rc.sourcerepo.dir):
        if 'bundle.yaml' in files:
            bundle_class = load_bundle(root)
            bundle = bundle_class(root)
            build_dirs[bundle.identity.name] = root

    if name:
        deps = repo.bundle_deps(name)
        deps.append(name)

    else:

        deps = []

        # Walk the subdirectory for the files to build, and
        # add all of their dependencies
        for root, _, files in os.walk(dir_):
            if 'bundle.yaml' in files:

                bundle_class = load_bundle(root)
                bundle = bundle_class(root)

                for dep in repo.bundle_deps(bundle.identity.name):
                    if dep not in deps:
                        deps.append(dep)

                deps.append(bundle.identity.name)

    for n in deps:
        try:
            dir_ = build_dirs[n]
        except KeyError:
            fatal("Failed to find directory for bundle {}".format(n))

        prt('')
        prt("{} Building in {}".format(n, dir_))
        build(dir_)
Exemple #6
0
def source_build(args, l, st, rc):
    """Build a single bundle, or a set of bundles in a directory.

    The build process will build all dependencies for each bundle before
    buildng the bundle.

    """

    from ambry.identity import Identity
    from ..source.repository import new_repository

    repo = new_repository(rc.sourcerepo(args.name))

    dir_ = None
    name = None

    if args.dir:
        if os.path.exists(args.dir):
            dir_ = args.dir
            name = None
        else:
            name = args.dir
            try:
                Identity.parse_name(name)
            except:
                fatal(
                    "Argument '{}' must be either a bundle name or a directory"
                    .format(name))
                return

    if not dir_:
        dir_ = rc.sourcerepo.dir

    def build(bundle_dir):
        from ambry.library import new_library

        # Import the bundle file from the directory

        bundle_class = load_bundle(bundle_dir)
        bundle = bundle_class(bundle_dir)

        l = new_library(rc.library(args.library_name))

        if l.get(bundle.identity.vid) and not args.force:
            prt("{} Bundle is already in library", bundle.identity.name)
            return
        elif bundle.is_built and not args.force and not args.clean:
            prt("{} Bundle is already built", bundle.identity.name)
            return
        else:

            if args.dryrun:
                prt("{} Would build but in dry run ", bundle.identity.name)
                return

            repo.bundle = bundle

            if args.clean:
                bundle.clean()

            # Re-create after cleaning is important for something ...

            bundle = bundle_class(bundle_dir)

            prt("{} Building ", bundle.identity.name)

            if not bundle.run_prepare():
                fatal("{} Prepare failed", bundle.identity.name)

            if not bundle.run_build():
                fatal("{} Build failed", bundle.identity.name)

        if args.install and not args.dryrun:
            if not bundle.run_install(force=True):
                fatal('{} Install failed', bundle.identity.name)

    build_dirs = {}

    # Find all of the dependencies for the named bundle, and make those first.
    for root, _, files in os.walk(rc.sourcerepo.dir):
        if 'bundle.yaml' in files:
            bundle_class = load_bundle(root)
            bundle = bundle_class(root)
            build_dirs[bundle.identity.name] = root

    if name:
        deps = repo.bundle_deps(name)
        deps.append(name)

    else:

        deps = []

        # Walk the subdirectory for the files to build, and
        # add all of their dependencies
        for root, _, files in os.walk(dir_):
            if 'bundle.yaml' in files:

                bundle_class = load_bundle(root)
                bundle = bundle_class(root)

                for dep in repo.bundle_deps(bundle.identity.name):
                    if dep not in deps:
                        deps.append(dep)

                deps.append(bundle.identity.name)

    for n in deps:
        try:
            dir_ = build_dirs[n]
        except KeyError:
            fatal("Failed to find directory for bundle {}".format(n))

        prt('')
        prt("{} Building in {}".format(n, dir_))
        build(dir_)