try:
spec = rpm.SpecFile(spec_to_parse)
- except GbpError, err:
+ except GbpError as err:
raise GbsError('%s' % err)
binary_list.append(spec.name)
log.warning('local repo: %s does not exist' % repo)
continue
opt_repo = SafeURL(repo)
- except ValueError, err:
+ except ValueError as err:
log.warning('Invalid repo %s: %s' % (repo, str(err)))
else:
repos.append(opt_repo)
% distconf)
try:
shutil.copy(buildconf, distconf)
- except IOError, err:
+ except IOError as err:
raise GbsError("Failed to copy build conf: %s" % (str(err)))
if not os.path.exists(distconf):
continue
deps_path.append(gnmapper.get_gerritname_by_obsname(pkg))
- except OSCError, err:
+ except OSCError as err:
raise GbsError(str(err))
sync_source(None, deps_path, url, download_path)
shutil.copy(buildconf, distconf)
log.info('build conf has been downloaded at:\n %s' \
% distconf)
- except IOError, err:
+ except IOError as err:
raise GbsError("Failed to copy build conf: %s" % (str(err)))
profile.buildconf = distconf
local_pkgs.append(pkg)
else:
log.error('package %s parse failed' %spec.name)
- except GbpError, err:
+ except GbpError as err:
log.warning('gbp parse spec failed. %s' % err)
if args.full_build:
try:
repo = RpmGitRepository(args.gitdir)
- except GitRepositoryError, err:
+ except GitRepositoryError as err:
raise GbsError(str(err))
packaging_dir = get_packaging_dir(args)
build_env = os.environ
build_env['PS1'] = "(tizen-build-env)@\h \W]\$ "
subprocess.call(cmd, env=build_env)
- except OSError, err:
+ except OSError as err:
raise GbsError('failed to chroot to %s: %s' % (build_root, err))
except KeyboardInterrupt:
log.info('keyboard interrupt ...')
log.warning('local repo: %s does not exist' % repo)
continue
opt_repo = SafeURL(repo)
- except ValueError, err:
+ except ValueError as err:
log.warning('Invalid repo %s: %s' % (repo, str(err)))
else:
repos.append(opt_repo)
% distconf)
try:
shutil.copy(buildconf, distconf)
- except IOError, err:
+ except IOError as err:
raise GbsError("Failed to copy build conf: %s" % (str(err)))
if not os.path.exists(distconf):
try:
repo = RpmGitRepository(args.gitdir)
- except GitRepositoryError, err:
+ except GitRepositoryError as err:
raise GbsError(str(err))
tmp = Temp(prefix='gbp_', dirn=configmgr.get('tmpdir', 'general'),
log.error(errmsg)
if ret:
raise GbsError("Failed to export packaging files from git tree")
- except GitRepositoryError, excobj:
+ except GitRepositoryError as excobj:
raise GbsError("Repository error: %s" % excobj)
workdir = args.gitdir
try:
repo = RpmGitRepository(workdir)
- except GitRepositoryError, err:
+ except GitRepositoryError as err:
raise GbsError(str(err))
log.debug("read repo path")
utils.read_localconf(repo.path)
specfile = os.path.basename(main_spec)
try:
spec = rpm.SpecFile(os.path.join(export_dir, specfile))
- except GbpError, err:
+ except GbpError as err:
raise GbsError('%s' % err)
if not spec.name or not spec.version:
try:
repo = RpmGitRepository(args.gitdir)
- except GitRepositoryError, err:
+ except GitRepositoryError as err:
raise GbsError(str(err))
workdir = repo.path
# get 'name' and 'version' from spec file
try:
spec = gbp.rpm.SpecFile(spec_to_parse)
- except GbpError, err:
+ except GbpError as err:
raise GbsError('%s' % err)
if not spec.name:
status[obs_repo][obs_arch]))
log.info('build log for %s/%s/%s/%s' % (target_prj, package,
obs_repo, obs_arch))
- print api.get_buildlog(target_prj, package, obs_repo, obs_arch)
+ print(api.get_buildlog(target_prj, package, obs_repo, obs_arch))
return 0
log.info('no build results from build server')
return 0
- except OSCError, err:
+ except OSCError as err:
raise GbsError(str(err))
with utils.Workdir(workdir):
try:
commit_msg = repo.get_commit_info(args.commit or 'HEAD')['subject']
- except GitRepositoryError, exc:
+ except GitRepositoryError as exc:
raise GbsError('failed to get commit info: %s' % exc)
files = glob.glob("%s/*" % exportdir)
api.create_package(target_prj, package)
# new project - submitting all local files
commit_files = files
- except OSCError, err:
+ except OSCError as err:
raise GbsError(str(err))
if not commit_files:
repo = RpmGitRepository(workdir)
commit = repo.rev_parse(args.commit)
current_branch = repo.get_branch()
- except GitRepositoryError, err:
+ except GitRepositoryError as err:
raise GbsError(str(err))
try:
try:
repo.create_tag(tagname, msg=message, commit=commit, sign=args.sign,
keyid=args.user_key)
- except GitRepositoryError, err:
+ except GitRepositoryError as err:
raise GbsError('failed to create tag %s: %s ' % (tagname, str(err)))
log.info("pushing tag to remote '%s'" % args.remote)
try:
repo.push_tag(args.remote, tagname)
- except GitRepositoryError, err:
+ except GitRepositoryError as err:
repo.delete_tag(tagname)
raise GbsError('failed to push tag %s :%s' % (tagname, str(err)))
cfgparser.get('general', 'work_dir') == '.':
cfgparser.set('general', 'work_dir',
os.path.abspath(os.path.dirname(fpath)))
- except Error, err:
+ except Error as err:
raise errors.ConfigError('config file error:%s' % err)
self._cfgparsers.append(cfgparser)
self._cfgparsers.append(self._create_default_parser())
with open(fpath, 'w') as wfile:
wfile.write(self.DEFAULT_CONF_TEMPLATE)
- os.chmod(fpath, 0600)
+ os.chmod(fpath, 0o600)
log.warning('Created a new config file %s. Please check and edit '
'your authentication information.' % fpath)
for cfgparser in self._cfgparsers:
try:
return cfgparser.get(section, opt)
- except Error, err:
+ except Error as err:
pass
raise errors.ConfigError(err)
try:
options.update(cfgparser.options(section))
sect_found = True
- except Error, err:
+ except Error as err:
pass
if not sect_found:
val = self._get('passwdx', section)
try:
ret = decode_passwdx(val)
- except (TypeError, IOError), err:
+ except (TypeError, IOError) as err:
raise errors.ConfigError('passwdx:%s' % err)
else:
ret = self._get(opt, section)
for cfgparser in cfgparsers:
try:
cfgparser.update()
- except IOError, err:
+ except IOError as err:
log.warning('update config file error: %s' % err)
password = url.password or parent.common_password
try:
self.url = SafeURL(url.url, user, password)
- except ValueError, err:
+ except ValueError as err:
raise errors.ConfigError('%s for %s' % (str(err), url.url))
def dump(self, fhandler):
value = re.sub(r'\$\{([^}]+)\}', r'%(\1)s', value)
try:
value = value % general_keys
- except KeyError, err:
+ except KeyError as err:
raise errors.ConfigError('unknown key: %s. Supportted '\
'keys are %s' % (str(err), ' '.join( \
self.DEFAULTS['general'].keys())))
dump_general(fhandler)
profile.dump(fhandler)
shutil.move(tmp.path, os.path.expanduser(fname))
- except IOError, err:
+ except IOError as err:
raise errors.ConfigError(err)
log.warning('subcommand oriented style of config is deprecated. '
if name == 'passwdx':
try:
value = decode_passwdx(value)
- except (TypeError, IOError), err:
+ except (TypeError, IOError) as err:
raise errors.ConfigError('Error decoding %s: %s' % \
(opt, err))
repos[key]['passwd'] = value
if oscrc:
try:
conf.get_config(override_conffile=oscrc)
- except OSError, err:
+ except OSError as err:
if err.errno == 1:
# permission problem, should be the chmod(0600) issue
raise ObsError('Current user has no write permission '\
try:
return method(url, data=data, file=filep)
except (urllib2.URLError, M2Crypto.m2urllib2.URLError,
- M2Crypto.SSL.SSLError, ssl.SSLError), err:
+ M2Crypto.SSL.SSLError, ssl.SSLError) as err:
if count == 3:
raise OSCError(str(err))
# Create target meta
meta = '<project name="%s"><title></title>'\
- '<description>%s</description>'\
+ '<description>%s</description>'\
'<person role="maintainer" userid="%s"/>' % \
(target, description, conf.get_apiurl_usr(self.apiurl))
if linkto:
for name in repos:
if linkedbuild:
meta += '<repository name="%s" linkedbuild="%s">' % \
- (name, linkedbuild)
+ (name, linkedbuild)
else:
meta += '<repository name="%s">' % name
meta += '<path project="%s" repository="%s" />' % (src, name)
# Create project and set its meta
core.edit_meta('prj', path_args=quote_plus(target), data=meta)
except (urllib2.URLError, M2Crypto.m2urllib2.URLError,
- M2Crypto.SSL.SSLError), err:
+ M2Crypto.SSL.SSLError) as err:
raise ObsError("Can't set meta for %s: %s" % (target, str(err)))
# don't need set project config if no src project
try:
config = core.show_project_conf(self.apiurl, src)
except (urllib2.URLError, M2Crypto.m2urllib2.URLError,
- M2Crypto.SSL.SSLError), err:
+ M2Crypto.SSL.SSLError) as err:
raise ObsError("Can't get config from project %s: %s" \
% (src, str(err)))
self.apiurl, False)
try:
self.core_http(core.http_PUT, url, data=''.join(config))
- except OSCError, err:
+ except OSCError as err:
raise ObsError("can't copy config from %s to %s: %s" \
% (src, target, err))
url = core.makeurl(self.apiurl, ['source', prj], query)
try:
self.core_http(core.http_DELETE, url)
- except OSCError, err:
+ except OSCError as err:
raise ObsError("can't delete project %s: %s" % (prj, err))
def exists(self, prj, pkg=''):
try:
core.meta_exists(metatype=metatype, path_args=path_args,
create_new=False, apiurl=self.apiurl)
- except urllib2.HTTPError, err:
+ except urllib2.HTTPError as err:
if err.code == 404:
return False
except (urllib2.URLError, M2Crypto.m2urllib2.URLError, \
- M2Crypto.SSL.SSLError), err:
+ M2Crypto.SSL.SSLError) as err:
pass
except SSLVerificationError:
raise ObsError("SSL verification error.")
try:
return core.rebuild(self.apiurl, prj, pkg, repo=None, arch=arch)
except (urllib2.URLError, M2Crypto.m2urllib2.URLError, \
- M2Crypto.SSL.SSLError), err:
+ M2Crypto.SSL.SSLError) as err:
raise ObsError("Can't trigger rebuild for %s/%s: %s" % \
(prj, pkg, str(err)))
except SSLVerificationError:
def commit_files(self, prj, pkg, files, message):
"""Commits files to OBS."""
- query = {'cmd' : 'commitfilelist',
- 'user' : conf.get_apiurl_usr(self.apiurl),
+ query = {'cmd': 'commitfilelist',
+ 'user': conf.get_apiurl_usr(self.apiurl),
'comment': message,
'keeplink': 1}
url = core.makeurl(self.apiurl, ['source', prj, pkg], query=query)
query="rev=repository")
self.core_http(core.http_PUT, put_url, filep=fpath)
self.core_http(core.http_POST, url, data=xml)
- except OSCError, err:
+ except OSCError as err:
raise ObsError("can't commit files to %s/%s: %s" % (prj, pkg, err))
def create_package(self, prj, pkg):
self.apiurl, False)
try:
self.core_http(core.http_PUT, url, data=meta)
- except OSCError, err:
+ except OSCError as err:
raise ObsError("can't create %s/%s: %s" % (prj, pkg, err))
def get_results(self, prj, pkg):
try:
build_status = core.get_results(self.apiurl, prj, pkg)
except (urllib2.URLError, M2Crypto.m2urllib2.URLError,
- M2Crypto.SSL.SSLError), err:
+ M2Crypto.SSL.SSLError) as err:
raise ObsError("can't get %s/%s build results: %s" \
% (prj, pkg, str(err)))
'_log?nostream=1&start=0'])
try:
log = self.core_http(core.http_GET, url).read()
- except OSCError, err:
+ except OSCError as err:
raise ObsError("can't get %s/%s build log: %s" % (prj, pkg, err))
return log.translate(None, "".join([chr(i) for i in \
- range(10) + range(11, 32)]))
+ range(10) + range(11, 32)]))
@staticmethod
def get_path(prj, pkg=None):
'return True is it is local path'
return self.startswith('/')
- def pathjoin(self, *args):
+ def pathjoin(self, args):
'''treat self as path and urljoin'''
- new = urlparse.urljoin(self.rstrip('/') + '/', *args)
+ new = urlparse.urljoin(self.rstrip('/') + '/', args)
return SafeURL(new, self.user, self.passwd)
def _get_userinfo(self):
(fds, path) = tempfile.mkstemp(suffix, prefix, dirn)
os.close(fds)
if content:
- with file(path, 'w+') as fobj:
+ #python3 will not support file, use open
+ with open(path, 'w+') as fobj:
fobj.write(content)
- except OSError, err:
+ except OSError as err:
raise GbsError("Failed to create dir or file on %s: %s" % \
(target_dir, str(err)))
self.path = path
original_handler = signal.signal(signal.SIGINT, handler)
try:
curl.perform()
- except pycurl.error, err:
+ except pycurl.error as err:
log.debug('fetching error:%s' % str(err))
errcode, errmsg = err.args
git.rev_parse(opts.commit)
is_clean = git.is_clean()[0]
status = git.status()
- except (GbpError, GitRepositoryError), err:
+ except (GbpError, GitRepositoryError) as err:
raise GbsError(str(err))
untracked_files = status['??']
with Workdir(git_path):
return subprocess.Popen(args,
stdout=subprocess.PIPE).communicate()[0]
- except (subprocess.CalledProcessError, OSError), err:
+ except (subprocess.CalledProcessError, OSError) as err:
log.debug('failed to checkout %s from %s:%s' % (relative_path,
commit_id, str(err)))
return None
with Workdir(git_path):
output = subprocess.Popen(args,
stdout=subprocess.PIPE).communicate()[0]
- except (subprocess.CalledProcessError, OSError), err:
+ except (subprocess.CalledProcessError, OSError) as err:
raise GbsError('failed to check existence of %s in %s:%s' % (
relative_path, commit_id, str(err)))
with Workdir(git_path):
output = subprocess.Popen(args,
stdout=subprocess.PIPE).communicate()[0]
- except (subprocess.CalledProcessError, OSError), err:
+ except (subprocess.CalledProcessError, OSError) as err:
raise GbsError('failed to glob %s in %s:%s' % (
pattern, commit_id, str(err)))
try:
with open(target_fname, 'w') as fobj:
fobj.write(changes)
- except IOError, err:
+ except IOError as err:
raise GbsError("Can't update %s: %s" % (target_fname, str(err)))
return True
"""Get version from module __init__.py"""
path = os.path.join(mod_name, "__init__.py")
if not os.path.isfile(path):
- print 'No %s version file found' % path
+ print('No %s version file found' % path)
sys.exit(1)
content = open(path).read()
if match:
return match.group(1)
- print 'Unable to find version in %s' % path
+ print('Unable to find version in %s' % path)
sys.exit(1)
check_debian()
from gitbuildsys.errors import ConfigError
import gitbuildsys.conf
-
+#after python3.0, reload has been moved to imp std lib.
+from imp import reload
FILE_DIRNAME = os.path.dirname(os.path.abspath(__file__))
"chroot", "chr"]:
try:
- print '>>>sub', sub
+ print('>>>sub', sub)
GBS(argv=["gbs", sub, "--help"])
- except SystemExit, err:
+ except SystemExit as err:
eq_(err.code, 0)
@staticmethod
"""Test running gbs --help and gbs help."""
try:
GBS(argv=["gbs", "--help"])
- except SystemExit, err:
+ except SystemExit as err:
eq_(err.code, 0)
from test_config import Fixture
+#after python3.0, reload has been moved to imp std lib.
+from imp import reload
class FakeFile(object):
'Fake file used to get updated config file'
from test_config import Fixture
from test_passwdx import FakeFile
+#after python3.0, reload has been moved to imp std lib.
+from imp import reload
def get_profile():
'''get current profile to test'''
except KeyboardInterrupt:
log.LOGGER.error('^C caught, program aborted.')
- except errors.Usage, usage:
+ except errors.Usage as usage:
log.LOGGER.error(str(usage))
- except errors.CmdError, err:
+ except errors.CmdError as err:
if log.LOGGER.level == log.DEBUG:
import traceback
log.LOGGER.error(traceback.format_exc())