X-Git-Url: https://git.decadent.org.uk/gitweb/?a=blobdiff_plain;f=utils.py;h=ae796855e959922ee40607e775c839decdbd6fd2;hb=8777e78d6f55062f170c1b2802c6c1f518695c98;hp=95a0882633dfb690d0f070cfa36102d5f91afcd6;hpb=9747704c3468d10a66a0bd20a489ee800815dacf;p=dak.git diff --git a/utils.py b/utils.py index 95a08826..ae796855 100644 --- a/utils.py +++ b/utils.py @@ -1,6 +1,6 @@ # Utility functions # Copyright (C) 2000 James Troup -# $Id: utils.py,v 1.23 2001-05-24 18:56:23 troup Exp $ +# $Id: utils.py,v 1.24 2001-05-31 02:19:30 troup Exp $ # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -42,7 +42,8 @@ no_files_exc = "No Files: field in .dsc file."; cant_open_exc = "Can't read file."; unknown_hostname_exc = "Unknown hostname"; cant_overwrite_exc = "Permission denied; can't overwrite existent file." - +file_exists_exc = "Destination file exists"; + ###################################################################################### def open_file(filename, mode): @@ -287,7 +288,7 @@ def poolify (source, component): ###################################################################################### -def move (src, dest): +def move (src, dest, overwrite = 0): if os.path.exists(dest) and os.path.isdir(dest): dest_dir = dest; else: @@ -299,14 +300,18 @@ def move (src, dest): #print "Moving %s to %s..." % (src, dest); if os.path.exists(dest) and os.path.isdir(dest): dest = dest + '/' + os.path.basename(src); - # Check for overwrite permission on existent files - if os.path.exists(dest) and not os.access(dest, os.W_OK): - raise cant_overwrite_exc + # Don't overwrite unless forced to + if os.path.exists(dest): + if not overwrite: + raise file_exists_exc; + else: + if not os.access(dest, os.W_OK): + raise cant_overwrite_exc shutil.copy2(src, dest); os.chmod(dest, 0664); os.unlink(src); -def copy (src, dest): +def copy (src, dest, overwrite = 0): if os.path.exists(dest) and os.path.isdir(dest): dest_dir = dest; else: @@ -318,8 +323,13 @@ def copy (src, dest): #print "Copying %s to %s..." % (src, dest); if os.path.exists(dest) and os.path.isdir(dest): dest = dest + '/' + os.path.basename(src); - if os.path.exists(dest) and not os.access(dest, os.W_OK): - raise cant_overwrite_exc + # Don't overwrite unless forced to + if os.path.exists(dest): + if not overwrite: + raise file_exists_exc + else: + if not os.access(dest, os.W_OK): + raise cant_overwrite_exc shutil.copy2(src, dest); os.chmod(dest, 0664);