# with this program; if not, write to the Free Software Foundation, Inc., 59
# Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+"""A wrapper to handle with OBS operations"""
+
from __future__ import with_statement
import os
import shutil
-import buildservice
-import runner
-import errors
-from utils import Workdir
+from common import buildservice
+from common import runner
+from common import errors
+from common.utils import Workdir
from osc import core, oscerr
else:
# branch from target project
print "branch package %s from %s" % (self._pkg, realprj)
- self._bs.branch_pkg(realprj, self._pkg, target_project=self._prj)
+ self._bs.branch_pkg(realprj, self._pkg, \
+ target_project=self._prj)
self._checkout_latest()
else:
# to init new package in local dir
self._mkpac()
def _mkpac(self):
+ """Make a package in OBS"""
print "mkpac %s %s" % (self._prj, self._pkg)
with Workdir(self._bdir):
self._bs.mk_pac(self._prj, self._pkg)
with Workdir(self._pkgpath):
try:
pac = core.findpacs([filename])[0]
- st, fn = sorted(pac.get_status(), lambda x, y: cmp(x[1], y[1]))[0]
- except oscerr.OscIOError, err:
+ status = sorted(pac.get_status(), key=lambda x: x[1])[0][0]
+ except oscerr.OscIOError:
return '?'
- return st
+ return status
def is_new_pkg(self):
- """Check whether this is new package in obs
+ """Check whether this is a new package in obs
"""
- print "%s package list:" % self._prj, self._bs.get_package_list(self._prj)
- if self._pkg in self._bs.get_package_list(self._prj):
+ packages = self._bs.get_package_list(self._prj)
+ print "%s package list:" % self._prj, packages
+ if self._pkg in packages:
print "%s is NOT new package in %s" % (self._pkg, self._prj)
return False
else:
return True
def get_workdir(self):
+ """Get package path"""
return self._pkgpath
def get_pkgname(self):
+ """Get package name"""
return self._pkg
def remove_all(self):
pac.delete_file(filename)
def add_file(self, fpath):
+ """Add a file with its' fpath to local package"""
# copy the file in
runner.quiet('/bin/cp -f %s %s' % (fpath, self._pkgpath))
print 'Invalid pac working dir, skip'
def commit(self, msg):
+ """Submit a package change to OBS with msg"""
with Workdir(self._pkgpath):
self._bs.submit(msg)
dst_pkg = self._pkg
with Workdir(self._pkgpath):
reqs = self._bs.get_request_list(dst_prj, dst_pkg)
- newreq = self._bs.submit_req(self._prj, self._pkg, dst_prj, dst_pkg, msg, src_update='cleanup')
+ newreq = self._bs.submit_req(self._prj, self._pkg, dst_prj, \
+ dst_pkg, msg, src_update='cleanup')
if supersede:
for req in reqs:
- self._bs.req_supersede(req.reqid, 'superseded by %s' % newreq, newreq)
+ self._bs.req_supersede(req.reqid, 'superseded by %s' % \
+ newreq, newreq)
return newreq