def run(self): # create tmp script file name self._scriptfile = '/tmp/conduct.PBuilderExecCmds.%s.sh' \ % hashlib.md5(str(time.time)).hexdigest() # create script with commands script = '#!/bin/sh\n' self.cmds.append('exit') # exit the jail at the end for cmd in self.cmds: script += '''echo '%s' \n''' % cmd self.log.debug('Generated script:\n%s' % script) with open(self._scriptfile, 'w') as f: f.write(script) # pipe commands to pbuilder cmd = 'sh %s | pbuilder --login ' % self._scriptfile if self.save: cmd += '--save-after-login ' cmd += '--configfile %s' % self.config systemCall(cmd, log=self.log)
def run(self): cwd = os.getcwd() try: os.chdir(self.sourcedir) cmd = 'pdebuild --configfile %s' % self.config systemCall(cmd, log=self.log) finally: os.chdir(cwd)
def run(self): cmds = [] for i in range(len(self.partitions)): cmds += self._createPartitionCmds(i+1, self.partitions[i]) cmds.append('p') # print partition table cmds.append('w') # write partition table cmds.append('') # confirm shCmd = '(%s)' % ''.join([ 'echo %s;' % entry for entry in cmds]) shCmd += '| fdisk %s 2>&1' % self.dev systemCall(shCmd, log=self.log)
def run(self): systemCall('git clone %s %s' % (self.url, self.destdir), log=self.log) if self.uselastversion: self.target = self._determineLastVersion() if self.target: checkoutCmd = 'git --git-dir=%s/.git --work-tree=%s checkout %s' % ( self.destdir, self.destdir, self.target ) if self.asbranch: checkoutCmd += ' -b %s' % self.asbranch systemCall(checkoutCmd, log=self.log)
def run(self): cwd = os.getcwd() try: os.chdir(self.workingdir) self.commandoutput = systemCall(self.command, log=self.log) finally: os.chdir(cwd)
def run(self): cmd = 'debootstrap --verbose --arch=%s ' % self.arch if self.includes: cmd += '--include %s ' % ','.join(self.includes) if self._isForeignArch(): # separate first and second stage cmd += '--foreign ' cmd += '%s %s' % (self.distribution, self.destdir) self.log.info('Bootstrapping ...') systemCall(cmd, log=self.log) if self._isForeignArch(): self._strapSecondStage()
def run(self): # create device files systemCall('kpartx -v -a -s %s' % self.dev, log=self.log) # request a proper formated list of devs out = systemCall('kpartx -v -l -s %s' % self.dev, log=self.log) # store loop dev self.loopdev = re.findall('(/dev/.*?) ', out)[0] # store created device file paths self.mapped = [] for line in out.splitlines(): devFile = line.rpartition(':')[0].strip() self.mapped.append(path.join('/dev/mapper', devFile)) self.log.info('Loop device: %s' % self.loopdev) self.log.info('Mapped devices: %s' % ', '.join(self.mapped))
def run(self): # request a proper formated list of created devs out = systemCall('kpartx -v -l -s %s' % self.dev, log=self.log) # create device files systemCall('kpartx -v -a -s %s' % self.dev, log=self.log) # store loop dev self.loopdev = re.findall('(/dev/.*?) ', out)[0] # store created device file paths self.mapped = [] for line in out.splitlines(): devFile = line.rpartition(':')[0].strip() self.mapped.append(path.join('/dev/mapper', devFile)) self.log.info('Loop device: %s' % self.loopdev) self.log.info('Mapped devices: %s' % ', '.join(self.mapped))
def _determineLastVersion(self): self.log.debug('Determine last version ...') # find last tag tags = systemCall('git --git-dir=%s/.git --work-tree=%s tag -l' % ( self.destdir, self.destdir), log=self.log).splitlines() tags = sorted([LooseVersion(entry.strip()) for entry in tags]) result = tags[-1].vstring self.log.debug('Last version: %s' % result) return result
def run(self): self._syscall = lambda cmd: (chrootedSystemCall(self.chrootdir, cmd, log=self.log) \ if self.chrootdir else systemCall(cmd, log=self.log)) self._installCmd = 'env DEBIAN_FRONTEND=noninteractive ' \ 'apt-get install --yes --force-yes ' \ '--no-install-recommends ' \ '-o Dpkg::Options::="--force-overwrite" ' \ '-o Dpkg::Options::="--force-confnew" ' \ '%s' if self.depsonly: deps = self._determineDependencies() for pkg in deps: self._syscall(self._installCmd % pkg) else: # install actual pkg self._syscall(self._installCmd % self.pkg)
def run(self): systemCall('mkfs -t %s %s' % (self.fstype, self.dev), log=self.log)
def cleanup(self): systemCall('kpartx -v -d -s %s' % self.dev, log=self.log)