1
0
mirror of https://github.com/openSUSE/osc.git synced 2025-08-05 15:13:39 +02:00

- added 3 new methods:

* createPackageDir(): create and initialize a new package dir in
    the given project.
  * get_apiurl_usr(): returns the username for a certain apiurl
  * get_configParser(): returns an ConfigParser() object which can be
    used for parsing the ~/.oscrc file
- fixed username issues when creating a new package (the problem was
  that the username for the default host was used and not the one for
  that specific apiurl)
- some small fixes in the do_importsrcpkg() method
This commit is contained in:
Marcus Hüwe
2008-03-15 22:51:37 +00:00
parent c307449167
commit 5d57d7e299
3 changed files with 104 additions and 66 deletions

View File

@@ -939,26 +939,7 @@ class Osc(cmdln.Cmdln):
if len(args) != 1:
print >>sys.stderr, 'wrong number of arguments!'
sys.exit(1)
prj_dir, pac_dir = getPrjPacPaths(args[0])
if is_project_dir(prj_dir):
if not os.path.exists(args[0]):
prj = Project(prj_dir, False)
if prj.addPackage(pac_dir):
os.mkdir(args[0])
os.chdir(args[0])
init_package_dir(prj.apiurl,
prj.name,
pac_dir, pac_dir, files=False)
os.chdir(prj.absdir)
print statfrmt('A', os.path.normpath(args[0]))
else:
print '\'%s\' already exists' % args[0]
sys.exit(1)
else:
print 'wrong number of arguments or ' \
'\'%s\' is not a working copy' % prj_dir
sys.exit(1)
createPackageDir(args[0])
def do_addremove(self, subcmd, opts, *args):
@@ -1859,6 +1840,9 @@ class Osc(cmdln.Cmdln):
srpm = os.path.basename(srpm)
srpm = os.path.abspath(srpm)
if not os.path.isfile(srpm):
print >>sys.stderr, 'file \'%s\' does not exist' % srpm
sys.exit(1)
if opts.project:
project_dir = opts.project
@@ -1866,19 +1850,13 @@ class Osc(cmdln.Cmdln):
project_dir = os.curdir
if not is_project_dir(project_dir):
print >>sys.stderr, 'project dir \'%s\' does not exist' % opts.project
print >>sys.stderr, 'project dir \'%s\' does not exist' % project_dir
sys.exit(1)
else:
if conf.config['do_package_tracking']:
project = Project(project_dir)
else:
project = store_read_project(project_dir)
# act as if run with -A `cat $project_dir/.osc/_apiurl`
# to get apiurl and user right
apiurl = store_read_apiurl(project_dir)
conf.get_config(override_conffile = self.options.conffile,
override_http_debug = self.options.http_debug,
override_apisrv = apiurl)
rpm_data = data_from_rpm(srpm, 'Name:', 'Summary:', '%description')
if rpm_data:
@@ -1900,20 +1878,20 @@ class Osc(cmdln.Cmdln):
sys.exit(1)
olddir = os.getcwd()
if not os.path.exists(os.path.join(project_dir, pac)):
os.mkdir(os.path.join(project_dir, pac))
os.chdir(os.path.join(project_dir, pac))
if conf.config['do_package_tracking']:
if project.addPackage(pac):
init_package_dir(conf.config['apiurl'], project.name, pac, os.path.join(project.dir, pac), files=False)
else:
sys.exit(1)
if conf.config['do_package_tracking']:
if createPackageDir(os.path.join(project.dir, pac), project):
os.chdir(os.path.join(project.dir, pac))
else:
sys.exit(1)
else:
if not os.path.exists(os.path.join(project_dir, pac)):
apiurl = store_read_apiurl(project_dir)
user = conf.get_apiurl_usr(apiurl)
data = meta_exists(metatype='pkg',
path_args=(quote_plus(project), quote_plus(pac)),
template_args=({
'name': pac,
'user': conf.config['user']}))
'user': user}), apiurl=apiurl)
if data:
data = ET.fromstring(''.join(data))
data.find('title').text = title
@@ -1924,34 +1902,37 @@ class Osc(cmdln.Cmdln):
sys.exit(1)
edit_meta(metatype='pkg',
path_args=(quote_plus(project), quote_plus(pac)),
data = data)
init_package_dir(conf.config['apiurl'], project, pac, os.path.join(project, pac))
unpack_srcrpm(srpm, os.getcwd())
p = Package(os.getcwd())
if len(p.filenamelist) == 0 and opts.commit:
print 'Adding files to working copy...'
addFiles(glob.glob('*'))
if conf.config['do_package_tracking']:
os.chdir(olddir)
project.commit((pac, ))
else:
p.update_datastructs()
p.commit()
elif opts.commit and opts.delete_old_files:
for file in p.filenamelist:
p.delete_remote_source_file(file)
p.update_local_filesmeta()
print 'Adding files to working copy...'
addFiles(glob.glob('*'))
data = data, apiurl=apiurl)
os.mkdir(os.path.join(project_dir, pac))
os.chdir(os.path.join(project_dir, pac))
init_package_dir(apiurl, project, pac, os.path.join(project, pac))
else:
print >>sys.stderr, 'error - local package already exists'
sys.exit(1)
unpack_srcrpm(srpm, os.getcwd())
p = Package(os.getcwd())
if len(p.filenamelist) == 0 and opts.commit:
print 'Adding files to working copy...'
addFiles(glob.glob('*'))
if conf.config['do_package_tracking']:
os.chdir(olddir)
project.commit((pac, ))
else:
p.update_datastructs()
p.commit()
else:
print 'No files were committed to the server. Please ' \
'commit them manually.'
print 'Package \'%s\' only imported locally' % pac
sys.exit(1)
elif opts.commit and opts.delete_old_files:
for file in p.filenamelist:
p.delete_remote_source_file(file)
p.update_local_filesmeta()
print 'Adding files to working copy...'
addFiles(glob.glob('*'))
p.update_datastructs()
p.commit()
else:
print >>sys.stderr, 'error - local package already exists'
print 'No files were committed to the server. Please ' \
'commit them manually.'
print 'Package \'%s\' only imported locally' % pac
sys.exit(1)
print 'Package \'%s\' imported successfully' % pac

View File

@@ -112,6 +112,21 @@ def parse_apisrv_url(scheme, apisrv):
else:
return scheme, apisrv
def get_apiurl_usr(apiurl):
"""
returns the user for this host - if this host does not exist in the
configfile the default user is returned.
"""
import sys
scheme, apisrv = parse_apisrv_url(None, apiurl)
cp = get_configParser()
try:
return cp.get(apisrv, 'user')
except ConfigParser.NoSectionError:
print >>sys.stderr, 'section [\'%s\'] does not exist - using default user: \'%s\'' \
% (apisrv, config['user'])
return config['user']
def init_basicauth(config):
"""initialize urllib2 with the credentials for Basic Authentication"""
@@ -162,6 +177,21 @@ def init_basicauth(config):
authhandler.add_password(None, host, auth['user'], auth['pass'])
def get_configParser(conffile=None, force_read=False):
"""
Returns an ConfigParser() object. After its first invocation the
ConfigParser object is stored in a method attribute and this attribute
is returned unless you pass force_read=True.
"""
import os
conffile = conffile or os.environ.get('OSC_CONFIG', '~/.oscrc')
conffile = os.path.expanduser(conffile)
if force_read or not get_configParser.__dict__.has_key('cp'):
get_configParser.cp = ConfigParser.SafeConfigParser(DEFAULTS)
get_configParser.cp.read(conffile)
return get_configParser.cp
def get_config(override_conffile = None,
override_http_debug = None,
override_apisrv = None):
@@ -213,8 +243,7 @@ def get_config(override_conffile = None,
# okay, we made sure that .oscrc exists
cp = ConfigParser.SafeConfigParser(DEFAULTS)
cp.read(conffile)
cp = get_configParser(conffile)
if not cp.has_section('general'):
# FIXME: it might be sufficient to just assume defaults?

View File

@@ -420,11 +420,12 @@ class Project:
if pac in self.pacs_available:
print 'package \'%s\' already exists' % pac
else:
user = conf.get_apiurl_usr(self.apiurl)
edit_meta(metatype='pkg',
path_args=(quote_plus(self.name), quote_plus(pac)),
template_args=({
'name': pac,
'user': conf.config['user']}),
'user': user}),
apiurl=self.apiurl)
# display the correct dir when sending the changes
olddir = os.getcwd()
@@ -485,11 +486,12 @@ class Project:
p.todo = files
p.commit(msg)
else:
user = conf.get_apiurl_usr(self.apiurl)
edit_meta(metatype='pkg',
path_args=(quote_plus(project), quote_plus(package)),
template_args=({
'name': pac,
'user': conf.config['user']}),
'user': user}),
apiurl=apiurl)
try:
p = Package(pac_path)
@@ -651,7 +653,7 @@ class Package:
query = []
query.append('cmd=commit')
query.append('rev=upload')
query.append('user=%s' % conf.config['user'])
query.append('user=%s' % conf.get_apiurl_usr(self.apiurl))
query.append('comment=%s' % quote_plus(msg))
u = makeurl(self.apiurl, ['source', self.prjname, self.name], query=query)
@@ -3033,6 +3035,32 @@ def delMaintainer(apiurl, prj, pac, user):
else:
print "an error occured"
def createPackageDir(pathname, prj_obj=None):
"""
create and initialize a new package dir in the given project.
prj_obj can be a Project() instance.
"""
prj_dir, pac_dir = getPrjPacPaths(pathname)
if is_project_dir(prj_dir):
if not os.path.exists(pac_dir):
prj = prj_obj or Project(prj_dir, False)
if prj.addPackage(pac_dir):
os.mkdir(pathname)
os.chdir(pathname)
init_package_dir(prj.apiurl,
prj.name,
pac_dir, pac_dir, files=False)
os.chdir(prj.absdir)
print statfrmt('A', os.path.normpath(pathname))
return True
else:
print '\'%s\' already exists' % pathname
return False
else:
print '\'%s\' is not a working copy' % prj_dir
return False
def addFiles(filenames):
for filename in filenames:
if not os.path.exists(filename):