rpm.SpecFile: change specfile attribute to represent filename
authorMarkus Lehtonen <markus.lehtonen@linux.intel.com>
Fri, 4 Jan 2013 13:10:02 +0000 (15:10 +0200)
committerMarkus Lehtonen <markus.lehtonen@linux.intel.com>
Thu, 5 Jun 2014 11:20:06 +0000 (14:20 +0300)
There is specdir to get the (absolute) directory path.

Signed-off-by: Markus Lehtonen <markus.lehtonen@linux.intel.com>
gbp/rpm/__init__.py
gbp/scripts/buildpackage_rpm.py
gbp/scripts/import_srpm.py
gbp/scripts/pq_rpm.py
tests/test_rpm.py

index 1000302b2e892a44bb5a9ab784579f6bd5e51ae2..46cea28a95420a63889a6732af157825fa19f7d9 100644 (file)
@@ -127,8 +127,8 @@ class SpecFile(object):
     def __init__(self, specfile):
 
         # Load spec file into our special data structure
-        self.specfile = os.path.abspath(specfile)
-        self.specdir = os.path.dirname(self.specfile)
+        self.specfile = os.path.basename(specfile)
+        self.specdir = os.path.dirname(os.path.abspath(specfile))
         self._content = LinkedList()
         try:
             with open(specfile) as spec_file:
@@ -247,7 +247,7 @@ class SpecFile(object):
         """
         Write, possibly updated, spec to disk
         """
-        with open(self.specfile, 'w') as spec_file:
+        with open(os.path.join(self.specdir, self.specfile), 'w') as spec_file:
             for line in self._content:
                 spec_file.write(str(line))
 
@@ -663,7 +663,7 @@ class SpecFile(object):
         Return patches of the RPM as a gbp patchseries
         """
         series = PatchSeries()
-        patchdir = os.path.dirname(self.specfile)
+        patchdir = self.specdir
         for n, p in sorted(self.patches.iteritems()):
             if p['autoupdate'] and p['apply']:
                 fname = os.path.basename(p['filename'])
index 338350c99cd88d6764dbf3c1dcaf5894525ce803..3c6b7c1c3844e1a2ffec8adb8b8fb68bb951b7b9 100755 (executable)
@@ -517,9 +517,8 @@ def main(argv):
             pkgfiles = os.listdir(spec.specdir)
             for f in pkgfiles:
                 src = os.path.join(spec.specdir, f)
-                if f == os.path.basename(spec.specfile):
+                if f == spec.specfile:
                     dst = os.path.join(spec_dir, f)
-                    spec.specfile = os.path.abspath(dst)
                 else:
                     dst = os.path.join(source_dir, f)
                 try:
@@ -530,7 +529,7 @@ def main(argv):
                         shutil.copy2(src, dst)
                 except IOError, err:
                     raise GbpError, "Error exporting files: %s" % err
-            spec.specdir = spec_dir
+            spec.specdir = os.path.abspath(spec_dir)
 
             if options.orig_prefix != 'auto':
                 options.orig_prefix = options.orig_prefix % dict(spec.version,
@@ -570,9 +569,10 @@ def main(argv):
 
                 # Finally build the package:
                 if options.builder.startswith("rpmbuild"):
-                    builder_args.extend([spec.specfile])
+                    builder_args.append(os.path.join(spec.specdir,
+                                        spec.specfile))
                 else:
-                    builder_args.extend([os.path.basename(spec.specfile)])
+                    builder_args.append(spec.specfile)
                 RunAtCommand(options.builder, builder_args, shell=True,
                              extra_env={'GBP_BUILD_DIR': export_dir})(dir=export_dir)
                 if options.postbuild:
index 269101d92aa2c949baca29f67cc2e6c8ec8ac0f1..bbaa43288cb0f25560dfa2e32299fa0f52fea9dc 100755 (executable)
@@ -157,8 +157,7 @@ def import_spec_patches(repo, spec, dirs):
         repo.force_head('HEAD', hard=True)
         raise PatchImportError("Unable to update spec file, you need to edit"
                                "and commit it  manually")
-    repo.commit_all(msg=PATCH_AUTODELETE_COMMIT_MSG %
-                        os.path.basename(spec.specfile))
+    repo.commit_all(msg=PATCH_AUTODELETE_COMMIT_MSG % spec.specfile)
 
 
 def force_to_branch_head(repo, branch):
@@ -331,7 +330,7 @@ def main(argv):
         for num, src in spec.sources.iteritems():
             if num != spec.orig_src_num:
                 files.append(src['filename'])
-        files.append(spec.specfile)
+        files.append(os.path.join(spec.specdir, spec.specfile))
         for fname in files:
             fpath = os.path.join(dirs['src'], fname)
             if os.path.exists(fpath):
@@ -469,7 +468,7 @@ def main(argv):
                 if options.patch_import:
                     spec = parse_spec(os.path.join(repo.path,
                                             options.packaging_dir,
-                                            os.path.basename(spec.specfile)))
+                                            spec.specfile))
                     import_spec_patches(repo, spec, dirs)
                     commit = options.packaging_branch
 
index ba34054c70173326b647a925ca5c63b15a6883ae..8a938fa3896ee187ad0bbfdb3f4824795a8fa372 100755 (executable)
@@ -337,7 +337,7 @@ def import_spec_patches(repo, branch, options):
 
     repo.set_branch(branch)
 
-    return os.path.basename(spec.specfile)
+    return spec.specfile
 
 
 def rebase_pq(repo, branch, options):
index 29ecb56ca6405aa2db41f263568eb80a07b7d8a4..68886e8602777d784fca9f36899db1f0c3b6dfce 100644 (file)
@@ -88,7 +88,7 @@ class TestSpecFile(object):
         spec = SpecFileTester(spec_filepath)
 
         # Test basic properties
-        assert spec.specfile == spec_filepath
+        assert spec.specfile == os.path.basename(spec_filepath)
         assert spec.specdir == os.path.dirname(spec_filepath)
         assert spec.specpath == spec_filepath