1
0
mirror of https://github.com/openSUSE/osc.git synced 2024-12-25 17:36:13 +01:00

Deprecate store_read_apiurl()

This commit is contained in:
Daniel Mach 2022-10-14 14:25:54 +02:00
parent 5493d632cc
commit fd52727394
2 changed files with 29 additions and 44 deletions

View File

@ -27,6 +27,7 @@ from . import build as osc_build
from . import cmdln
from . import conf
from . import oscerr
from . import store as osc_store
from .core import *
from .grabber import OscFileGrabber
from .meter import create_text_meter
@ -219,7 +220,7 @@ class Osc(cmdln.Cmdln):
sys.exit(1)
if (is_package_dir(localdir) or is_project_dir(localdir)) and not self.options.apiurl:
return store_read_apiurl(Path.cwd())
return osc_store.Store(Path.cwd()).apiurl
else:
return conf.config['apiurl']
@ -994,14 +995,14 @@ class Osc(cmdln.Cmdln):
attributepath = []
if cmd in ['prj', 'prjconf']:
if len(args) < 1:
apiurl = store_read_apiurl(Path.cwd())
apiurl = osc_store.Store(Path.cwd()).apiurl
project = store_read_project(Path.cwd())
else:
project = self._process_project_name(args[0])
elif cmd == 'pkg':
if len(args) < 2:
apiurl = store_read_apiurl(Path.cwd())
apiurl = osc_store.Store(Path.cwd()).apiurl
project = store_read_project(Path.cwd())
if len(args) < 1:
package = store_read_package(Path.cwd())
@ -4903,7 +4904,7 @@ Please submit there instead, or use --nodevelproject to force direct submission.
for pac in no_pacs:
if os.path.exists(pac):
# fail with an appropriate error message
store_read_apiurl(pac, defaulturl=False)
Package(pac)
path = os.path.normpath(os.path.join(pac, os.pardir))
if is_project_dir(path):
pac_name = os.path.basename(os.path.normpath(os.path.abspath(pac)))
@ -4914,7 +4915,7 @@ Please submit there instead, or use --nodevelproject to force direct submission.
files.setdefault(path, {})[pac_name] = []
else:
# fail with an appropriate error message
store_read_apiurl(pac, defaulturl=False)
Package(pac)
for prj_path, packages in prj_paths.items():
prj = Project(prj_path)
if not msg and not opts.no_message:
@ -4939,7 +4940,7 @@ Please submit there instead, or use --nodevelproject to force direct submission.
store_unlink_file(p.absdir, '_commit_msg')
elif no_pacs:
# fail with an appropriate error message
store_read_apiurl(no_pacs[0], defaulturl=False)
Package.from_paths(no_pacs)
else:
for p in pacs:
if not p.todo:
@ -6990,10 +6991,10 @@ Please submit there instead, or use --nodevelproject to force direct submission.
if is_package_dir(Path.cwd()):
project = store_read_project(Path.cwd())
package = store_read_package(Path.cwd())
apiurl = store_read_apiurl(Path.cwd())
apiurl = osc_store.Store(Path.cwd()).apiurl
elif is_project_dir(Path.cwd()):
project = store_read_project(Path.cwd())
apiurl = store_read_apiurl(Path.cwd())
apiurl = osc_store.Store(Path.cwd()).apiurl
else:
raise oscerr.WrongArgs('Too few arguments.')
else:
@ -7058,7 +7059,7 @@ Please submit there instead, or use --nodevelproject to force direct submission.
if is_package_dir(Path.cwd()):
project = store_read_project(Path.cwd())
package = store_read_package(Path.cwd())
apiurl = store_read_apiurl(Path.cwd())
apiurl = osc_store.Store(Path.cwd()).apiurl
repo = args[0]
arch = args[1]
sysrq = args[2]
@ -7113,10 +7114,10 @@ Please submit there instead, or use --nodevelproject to force direct submission.
if is_package_dir(Path.cwd()):
project = store_read_project(Path.cwd())
package = store_read_package(Path.cwd())
apiurl = store_read_apiurl(Path.cwd())
apiurl = osc_store.Store(Path.cwd()).apiurl
elif is_project_dir(Path.cwd()):
project = store_read_project(Path.cwd())
apiurl = store_read_apiurl(Path.cwd())
apiurl = osc_store.Store(Path.cwd()).apiurl
else:
raise oscerr.WrongArgs('Too few arguments.')
else:
@ -7931,7 +7932,7 @@ Please submit there instead, or use --nodevelproject to force direct submission.
createPackageDir(os.path.join(project.dir, pac), project)
else:
if not os.path.exists(os.path.join(project_dir, pac)):
apiurl = store_read_apiurl(project_dir)
apiurl = osc_store.Store(project_dir).apiurl
user = conf.get_apiurl_usr(apiurl)
data = meta_exists(metatype='pkg',
path_args=(quote_plus(project), quote_plus(pac)),
@ -8956,7 +8957,7 @@ Please submit there instead, or use --nodevelproject to force direct submission.
return 1
if args and is_package_dir(args[0]):
apiurl = store_read_apiurl(args[0])
apiurl = osc_store.Store(args[0]).apiurl
else:
apiurl = self.get_api_url()

View File

@ -708,11 +708,12 @@ class Project:
"""
self.dir = dir
self.absdir = os.path.abspath(dir)
self.store = Store(dir)
self.progress_obj = progress_obj
self.name = store_read_project(self.dir)
self.scm_url = store_read_scmurl(self.dir)
self.apiurl = store_read_apiurl(self.dir, defaulturl=not wc_check)
self.apiurl = self.store.apiurl
dirty_files = []
if wc_check:
@ -1147,9 +1148,10 @@ class Project:
else:
pac_path = os.path.join(self.dir, pac)
store = Store(pac_path)
project = store_read_project(pac_path)
package = store_read_package(pac_path)
apiurl = store_read_apiurl(pac_path, defaulturl=False)
apiurl = store.apiurl
if not meta_exists(metatype='pkg',
path_args=(quote_plus(project), quote_plus(package)),
template_args=None, create_new=False, apiurl=apiurl):
@ -1209,6 +1211,7 @@ class Package:
self.dir = workingdir
self.absdir = os.path.abspath(self.dir)
self.store = Store(self.dir)
self.storedir = os.path.join(self.absdir, store)
self.progress_obj = progress_obj
self.size_limit = size_limit
@ -1220,7 +1223,7 @@ class Package:
self.prjname = store_read_project(self.dir)
self.name = store_read_package(self.dir)
self.apiurl = store_read_apiurl(self.dir, defaulturl=not wc_check)
self.apiurl = self.store.apiurl
self.update_datastructs()
dirty_files = []
@ -6757,33 +6760,13 @@ def store_read_scmurl(dir):
def store_read_apiurl(dir, defaulturl=True):
global store
fname = os.path.join(dir, store, '_apiurl')
try:
with open(fname) as f:
url = f.readlines()[0].strip()
# this is needed to get a proper apiurl
# (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:
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(project, package, ['_apiurl'], msg)
apiurl = conf.config['apiurl']
return apiurl
import warnings
warnings.warn(
"osc.core.store_read_apiurl() is deprecated. "
"You should be using high-level classes such as Store, Project or Package instead.",
DeprecationWarning
)
return Store(dir).apiurl
def store_read_last_buildroot(dir):
@ -7491,8 +7474,9 @@ def addFiles(filenames, prj_obj=None, force=False):
prj_dir, pac_dir = getPrjPacPaths(filename)
if not is_package_dir(filename) and os.path.isdir(filename) and is_project_dir(prj_dir) \
and conf.config['do_package_tracking']:
store = Store(prj_dir)
prj_name = store_read_project(prj_dir)
prj_apiurl = store_read_apiurl(prj_dir, defaulturl=False)
prj_apiurl = store.apiurl
Package.init_package(prj_apiurl, prj_name, pac_dir, filename)
elif is_package_dir(filename) and conf.config['do_package_tracking']:
print('osc: warning: \'%s\' is already under version control' % filename)