extras-buildsys/utils ExtrasPushUtils.py,1.4,1.5

Michael Schwendt (mschwendt) fedora-extras-commits at redhat.com
Mon Aug 21 20:42:57 UTC 2006


Author: mschwendt

Update of /cvs/fedora/extras-buildsys/utils
In directory cvs-int.fedora.redhat.com:/tmp/cvs-serv12526

Modified Files:
	ExtrasPushUtils.py 
Log Message:
- move more shared functions into module + revise them slightly


Index: ExtrasPushUtils.py
===================================================================
RCS file: /cvs/fedora/extras-buildsys/utils/ExtrasPushUtils.py,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- ExtrasPushUtils.py	20 Aug 2006 22:51:49 -0000	1.4
+++ ExtrasPushUtils.py	21 Aug 2006 20:42:55 -0000	1.5
@@ -17,6 +17,7 @@
 
 import errno
 import os, sys
+import shutil
 
 signersgid = 100581  # signers group
 
@@ -64,3 +65,45 @@
             print 'WARNING: Could not get group name for gid %d' % signersgid
         print 'ERROR: Change into the %s group before running this!  Use "newgrp %s".' % (grpname, grpname)
         sys.exit(errno.EPERM)
+
+
+def install_copy(src,dest,overwrite=False):
+    """shutil.copy2 a file, but by default don't overwrite destination"""
+    if not overwrite and os.path.exists(dest):
+        print('WARNING: %s already exists, ignoring new one' % dest)
+        return
+    debugprint('Copying %s to %s' % (src,dest))
+    if not DEBUG:
+        shutil.copy2(src,dest)
+
+
+def install_move(src,dest,overwrite=False):
+    """shutil.move a file, but by default don't overwrite destination"""
+    if not overwrite and os.path.exists(dest):
+        print('WARNING: %s already exists, ignoring new one' % dest)
+        return
+    debugprint('Moving %s to %s' % (src,dest))
+    if not DEBUG:
+        shutil.move(src,dest)
+
+
+def install_link(src,dest):
+    """os.link a file, but don't overwrite destination"""
+    if os.path.exists(dest):
+        print('WARNING: %s already exists, ignoring new one' % dest)
+        return
+    debugprint('Linking %s <- %s' % (src,dest))
+    if not DEBUG:
+        os.link(src,dest)
+
+
+def install_link_or_copy(src,dest):
+    """try install_link, if it fails, use install_copy"""
+    linked = False
+    try:
+        install_link(src,dest)
+        linked = True
+    except OSError, e:
+        print 'WARNING: Linking failed (%s), trying to copy...' % e
+    if not linked:
+        install_copy(src,dest)




More information about the fedora-extras-commits mailing list