# Only guess spec filename here, parse later when we have the correct
# spec file at hand
specfile = utils.guess_spec(workdir, opts.spec)
- packaging_dir = os.path.join(workdir, 'packaging/')
- export_dir = tempfile.mkdtemp(prefix=packaging_dir + 'build_')
+ packaging_dir = os.path.join(workdir, 'packaging/', 'build_')
+ tmpd = utils.Temp(prefix=packaging_dir, directory=True)
+ export_dir = tmpd.path
with utils.Workdir(workdir):
if opts.commit:
commit = opts.commit
msger.info('keyboard interrupt, killing build ...')
subprocess.call(cmd + ["--kill"])
msger.error('interrupt from keyboard')
- finally:
- import shutil
- shutil.rmtree(export_dir, ignore_errors=True)
# Only guess spec filename here, parse later when we have the correct
# spec file at hand
specfile = utils.guess_spec(workdir, opts.spec)
- export_dir = tempfile.mkdtemp(prefix='gbs_export_', dir=outdir)
+ tempd = Temp(prefix='gbs_export_', dirn=outdir, directory=True)
+ export_dir = tempd.path
with utils.Workdir(workdir):
if opts.commit:
commit = opts.commit
if not os.access(tmpdir, os.W_OK|os.R_OK|os.X_OK):
msger.error('No access permission to %s, please check' % tmpdir)
- oscrc = OSCRC_TEMPLATE % {
- "http_debug": 1 if msger.get_loglevel() == 'debug' else 0,
- "debug": 1 if msger.get_loglevel() == 'verbose' else 0,
- "apiurl": APISERVER,
- "user": USER,
- "passwdx": PASSWDX,
- }
- (fds, oscrcpath) = tempfile.mkstemp(dir=tmpdir, prefix='.oscrc')
- os.close(fds)
- with file(oscrcpath, 'w+') as foscrc:
- foscrc.write(oscrc)
-
# TODO: check ./packaging dir at first
specs = glob.glob('%s/packaging/*.spec' % workdir)
if not specs:
else:
target_prj = opts.target_obsprj
+ # Create temporary oscrc
+ oscrc = OSCRC_TEMPLATE % {
+ "http_debug": 1 if msger.get_loglevel() == 'debug' else 0,
+ "debug": 1 if msger.get_loglevel() == 'verbose' else 0,
+ "apiurl": APISERVER,
+ "user": USER,
+ "passwdx": PASSWDX,
+ }
+
+ tmpf = Temp(dirn=tmpdir, prefix='.oscrc', content=oscrc)
+ oscrcpath = tmpf.path
+
if opts.buildlog:
bs = buildservice.BuildService(apiurl=APISERVER, oscrc=oscrcpath)
archlist = []
except GitRepositoryError, exc:
msger.error('failed to get commit info: %s' % exc)
- os.unlink(oscrcpath)
msger.info('local changes submitted to build server successfully')
msger.info('follow the link to monitor the build progress:\n'
' %s/package/show?package=%s&project=%s' \
specfile = specs[0]
return specfile
+class Temp(object):
+ """
+ Create temporary file or directory.
+ Delete it automatically when object is destroyed.
+
+ """
+
+ def __init__(self, suffix='', prefix='tmp', dirn=None,
+ directory=False, content=None):
+ """
+ Create file or directory using tempfile.mk[sd]temp.
+ If content is provided write it to the file.
+
+ """
+ self.directory = directory
+
+ if directory:
+ path = tempfile.mkdtemp(suffix, prefix, dirn)
+ else:
+ (fds, path) = tempfile.mkstemp(suffix, prefix, dirn)
+ os.close(fds)
+ if content:
+ with file(path, 'w+') as fobj:
+ fobj.write(content)
+
+ self.path = path
+
+ def __del__(self):
+ """Remove it when object is destroyed."""
+ if os.path.exists(self.path):
+ if self.directory:
+ shutil.rmtree(self.path, True)
+ else:
+ os.unlink(self.path)
+
class TempCopy(object):
"""Copy original file to temporary file in the same directory as
original. Creates empty termporary file if original doesn't exist.
msger.error(traceback.format_exc())
else:
msger.error('\n'+str(err))
+
+ except Exception:
+ import traceback
+ msger.error(traceback.format_exc())