def execute(cwd, cmd, args=[], quiet=False): ''' Run the given command. ''' stdout = None stderr = None if quiet: stdout = subprocess.PIPE stderr = subprocess.STDOUT try: process = subprocess.Popen([cmd] + args, stdout=stdout, stderr=stderr, cwd=cwd) output = process.communicate()[0] exitcode = process.returncode if exitcode: raise Exception('Not null exit value') if quiet: output = re.sub(' +', ' ', output) output = re.sub('\n\n', '\n', output) output = re.sub('\n ', '\n', output) return output, exitcode except Exception as e: console.fail('[Failed - %s] %s' % (cmd, str(e)))
def execute(envcopy, command, path = "", preexec = "", silent = False): if path: envcopy.append('cd "%s"' % path) if preexec: envcopy.append(preexec) # envcopy.append('entryenv=`env`') # envcopy.append('if %s; then exitenv=`env`; if [[ "$entryenv" == "$exitenv" ]]; then exit 0; fi; echo "Env change!" >&2; echo $entryenv >&2; echo $exitenv >&2; fi; exit 1' % command) envcopy.append('if %s; then exit 0; fi; exit 1' % command) std = puke.Std() console.info('Running command:') for i in envcopy: console.info(i) puke.sh(envcopy, std=std, output = False) if std.code == 1: if silent: raise() console.debug("Monade shell stdout:", std.out) console.fail("Monade shell stderr: %s" % std.err) console.debug("Monade shell stdout:", std.out) if std.err: console.warn("Monade shell stderr:", std.err) return std
def __dopkg(path): console.info('Processing pkg') try: std = puke.Std() puke.sh('sudo installer -pkg %s -target /' % path, std = std) if std.err: raise std.err except: console.fail('Retry your task with the following stance: sudo echo "lame workaround"; puke MYTASK')
def __init__(self, name): yawn = puke.FileSystem.join('technicolor', '%s.yaml' % name) if not puke.FileSystem.exists(yawn): console.fail('The requested yawn (%s, at path %s) doesn\'t exist!' % (name, yawn)) data = yaml.load(puke.FileSystem.readfile(yawn)) self.name = name # Extend this so that multiple targets can be supported self.done = {} if 'LICENSE' in data: self.license = data['LICENSE'] else: console.error('We are missing license information!') self.license = 'UNKNOWN' if 'VERSION' in data: self.version = data['VERSION'] else: console.warn('We are missing version information') self.version = 'No version specified!' if 'URL' in data: self.url = data['URL'].replace('{VERSION}', self.version) self.__checksum = data['CHECKSUM'] if 'LOCAL' in data: self.local = data['LOCAL'].replace('{VERSION}', self.version) else: self.local = self.url.split('/').pop().split('.').shift() self.production = data['PRODUCTION'] else: console.info('This is a dummy package') self.url = '' self.__checksum = '' self.local = '' self.production = '' self.hack = False if 'HACK' in data: self.hack = data['HACK'] if 'DEPENDS' in data: self.depends = data['DEPENDS'] if isinstance(self.depends, str) and self.depends: self.depends = [self.depends] else: self.depends = [] if 'TOOLCHAIN' in data: self.toolchain = data['TOOLCHAIN'] if isinstance(self.toolchain, str) and self.toolchain: self.toolchain = [self.toolchain] else: self.toolchain = []
def bootstrap(args = "", preexec= ""): if fs.exists(fs.join(environ.src, technicolor.local, 'bootstrap')): command = fs.join(environ.src, technicolor.local, 'bootstrap') elif fs.exists(fs.join(environ.src, technicolor.local, 'bootstrap.sh')): command = fs.join(environ.src, technicolor.local, 'bootstrap.sh') elif fs.exists(fs.join(environ.src, technicolor.local, '..', 'bootstrap')): command = fs.join(environ.src, technicolor.local, '..', 'bootstrap') else: console.fail('Calling bootstrap but there is nothing like that around!') command = '%s --prefix="%s" --with-toolset=$MY_BOOST_TOOLSET %s' % (command, environ.prefix, args) # --libdir="%s/lib" environ.prefix, shell.execute(environ.flush(), command, environ.pwd, preexec)
def __init__(self, target): self.__data = yaml.load(self.__data) if not target in self.__data: console.fail('Requested target (%s) is not supported. Describe it to your env.yaml.' % target) self.__data = self.__data[target] self.target = target self.prefix = '' self.tmp = '' self.src = '' self.debug = False self.static = False
def fetch(self, tmp, clean = False): url = self.url # Garde-fou if not url: console.fail('Can\'t fetch unspecified url, can I?') # Complete local path type = url.split('.').pop().lower() # Unpack it # Git repositories if type == 'git': pwd = puke.FileSystem.join(tmp, self.local.split(puke.os.sep).pop(0)) console.info('Git repository') if self.hack: self.__dogit(url, pwd, self.hack) else: self.__dogit(url, pwd) else: pwd = puke.FileSystem.join(tmp, self.local) # Remove the directory if clean requested if clean and self.local and puke.FileSystem.exists(pwd): console.info('Cleaning unpack directory') puke.FileSystem.remove(pwd) # If the directory is here already, just return if puke.FileSystem.exists(pwd): return False # Copy locally puke.deepcopy(url, tmp); # Verify checksum localtmp = puke.FileSystem.join(tmp, url.split('/').pop()) if puke.FileSystem.checksum(localtmp) != self.__checksum: console.fail("PANIC! Archive doesn't pan out. You may puke -c if in doubt, and anyhow double check integrity. %s vs. %s" % (puke.FileSystem.checksum(localtmp), self.__checksum)) if type == 'dmg': console.info('Processing dmg') self.__dodmg(localtmp, self.local, pwd) elif type == 'pkg': console.info('Processing pkg') self.__dopkg(localtmp) else: console.info('Processing archive file') self.__dounpack(localtmp, puke.FileSystem.dirname(pwd)) return True
def patch(project, patch, revert=False): ''' Apply the given patch to the given project. ''' patch_cmd = ['patch', '-p1', '-d', project] dry_options = ['--dry-run', '-R', '-f', '-s', '-i'] if not os.path.exists(patch): console.fail(patch + ' does not exist.') # First check if the patch can be applied to the project. patch_applicable = subprocess.call(patch_cmd + dry_options + [patch]) # Apply the patch if project is clean and revert flag is not set. if not revert and patch_applicable: if subprocess.call(patch_cmd + ['-i', patch]): console.fail('Failed to apply ' + patch) # Revert the patch if the project already contains the modifications. if revert and not patch_applicable: if subprocess.call(patch_cmd + ['-i', patch, '-R']): console.fail('Failed to revert ' + patch)