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:53 -0500, Paul Nasrat wrote:
> 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:

Without stupid save error (ie ignore first hunk)

Paul

_______________________________________________
Rpm-metadata mailing list
[email protected]
https://lists.dulug.duke.edu/mailman/listinfo/rpm-metadata
createrepo-relative.patch (text/x-patch, 2.4 KB)
Index: generate/genpkgmetadata.py
===================================================================
--- generate.orig/genpkgmetadata.py
+++ generate/genpkgmetadata.py
@@ -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,30 @@ def parseArgs(args):
 def main(args):
     cmds, directories = parseArgs(args)
     directory = directories[0]
+# Fix paths
+    directory = os.path.normpath(directory)
+    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.