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>
Tue, 7 Jan 2014 14:21:30 +0000 (16:21 +0200)
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 68f9b753d8ccb30d307716bb1a0db555b5a53c11..25c449cb69aa6e18fc3b9f79189494cfd3c44c55 100644 (file)
@@ -121,8 +121,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:
@@ -241,7 +241,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))
 
@@ -661,7 +661,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 75643fc4ee2878aa3fca3bafa03b294362382d00..47b352d407c1c0bfd8eef6ed51f1ac1ace177ae4 100755 (executable)
@@ -509,9 +509,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:
@@ -522,7 +521,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,
@@ -562,9 +561,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 a5d0a9a61381a3c12c20f82b76208e8a3879f849..e57ddcc4de890dad9f20b1d1e681def528d72a64 100755 (executable)
@@ -151,8 +151,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):
@@ -325,7 +324,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):
@@ -463,7 +462,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 16e1f52e7105f1d316554747bbe1bb84ed8df639..d86d654a93cde63c74a3309e50a7f34831ee049d 100755 (executable)
@@ -336,7 +336,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 3e04fcd896ea99f6126ac91d99947c23b87823f8..01d8b27798ab0e940278a45cdd6de22f4b86f738 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.name == 'gbp-test'