def generate(self): """Generate patches from customized bdists. Limitations for now: one patchset per bdist, only apply to bdist with the same name. """ for name, abspath in self.cmds.list("cloned").items(): # create dir for bdist in patches if not exists patches_dir = self.cfg["patches_dir"] if not os.path.isabs(patches_dir): patches_dir = os.path.join(self.root, patches_dir) targetdir = os.path.join(patches_dir, name) if not os.path.isdir(patches_dir): os.mkdir(patches_dir) if not os.path.isdir(targetdir): os.mkdir(targetdir) # format-patch there if Popen(["git", "status", "--porcelain"], stdout=PIPE, cwd=abspath).communicate()[0]: logger.warn("Ignoring egg with uncommitted changes: %s." % (abspath,)) continue tmp = Popen(["git", "branch", "--no-color"], cwd=abspath, stdout=PIPE).communicate()[0].split("\n") currentbranch = None for x in tmp: if x.startswith("*"): currentbranch = x.split()[1] break else: raise CouldNotDetectCurrentBranch if currentbranch == "__mrsd_patched__": logger.error("Ignoring egg on __mrsd_patched__ branch: %s." % (abspath,)) return check_call(["git", "format-patch", "-o", targetdir, "initial..HEAD"], cwd=abspath)
def get_dependency_map(self): """Build the dependency map - extras are already reduced. """ if not self.root: logger.error("Not rooted, run 'mrsd init'.") sys.exit(0) src_dir = os.path.join(self.root, 'src') if not os.path.isdir(src_dir): logger.error('Expected %s to be the source directory' % src_dir) sys.exit(0) # dependencies including extras for each egg dependencies = {} for name in os.listdir(src_dir): path = os.path.join(src_dir, name) # is it a dir? if not os.path.isdir(path): continue # does it have a .egg-info? egginfos = filter(lambda n: os.path.isdir(os.path.join(path, n)) \ and n.endswith('.egg-info'), os.listdir(path)) if len(egginfos) > 0: pkgname, requires = self._read_egginfo(os.path.join( path, egginfos[0])) dependencies[pkgname] = requires return self._reduce_extras(dependencies)
def __call__(self, dists=None, pargs=None): """Execute the command, will receive parser args from argparse, when run from cmdline. """ if not self.root: logger.error("Not rooted, run 'mrsd init'.") return if dists is None: dists = pargs.dist if not dists: return self.cmds.list() if type(dists) not in (tuple, list): dists = (dists,) for dist in dists: self._clone(dist)
def distFromPath(path): """Create distribution object living at path in the filesystem Path can be - a zipped file ending in .egg (zipped binary distribution) - a directory ending in .egg (unzipped binary distribution) - unspported """ if not os.path.isdir(path): msg = 'No distributions in singular files yet: %s.' % (path,) logger.error(msg) raise RuntimeError(msg) if not path.endswith('.egg'): msg = 'Only bdists ending in .egg so far: %s.' % (path,) logger.error(msg) raise RuntimeError(msg) head, tail = os.path.split(path) parent = BDistDirectory(head) dist = parent[tail] return dist
def __call__(self, channels=None, pargs=None): """So far we just list all distributions used by the current env """ if not os.path.isdir(os.path.join(self.root, 'eggs-mrsd')): os.mkdir(os.path.join(self.root, 'eggs-mrsd')) if not self.root: logger.error("Not rooted, run 'mrsd init'.") return if channels is None: if pargs is not None: channels = pargs.channel if type(channels) not in (tuple, list): channels = (channels,) for channel in channels: if channel == "cloned": cloned = Directory(os.path.join(self.root, 'eggs-mrsd')) return dict((x.__name__, x.abspath) for x in cloned.values()) pyscriptdir = PyScriptDir(os.path.join(self.root, 'bin')) return dict((x.__name__, x.abspath) for x in pyscriptdir.values())
def generate(self): """Generate patches from customized bdists. Limitations for now: one patchset per bdist, only apply to bdist with the same name. """ for name, abspath in self.cmds.list('cloned').items(): # create dir for bdist in patches if not exists patches_dir = self.cfg['patches_dir'] if not os.path.isabs(patches_dir): patches_dir = os.path.join(self.root, patches_dir) targetdir = os.path.join(patches_dir, name) if not os.path.isdir(patches_dir): os.mkdir(patches_dir) if not os.path.isdir(targetdir): os.mkdir(targetdir) # format-patch there if Popen(['git', 'status', '--porcelain'], stdout=PIPE, cwd=abspath).communicate()[0]: logger.warn('Ignoring egg with uncommitted changes: %s.' % (abspath,)) continue tmp = Popen(['git', 'branch', '--no-color'], cwd=abspath, stdout=PIPE).communicate()[0].split('\n') currentbranch = None for x in tmp: if x.startswith('*'): currentbranch = x.split()[1] break else: raise CouldNotDetectCurrentBranch if currentbranch == '__mrsd_patched__': logger.error('Ignoring egg on __mrsd_patched__ branch: %s.' % (abspath,)) return check_call(['git', 'format-patch', '-o', targetdir, 'initial..HEAD'], cwd=abspath)