mirror of
https://github.com/openSUSE/osc.git
synced 2025-02-22 18:22:12 +01:00
- repairwc: repair a project wc (only missing '_apiurl' file so far)
This commit is contained in:
parent
48eaacef18
commit
4229eb6197
@ -6041,11 +6041,34 @@ Please submit there instead, or use --nodevelproject to force direct submission.
|
||||
${cmd_usage}
|
||||
${cmd_option_list}
|
||||
"""
|
||||
def get_apiurl(apiurls):
|
||||
print 'No apiurl is defined for this working copy.\n' \
|
||||
'Please choose one from the following list (enter the number):'
|
||||
for i in range(len(apiurls)):
|
||||
print ' %d) %s' % (i, apiurls[i])
|
||||
num = raw_input('> ')
|
||||
try:
|
||||
num = int(num)
|
||||
except ValueError:
|
||||
raise oscerr.WrongArgs('\'%s\' is not a number. Aborting' % num)
|
||||
if num < 0 or num >= len(apiurls):
|
||||
raise oscerr.WrongArgs('number \'%s\' out of range. Aborting' % num)
|
||||
return apiurls[num]
|
||||
|
||||
args = parseargs(args)
|
||||
pacs = []
|
||||
cp = conf.get_configParser(conf.config['conffile'])
|
||||
apiurls = [i.rstrip('/') for i in cp.sections() if i != 'general']
|
||||
for i in args:
|
||||
if is_project_dir(i):
|
||||
prj = Project(i, getPackageList=False)
|
||||
try:
|
||||
prj = Project(i, getPackageList=False)
|
||||
except oscerr.WorkingCopyInconsistent, e:
|
||||
apiurl = None
|
||||
if '_apiurl' in e.dirty_files:
|
||||
apiurl = get_apiurl(apiurls)
|
||||
prj = Project(i, getPackageList=False, wc_check=False)
|
||||
prj.wc_repair(apiurl)
|
||||
for p in prj.pacs_have:
|
||||
if p in prj.pacs_broken:
|
||||
continue
|
||||
@ -6058,26 +6081,13 @@ Please submit there instead, or use --nodevelproject to force direct submission.
|
||||
else:
|
||||
print >>sys.stderr, '\'%s\' is neither a project working copy ' \
|
||||
'nor a package working copy' % i
|
||||
cp = conf.get_configParser(conf.config['conffile'])
|
||||
apiurls = [i.rstrip('/') for i in cp.sections() if i != 'general']
|
||||
for pdir in pacs:
|
||||
try:
|
||||
p = Package(pdir)
|
||||
except oscerr.WorkingCopyInconsistent, e:
|
||||
apiurl = None
|
||||
if '_apiurl' in e.dirty_files:
|
||||
print 'No apiurl is defined for this package.\n' \
|
||||
'Please choose one from the following list (enter the number):'
|
||||
for i in range(len(apiurls)):
|
||||
print ' %d) %s' % (i, apiurls[i])
|
||||
num = raw_input('> ')
|
||||
try:
|
||||
num = int(num)
|
||||
except ValueError:
|
||||
raise oscerr.WrongArgs('\'%s\' is not a number. Aborting' % num)
|
||||
if num < 0 or num >= len(apiurls):
|
||||
raise oscerr.WrongArgs('number \'%s\' out of range. Aborting' % num)
|
||||
apiurl = apiurls[num]
|
||||
apiurl = get_apiurl(apiurls)
|
||||
p = Package(pdir, wc_check=False)
|
||||
p.wc_repair(apiurl)
|
||||
print 'done. Please check the state of the wc (via \'osc status %s\').' % i
|
||||
|
51
osc/core.py
51
osc/core.py
@ -414,14 +414,26 @@ def xmlindent(elem, level=0):
|
||||
|
||||
class Project:
|
||||
"""represent a project directory, holding packages"""
|
||||
def __init__(self, dir, getPackageList=True, progress_obj=None):
|
||||
REQ_STOREFILES = ('_project', '_apiurl')
|
||||
if conf.config['do_package_tracking']:
|
||||
REQ_STOREFILES += ('_packages',)
|
||||
def __init__(self, dir, getPackageList=True, progress_obj=None, wc_check=True):
|
||||
import fnmatch
|
||||
self.dir = dir
|
||||
self.absdir = os.path.abspath(dir)
|
||||
self.progress_obj = progress_obj
|
||||
|
||||
self.name = store_read_project(self.dir)
|
||||
self.apiurl = store_read_apiurl(self.dir, defaulturl=False)
|
||||
self.apiurl = store_read_apiurl(self.dir, defaulturl=not wc_check)
|
||||
|
||||
dirty_files = []
|
||||
if wc_check:
|
||||
dirty_files = self.wc_check()
|
||||
if dirty_files:
|
||||
msg = 'Your working copy \'%s\' is in an inconsistent state.\n' \
|
||||
'Please run \'osc repairwc %s\' and check the state\n' \
|
||||
'of the working copy afterwards (via \'osc status %s\')' % (self.dir, self.dir, self.dir)
|
||||
raise oscerr.WorkingCopyInconsistent(self.prjname, self.name, dirty_files, msg)
|
||||
|
||||
if getPackageList:
|
||||
self.pacs_available = meta_get_packagelist(self.apiurl, self.name)
|
||||
@ -448,6 +460,25 @@ class Project:
|
||||
|
||||
self.pacs_missing = [ i for i in self.pacs_available if i not in self.pacs_have ]
|
||||
|
||||
def wc_check(self):
|
||||
global store
|
||||
dirty_files = []
|
||||
for fname in Project.REQ_STOREFILES:
|
||||
if not os.path.exists(os.path.join(self.absdir, store, fname)):
|
||||
dirty_files.append(fname)
|
||||
return dirty_files
|
||||
|
||||
def wc_repair(self, apiurl=None):
|
||||
global store
|
||||
if not os.path.exists(os.path.join(self.dir, store, '_apiurl')):
|
||||
if apiurl is None:
|
||||
msg = 'cannot repair wc: the \'_apiurl\' file is missing but ' \
|
||||
'no \'apiurl\' was passed to wc_repair'
|
||||
# hmm should we raise oscerr.WrongArgs?
|
||||
raise oscerr.WorkingCopyInconsistent(self.prjname, self.name, [], msg)
|
||||
store_write_apiurl(self.dir, apiurl)
|
||||
self.apiurl = store_read_apiurl(self.dir, defaulturl=False)
|
||||
|
||||
def checkout_missing_pacs(self, expand_link=False):
|
||||
for pac in self.pacs_missing:
|
||||
|
||||
@ -4701,15 +4732,21 @@ def store_read_apiurl(dir, defaulturl=True):
|
||||
# (former osc versions may stored an apiurl with a trailing slash etc.)
|
||||
apiurl = conf.urljoin(*conf.parse_apisrv_url(None, url))
|
||||
except:
|
||||
if not defaulturl and is_package_dir(dir):
|
||||
if not defaulturl:
|
||||
if is_project_dir(dir):
|
||||
project = store_read_project(dir)
|
||||
package = None
|
||||
elif is_package_dir(dir):
|
||||
project = store_read_project(dir)
|
||||
package = None
|
||||
else:
|
||||
msg = 'Error: \'%s\' is not an osc package working copy' % os.path.abspath(dir)
|
||||
raise oscerr.NoWorkingCopy(msg)
|
||||
msg = 'Your working copy \'%s\' is in an inconsistent state.\n' \
|
||||
'Please run \'osc repairwc %s\' (Note this might _remove_\n' \
|
||||
'files from the .osc/ dir). Please check the state\n' \
|
||||
'of the working copy afterwards (via \'osc status %s\')' % (dir, dir, dir)
|
||||
raise oscerr.WorkingCopyInconsistent(store_read_project(dir), store_read_package(dir), ['_apiurl'], msg)
|
||||
elif not defaulturl:
|
||||
msg = 'Error: \'%s\' is not an osc package working copy' % os.path.abspath(dir)
|
||||
raise oscerr.NoWorkingCopy(msg)
|
||||
raise oscerr.WorkingCopyInconsistent(project, package, ['_apiurl'], msg)
|
||||
apiurl = conf.config['apiurl']
|
||||
return apiurl
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user