Create tar directory when making build set tar files.

Move the mkdir and removeall code from the build module to the path
module.
This commit is contained in:
Chris Johns 2013-02-22 14:44:51 +11:00
parent cafbcc611b
commit ee47d7210e
3 changed files with 41 additions and 31 deletions

View File

@ -44,14 +44,6 @@ import path
# #
version = '0.1' version = '0.1'
def removeall(path):
def _onerror(function, path, excinfo):
print 'removeall error: (%r) %s' % (function, path)
shutil.rmtree(path, onerror = _onerror)
return
def _notice(opts, text): def _notice(opts, text):
if not opts.quiet() and not log.default.has_stdout(): if not opts.quiet() and not log.default.has_stdout():
print text print text
@ -107,7 +99,7 @@ class build:
def __init__(self, name, create_tar_files, _defaults, opts): def __init__(self, name, create_tar_files, _defaults, opts):
self.opts = opts self.opts = opts
self.create_tar_files = create_tar_files self.create_tar_files = create_tar_files
_notice(opts, 'building: ' + name) _notice(opts, 'config: ' + name)
self.config = config.file(name, _defaults = _defaults, opts = opts) self.config = config.file(name, _defaults = _defaults, opts = opts)
self.script = script(quiet = opts.quiet(), trace = opts.trace()) self.script = script(quiet = opts.quiet(), trace = opts.trace())
@ -119,27 +111,12 @@ class build:
self._output('removing: %s' % (path.host(rmpath))) self._output('removing: %s' % (path.host(rmpath)))
if not self.opts.dry_run(): if not self.opts.dry_run():
if path.exists(rmpath): if path.exists(rmpath):
removeall(rmpath) path.removeall(rmpath)
def mkdir(self, mkpath): def mkdir(self, mkpath):
self._output('making dir: %s' % (path.host(mkpath))) self._output('making dir: %s' % (path.host(mkpath)))
if not self.opts.dry_run(): if not self.opts.dry_run():
if os.name == 'nt': path.mkdir(mkpath)
try:
os.makedirs(path.host(mkpath))
except IOError, err:
_notice(self.opts, 'warning: cannot make directory: %s' % (mkpath))
except OSError, err:
_notice(self.opts, 'warning: cannot make directory: %s' % (mkpath))
except WindowsError, err:
_notice(self.opts, 'warning: cannot make directory: %s' % (mkpath))
else:
try:
os.makedirs(path.host(mkpath))
except IOError, err:
_notice(self.opts, 'warning: cannot make directory: %s' % (mkpath))
except OSError, err:
_notice(self.opts, 'warning: cannot make directory: %s' % (mkpath))
def get_file(self, url, local): def get_file(self, url, local):
if local is None: if local is None:
@ -369,7 +346,7 @@ class build:
self._output('run: ' + cmd) self._output('run: ' + cmd)
exit_code, proc, output = e.shell(cmd, cwd = path.host(cwd)) exit_code, proc, output = e.shell(cmd, cwd = path.host(cwd))
if exit_code != 0: if exit_code != 0:
raise error.general('shell cmd failed: %s' % (os.path.relpath(cmd))) raise error.general('shell cmd failed: %s' % (cmd))
def builddir(self): def builddir(self):
builddir = self.config.abspath('_builddir') builddir = self.config.abspath('_builddir')

View File

@ -24,8 +24,11 @@
# #
import os import os
import shutil
import string import string
import error
windows = os.name == 'nt' windows = os.name == 'nt'
def host(path): def host(path):
@ -81,6 +84,36 @@ def isfile(path):
def isabspath(path): def isabspath(path):
return path[0] == '/' return path[0] == '/'
def mkdir(path):
if exists(path):
if not isdir(path):
raise error.general('path exists and is not a directory: %s' % (path))
else:
if windows:
try:
os.makedirs(host(path))
except IOError, err:
raise error.general('cannot make directory: %s' % (path))
except OSError, err:
raise error.general('cannot make directory: %s' % (path))
except WindowsError, err:
raise error.general('cannot make directory: %s' % (path))
else:
try:
os.makedirs(host(path))
except IOError, err:
raise error.general('cannot make directory: %s' % (path))
except OSError, err:
raise error.general('cannot make directory: %s' % (path))
def removeall(path):
def _onerror(function, path, excinfo):
print 'removeall error: (%r) %s' % (function, path)
shutil.rmtree(path, onerror = _onerror)
return
if __name__ == '__main__': if __name__ == '__main__':
print host('/a/b/c/d-e-f') print host('/a/b/c/d-e-f')
print host('//a/b//c/d-e-f') print host('//a/b//c/d-e-f')

View File

@ -127,10 +127,10 @@ class buildset:
def last_package(self, _build, tmproot): def last_package(self, _build, tmproot):
if self.opts.get_arg('--bset-tar-file'): if self.opts.get_arg('--bset-tar-file'):
tar = path.join(_build.config.expand('%{_tardir}'), tardir = _build.config.expand('%{_tardir}')
_build.config.expand('%s.tar.bz2' % (self.bset_pkg))) path.mkdir(tardir)
_notice(self.opts, 'tarball: %s -> %s' % tar = path.join(tardir, _build.config.expand('%s.tar.bz2' % (self.bset_pkg)))
(os.path.relpath(path.host(tmproot)), os.path.relpath(path.host(tar)))) _notice(self.opts, 'tarball: %s' % (os.path.relpath(path.host(tar))))
if not self.opts.dry_run(): if not self.opts.dry_run():
cmd = _build.config.expand("'cd " + tmproot + \ cmd = _build.config.expand("'cd " + tmproot + \
" && %{__tar} -cf - . | %{__bzip2} > " + tar + "'") " && %{__tar} -cf - . | %{__bzip2} > " + tar + "'")