mirror of
https://github.com/openSUSE/osc.git
synced 2025-01-28 23:46:13 +01:00
- cleanup: use exceptions
This commit is contained in:
parent
f47c19d209
commit
59073eaff5
@ -3830,10 +3830,8 @@ Please submit there instead, or use --nodevelproject to force direct submission.
|
|||||||
|
|
||||||
olddir = os.getcwd()
|
olddir = os.getcwd()
|
||||||
if conf.config['do_package_tracking']:
|
if conf.config['do_package_tracking']:
|
||||||
if createPackageDir(os.path.join(project.dir, pac), project):
|
createPackageDir(os.path.join(project.dir, pac), project)
|
||||||
os.chdir(os.path.join(project.dir, pac))
|
os.chdir(os.path.join(project.dir, pac))
|
||||||
else:
|
|
||||||
sys.exit(1)
|
|
||||||
else:
|
else:
|
||||||
if not os.path.exists(os.path.join(project_dir, pac)):
|
if not os.path.exists(os.path.join(project_dir, pac)):
|
||||||
apiurl = store_read_apiurl(project_dir)
|
apiurl = store_read_apiurl(project_dir)
|
||||||
|
54
osc/core.py
54
osc/core.py
@ -427,7 +427,8 @@ class Project:
|
|||||||
import fnmatch
|
import fnmatch
|
||||||
for i in conf.config['exclude_glob']:
|
for i in conf.config['exclude_glob']:
|
||||||
if fnmatch.fnmatch(pac, i):
|
if fnmatch.fnmatch(pac, i):
|
||||||
return False
|
msg = 'invalid package name: \'%s\' (see \'exclude_glob\' config option)' % pac
|
||||||
|
raise oscerr.OscIOError(None, msg)
|
||||||
state = self.get_state(pac)
|
state = self.get_state(pac)
|
||||||
if state == None or state == 'D':
|
if state == None or state == 'D':
|
||||||
self.new_package_entry(pac, 'A')
|
self.new_package_entry(pac, 'A')
|
||||||
@ -436,10 +437,8 @@ class Project:
|
|||||||
# it would take too much time to update all data structs regularly
|
# it would take too much time to update all data structs regularly
|
||||||
if pac in self.pacs_unvers:
|
if pac in self.pacs_unvers:
|
||||||
self.pacs_unvers.remove(pac)
|
self.pacs_unvers.remove(pac)
|
||||||
return True
|
|
||||||
else:
|
else:
|
||||||
print 'package \'%s\' is already under version control' % pac
|
raise oscerr.PackageExists(self.name, pac, 'package \'%s\' is already under version control' % pac)
|
||||||
return False
|
|
||||||
|
|
||||||
def delPackage(self, pac, force = False):
|
def delPackage(self, pac, force = False):
|
||||||
state = self.get_state(pac.name)
|
state = self.get_state(pac.name)
|
||||||
@ -4232,39 +4231,32 @@ def createPackageDir(pathname, prj_obj=None):
|
|||||||
if is_project_dir(prj_dir):
|
if is_project_dir(prj_dir):
|
||||||
if not os.path.exists(pac_dir):
|
if not os.path.exists(pac_dir):
|
||||||
prj = prj_obj or Project(prj_dir, False)
|
prj = prj_obj or Project(prj_dir, False)
|
||||||
if prj.addPackage(pac_dir):
|
prj.addPackage(pac_dir)
|
||||||
os.mkdir(pathname)
|
os.mkdir(pathname)
|
||||||
os.chdir(pathname)
|
os.chdir(pathname)
|
||||||
init_package_dir(prj.apiurl,
|
init_package_dir(prj.apiurl,
|
||||||
prj.name,
|
prj.name,
|
||||||
pac_dir, pac_dir, files=False)
|
pac_dir, pac_dir, files=False)
|
||||||
os.chdir(prj.absdir)
|
os.chdir(prj.absdir)
|
||||||
print statfrmt('A', os.path.normpath(pathname))
|
print statfrmt('A', os.path.normpath(pathname))
|
||||||
return True
|
|
||||||
else:
|
|
||||||
return False
|
|
||||||
else:
|
else:
|
||||||
print '\'%s\' already exists' % pathname
|
raise oscerr.OscIOError(None, 'file or directory \'%s\' already exists' % pathname)
|
||||||
return False
|
|
||||||
else:
|
else:
|
||||||
print '\'%s\' is not a working copy' % prj_dir
|
msg = '\'%s\' is not a working copy' % prj_dir
|
||||||
if os.path.exists(os.path.join(prj_dir, '.svn')):
|
if os.path.exists(os.path.join(prj_dir, '.svn')):
|
||||||
print 'try svn instead of osc.'
|
msg += '\ntry svn instead of osc.'
|
||||||
return False
|
raise oscerr.NoWorkingCopy(msg)
|
||||||
|
|
||||||
|
|
||||||
def addFiles(filenames, prj_obj = None):
|
def addFiles(filenames, prj_obj = None):
|
||||||
for filename in filenames:
|
for filename in filenames:
|
||||||
if not os.path.exists(filename):
|
if not os.path.exists(filename):
|
||||||
print >>sys.stderr, "file '%s' does not exist" % filename
|
raise oscerr.OscIOError(None, 'file \'%s\' does not exist' % filename)
|
||||||
return 1
|
|
||||||
|
|
||||||
# init a package dir if we have a normal dir in the "filenames"-list
|
# init a package dir if we have a normal dir in the "filenames"-list
|
||||||
# so that it will be find by findpacs() later
|
# so that it will be find by findpacs() later
|
||||||
for filename in filenames:
|
for filename in filenames:
|
||||||
|
|
||||||
prj_dir, pac_dir = getPrjPacPaths(filename)
|
prj_dir, pac_dir = getPrjPacPaths(filename)
|
||||||
|
|
||||||
if not is_package_dir(filename) and os.path.isdir(filename) and is_project_dir(prj_dir) \
|
if not is_package_dir(filename) and os.path.isdir(filename) and is_project_dir(prj_dir) \
|
||||||
and conf.config['do_package_tracking']:
|
and conf.config['do_package_tracking']:
|
||||||
old_dir = os.getcwd()
|
old_dir = os.getcwd()
|
||||||
@ -4274,21 +4266,17 @@ def addFiles(filenames, prj_obj = None):
|
|||||||
init_package_dir(prj_apiurl, prj_name, pac_dir, pac_dir, files=False)
|
init_package_dir(prj_apiurl, prj_name, pac_dir, pac_dir, files=False)
|
||||||
os.chdir(old_dir)
|
os.chdir(old_dir)
|
||||||
elif is_package_dir(filename) and conf.config['do_package_tracking']:
|
elif is_package_dir(filename) and conf.config['do_package_tracking']:
|
||||||
print >>sys.stderr, 'osc: warning: \'%s\' is already under version control' % filename
|
raise oscerr.PackageExists(store_read_project(filename), store_read_package(filename),
|
||||||
return 1
|
'osc: warning: \'%s\' is already under version control' % filename)
|
||||||
elif os.path.isdir(filename) and is_project_dir(prj_dir):
|
elif os.path.isdir(filename) and is_project_dir(prj_dir):
|
||||||
print >>sys.stderr, 'osc: cannot add a directory to a project unless ' \
|
raise oscerr.WrongArgs('osc: cannot add a directory to a project unless ' \
|
||||||
'\'do_package_tracking\' is enabled in the configuration file'
|
'\'do_package_tracking\' is enabled in the configuration file')
|
||||||
return 1
|
|
||||||
|
|
||||||
pacs = findpacs(filenames)
|
pacs = findpacs(filenames)
|
||||||
|
|
||||||
for pac in pacs:
|
for pac in pacs:
|
||||||
if conf.config['do_package_tracking'] and not pac.todo:
|
if conf.config['do_package_tracking'] and not pac.todo:
|
||||||
prj = prj_obj or Project(os.path.dirname(pac.absdir), False)
|
prj = prj_obj or Project(os.path.dirname(pac.absdir), False)
|
||||||
if pac.name in prj.pacs_unvers:
|
if pac.name in prj.pacs_unvers:
|
||||||
if not prj.addPackage(pac.name):
|
prj.addPackage(pac.name)
|
||||||
sys.exit(1)
|
|
||||||
print statfrmt('A', getTransActPath(os.path.join(pac.dir, os.pardir, pac.name)))
|
print statfrmt('A', getTransActPath(os.path.join(pac.dir, os.pardir, pac.name)))
|
||||||
for filename in pac.filenamelist_unvers:
|
for filename in pac.filenamelist_unvers:
|
||||||
pac.todo.append(filename)
|
pac.todo.append(filename)
|
||||||
|
Loading…
Reference in New Issue
Block a user