From 557304745f2e51ef08dbc4cbe98d21fd68037173 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrian=20Schr=C3=B6ter?= Date: Tue, 13 Feb 2024 14:09:06 +0100 Subject: [PATCH] Allow to use "tar" service also standalone. One use case is to maintain a package in git repo and just create tar balls at buildtime. Example (in this case with submodule) can be found here https://github.com/adrianschroeter/git-example-4 --- TarSCM/scm/tar.py | 40 +++++++++++++++++++++++++++------------- 1 file changed, 27 insertions(+), 13 deletions(-) diff --git a/TarSCM/scm/tar.py b/TarSCM/scm/tar.py index 9515abd7..fbbb33b2 100644 --- a/TarSCM/scm/tar.py +++ b/TarSCM/scm/tar.py @@ -15,25 +15,35 @@ def fetch_upstream(self): if files: # or we refactor and loop about all on future self.args.obsinfo = files[0] - if self.args.obsinfo is None: - raise SystemExit("ERROR: no .obsinfo file found in directory: " + + version = None + if self.args.obsinfo: + self.basename = self.clone_dir = self.read_from_obsinfo( + self.args.obsinfo, "name" + ) + version = self.read_from_obsinfo(self.args.obsinfo, "version") + + if self.args.filename: + self.basename = self.clone_dir = self.args.filename + + if self.args.version: + version = self.args.version + + if not self.basename or not self.clone_dir: + raise SystemExit("ERROR: no .obsinfo file found in directory\n" + " and no manual configuration: " "'%s'" % os.getcwd()) - self.basename = self.clone_dir = self.read_from_obsinfo( - self.args.obsinfo, - "name" - ) if "/" in self.clone_dir: sys.exit("name in obsinfo contains '/'.") - version = self.read_from_obsinfo(self.args.obsinfo, "version") - if "/" in version or '..' in version: - sys.exit("verion in obsinfo contains '/' or '..'.") + sys.exit("version in obsinfo contains '/' or '..'.") - if version != '': + if version != '' and version != '_none_': self.clone_dir += "-" + version - if not os.path.exists(self.clone_dir): + if not os.path.exists(self.clone_dir) \ + and self.basename != self.clone_dir: self._final_rename_needed = True # not need in case of local osc build try: @@ -51,10 +61,14 @@ def update_cache(self): def detect_version(self, args): """Read former stored version.""" - return self.read_from_obsinfo(self.args.obsinfo, "version") + if self.args.obsinfo: + return self.read_from_obsinfo(self.args.obsinfo, "version") def get_timestamp(self): - return int(self.read_from_obsinfo(self.args.obsinfo, "mtime")) + if self.args.obsinfo: + return int(self.read_from_obsinfo(self.args.obsinfo, "mtime")) + if self.args.filename: + return int(os.path.getmtime(self.args.filename)) def read_from_obsinfo(self, filename, key): infofile = open(filename, "r")