1
0
mirror of https://github.com/openSUSE/osc.git synced 2024-11-10 22:56:15 +01:00

Merge _expand_as_project_name into _process_project_name

This function was already doing most of the work, so we can do this
extra there as well. simplifies the code a little. also fix a regression
in previous change where Pwd.cwd().replace() would rename the directory
(rather than doing a replace on the string value).
This commit is contained in:
Dirk Müller 2022-10-18 23:38:28 +02:00
parent ca744aa7d7
commit 51d993c1e7
No known key found for this signature in database

View File

@ -75,16 +75,13 @@ class Osc(cmdln.Cmdln):
def get_version(self): def get_version(self):
return get_osc_version() return get_osc_version()
def _expand_as_project_name(self, arg):
if arg == '.':
if is_package_dir(Path.cwd()) or is_project_dir(Path.cwd()):
arg = store_read_project(Path.cwd())
else:
raise oscerr.WrongArgs('No working directory')
return arg
def _process_project_name(self, project): def _process_project_name(self, project):
if isinstance(project, str): if isinstance(project, str):
if project == '.':
if is_package_dir(Path.cwd()) or is_project_dir(Path.cwd()):
project = store_read_project(Path.cwd())
else:
raise oscerr.WrongArgs('No working directory')
return project.replace(conf.config['project_separator'], ':') return project.replace(conf.config['project_separator'], ':')
return project return project
@ -363,7 +360,7 @@ class Osc(cmdln.Cmdln):
if project == '/': if project == '/':
project = None project = None
if project == '.': if project == '.':
project = self._expand_as_project_name(project) project = self._process_project_name(project)
cwd = os.getcwd() cwd = os.getcwd()
if is_package_dir(cwd): if is_package_dir(cwd):
package = store_read_package(cwd) package = store_read_package(cwd)
@ -1438,6 +1435,7 @@ class Osc(cmdln.Cmdln):
dst_package = args[3] dst_package = args[3]
else: else:
dst_package = src_package dst_package = src_package
src_project = self._process_project_name(src_project)
dst_project = self._process_project_name(dst_project) dst_project = self._process_project_name(dst_project)
else: else:
self.argparse_error("Incorrect number of arguments.") self.argparse_error("Incorrect number of arguments.")
@ -1662,6 +1660,7 @@ Please submit there instead, or use --nodevelproject to force direct submission.
dst_package = args[3] dst_package = args[3]
else: else:
dst_package = src_package dst_package = src_package
src_project = self._process_project_name(src_project)
dst_project = self._process_project_name(dst_project) dst_project = self._process_project_name(dst_project)
else: else:
self.argparse_error("Incorrect number of arguments.") self.argparse_error("Incorrect number of arguments.")
@ -3020,9 +3019,9 @@ Please submit there instead, or use --nodevelproject to force direct submission.
if not args or len(args) < 3: if not args or len(args) < 3:
self.argparse_error("Incorrect number of arguments.") self.argparse_error("Incorrect number of arguments.")
src_project = self._process_project_name(self._expand_as_project_name(args[0])) src_project = self._process_project_name(args[0])
src_package = args[1] src_package = args[1]
dst_project = self._process_project_name(self._expand_as_project_name(args[2])) dst_project = self._process_project_name(args[2])
if len(args) > 3: if len(args) > 3:
dst_package = args[3] dst_package = args[3]
else: else:
@ -3551,8 +3550,8 @@ Please submit there instead, or use --nodevelproject to force direct submission.
usage: usage:
osc branch osc branch
osc branch SOURCEPROJECT SOURCEPACKAGE osc branch SOURCEPROJECT SOURCEPACKAGE
osc branch SOURCEPROJECT SOURCEPACKAGE TARGETPROJECT osc branch SOURCEPROJECT SOURCEPACKAGE TARGETPROJECT|.
osc branch SOURCEPROJECT SOURCEPACKAGE TARGETPROJECT TARGETPACKAGE osc branch SOURCEPROJECT SOURCEPACKAGE TARGETPROJECT|. TARGETPACKAGE
osc getpac SOURCEPACKAGE osc getpac SOURCEPACKAGE
osc bco ... osc bco ...
""" """
@ -3714,7 +3713,7 @@ Please submit there instead, or use --nodevelproject to force direct submission.
raise oscerr.WrongArgs('Wrong number of arguments') raise oscerr.WrongArgs('Wrong number of arguments')
apiurl = self.get_api_url() apiurl = self.get_api_url()
prj = self._process_project_name(self._expand_as_project_name(args[0])) prj = self._process_project_name(args[0])
msg = '' msg = ''
if opts.message: if opts.message:
@ -4504,7 +4503,7 @@ Please submit there instead, or use --nodevelproject to force direct submission.
if len(args) == 1 and is_project_dir(Path.cwd()): if len(args) == 1 and is_project_dir(Path.cwd()):
project = store_read_project(Path.cwd()) project = store_read_project(Path.cwd())
project_dir = Path.cwd() project_dir = str(Path.cwd())
package = args[0] package = args[0]
if opts.deleted and package: if opts.deleted and package:
@ -7889,7 +7888,7 @@ Please submit there instead, or use --nodevelproject to force direct submission.
if opts.project: if opts.project:
project_dir = opts.project project_dir = opts.project
else: else:
project_dir = Path.cwd() project_dir = str(Path.cwd())
if not is_project_dir(project_dir): if not is_project_dir(project_dir):
raise oscerr.WrongArgs("'%s' is no project working copy" % project_dir) raise oscerr.WrongArgs("'%s' is no project working copy" % project_dir)
@ -8373,7 +8372,7 @@ Please submit there instead, or use --nodevelproject to force direct submission.
apiurl = self.get_api_url() apiurl = self.get_api_url()
project = None project = None
project_dir = Path.cwd() project_dir = str(Path.cwd())
if is_project_dir(project_dir): if is_project_dir(project_dir):
project = store_read_project(project_dir) project = store_read_project(project_dir)
elif is_package_dir(project_dir): elif is_package_dir(project_dir):