exit(0)
class util:
+ @staticmethod
+ def clear_tmpdir(path=None):
+ """
+ Ensure the given directory (or TASK_TMPDIR if none given)
+ exists and is empty.
+ """
+ if path == None:
+ path = current_task().tmpdir
+ if os.path.exists(path):
+ p = subprocess.Popen(['rm', '-rf', path])
+ stdout, stderr = p.communicate(None)
+ if p.returncode != 0:
+ raise Exception('rm -rf %s: %s' % (path, stderr))
+ os.mkdir(path)
+
@staticmethod
def run_command(execargs, **kwargs):
- if 'stdin' not in kwargs:
- kwargs['stdin'] = subprocess.PIPE
- if 'stdout' not in kwargs:
- kwargs['stdout'] = subprocess.PIPE
- if 'stderr' not in kwargs:
- kwargs['stderr'] = subprocess.PIPE
- p = subprocess.Popen(execargs, close_fds=True, shell=False,
- **kwargs)
+ kwargs.setdefault('stdin', subprocess.PIPE)
+ kwargs.setdefault('stdout', subprocess.PIPE)
+ kwargs.setdefault('stderr', sys.stderr)
+ kwargs.setdefault('close_fds', True)
+ kwargs.setdefault('shell', False)
+ p = subprocess.Popen(execargs, **kwargs)
stdoutdata, stderrdata = p.communicate(None)
if p.returncode != 0:
- raise Exception("run_command %s exit %d:\n%s" %
- (execargs, p.returncode, stderrdata))
+ raise errors.CommandFailedError(
+ "run_command %s exit %d:\n%s" %
+ (execargs, p.returncode, stderrdata))
return stdoutdata, stderrdata
@staticmethod
outfile.write(buf)
outfile.close()
if len(files_got) < len(files):
- raise Exception("Wanted files %s but only got %s from %s" % (files, files_got, map(lambda z: z.name(), list(CollectionReader(collection).all_files()))))
+ raise errors.AssertionError(
+ "Wanted files %s but only got %s from %s" %
+ (files, files_got,
+ [z.name() for z in CollectionReader(collection).all_files()]))
- os.symlink(collection, os.path.join(path, '.locator'))
+ os.symlink(collection_hash, os.path.join(path, '.locator'))
lockfile.close()
return path
self.set_current_stream_name(newstreamname)
def set_current_stream_name(self, newstreamname):
if re.search(r'[ \t\n]', newstreamname):
- raise AssertionError("Manifest stream names cannot contain whitespace")
+ raise errors.AssertionError(
+ "Manifest stream names cannot contain whitespace")
- self._current_stream_name = newstreamname
+ self._current_stream_name = '.' if newstreamname=='' else newstreamname
def current_stream_name(self):
return self._current_stream_name
def finish_current_stream(self):