コード例 #1
0
ファイル: git.py プロジェクト: kball/databundles
    def dependencies(self):
        '''Return a set of dependencies for the source packages'''
        from collections import defaultdict
        import os
        from databundles.identity import Identity
        from databundles.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())
コード例 #2
0
ファイル: git.py プロジェクト: kball/databundles
    def bundle_deps(self,name, reverse=False):
        '''Dependencies for a particular bundle'''
        from databundles.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
コード例 #3
0
ファイル: source.py プロジェクト: kball/databundles
def source_build(args,rc, src):
    '''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 databundles.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:  
                err("Argument '{}' must be either a bundle name or a directory")
                return
            
    if not dir_:
        dir_ = rc.sourcerepo.dir
        
    
        
    def build(bundle_dir):
        from databundles.library import new_library
        from databundles.source.repository.git import GitShellService
        
        # Stash must happen before pull, and pull must happen
        # before the class is loaded in load_bundle, otherwize the class
        # can't be updated by the pull. And, we have to use the GitShell
        # sevice directly, because thenew_repository route will ooad the bundle
        
        gss = GitShellService(bundle_dir)
        
        if args.stash:
            prt("{} Stashing ", bundle_dir)
            gss.stash()
            
        if args.pull:
            prt("{} Pulling ", bundle_dir)
            gss.pull()

        # 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))

        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():
                err("{} Prepare failed", bundle.identity.name)
            
            if not bundle.run_build():
                err("{} Build failed", bundle.identity.name)
            
        if args.install and not args.dryrun:
            if not bundle.run_install(force=True):
                err('{} 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:
            err("Failed to find directory for bundle {}".format(n))

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