Re: [PATCH] Fix handling for relative absolute paths

Paul Nasrat <[email protected]>
Newsgroups gmane.linux.rpm.metadata
Organization Red Hat, Inc.
Message-ID <[email protected]>
On Thu, 2005-11-17 at 12:43 -0500, Paul Nasrat wrote:
> On Thu, 2005-11-17 at 12:36 -0500, Paul Nasrat wrote:
> > Ugly but works, expect a clean up of the option parsing/setting sometime
> > after fc5t1 is out.
> > 
> > This fixes cachedir/groupfile handling with basedir and using paths not
> > relative to cwd without basedir.
> 
> Without stupid typo/indent error.

With testing:

[pauln@enki tmp]$ python
~/work/createrepo/devel/createrepo-0.4.3/genpkgmetadata.py -g
Fedora/base/comps.xml ~/tmp/myrepo/
2/2 - Fedora/RPMS/setup-2.5.47-1.1.noarch.rpm
Saving Primary metadata
Saving file lists metadata
Saving other metadata
[pauln@enki tmp]$ python
~/work/createrepo/devel/createrepo-0.4.3/genpkgmetadata.py -g
Fedora/base/comps.xml myrepo/
2/2 - Fedora/RPMS/setup-2.5.47-1.1.noarch.rpm
Saving Primary metadata
Saving file lists metadata
Saving other metadata
[pauln@enki tmp]$ vi myrepo/repodata/repomd.xml
[pauln@enki tmp]$ cd rpm
[pauln@enki rpm]$ python
~/work/createrepo/devel/createrepo-0.4.3/genpkgmetadata.py -g
Fedora/base/comps.xml ../myrepo/
2/2 - Fedora/RPMS/setup-2.5.47-1.1.noarch.rpm
Saving Primary metadata
Saving file lists metadata
Saving other metadata
[pauln@enki rpm]$


Paul

_______________________________________________
Rpm-metadata mailing list
[email protected]
https://lists.dulug.duke.edu/mailman/listinfo/rpm-metadata
createrepo-relative.patch (text/x-patch, 2.5 KB)
Index: generate/genpkgmetadata.py
===================================================================
--- generate.orig/genpkgmetadata.py
+++ generate/genpkgmetadata.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python -t
+#!/usr/bin/python -t:
 # primary functions and glue for generating the repository metadata
 #
 
@@ -397,11 +397,7 @@ def parseArgs(args):
                     errorprint(_('Error: Only one groupfile allowed.'))
                     usage()
                 else:
-                    if os.path.exists(a):
-                        cmds['groupfile'] = a
-                    else:
-                        errorprint(_('Error: groupfile %s cannot be found.' % a))
-                        usage()
+                    cmds['groupfile'] = a
             elif arg in ['-x', '--exclude']:
                 cmds['excludes'].append(a)
             elif arg in ['-p', '--pretty']:
@@ -412,12 +408,7 @@ def parseArgs(args):
                 errorprint(_('This option is deprecated'))
             elif arg in ['-c', '--cachedir']:
                 cmds['cache'] = True
-                if not os.path.isabs(a):
-                   a = os.path.join(os.getcwd(), a)
                 cmds['cachedir'] = a
-                if not checkAndMakeDir(a):
-                    errorprint(_('Error: cannot open/write to cache dir %s' % a))
-                    usage()
             elif arg == '--basedir':
                 cmds['basedir'] = a
                     
@@ -431,6 +422,29 @@ def parseArgs(args):
 def main(args):
     cmds, directories = parseArgs(args)
     directory = directories[0]
+# Fix paths
+    if os.path.isabs(directory):
+        cmds['basedir'] = directory
+        directory = '.'
+    else:
+        cmds['basedir'] = os.path.realpath(os.path.join(cmds['basedir'], directory))
+        directory = '.'
+    if cmds['groupfile']:
+        a = cmds['groupfile']
+        if not os.path.isabs(cmds['groupfile']):
+            a = os.path.join(cmds['basedir'], cmds['groupfile'])
+        if not os.path.exists(a):
+            errorprint(_('Error: groupfile %s cannot be found.' % a))
+            usage()
+        cmds['groupfile'] = a
+    if cmds['cachedir']:
+        a = cmds ['cachedir']
+        if not os.path.isabs(a):
+            a = os.path.join(cmds['basedir'] ,a)
+        if not checkAndMakeDir(a):
+            errorprint(_('Error: cannot open/write to cache dir %s' % a))
+            usage()
+        cmds['cachdir'] = a
 
     #setup some defaults
     cmds['primaryfile'] = 'primary.xml.gz'
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.