Commit 8bc425826c088600e83815dc44fa636b248dd0df

Authored by Jürgen Knödlseder
1 parent 89679dc5

Correct csiactcopy.py script so that it passes make distcheck

Showing 1 changed file with 17 additions and 8 deletions
cscripts/csiactcopy.py
@@ -2,7 +2,7 @@ @@ -2,7 +2,7 @@
2 # ========================================================================== 2 # ==========================================================================
3 # Copies IACT data from remote machine 3 # Copies IACT data from remote machine
4 # 4 #
5 -# Copyright (C) 2016 Michael Mayer 5 +# Copyright (C) 2016-2017 Michael Mayer
6 # 6 #
7 # This program is free software: you can redistribute it and/or modify 7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by 8 # it under the terms of the GNU General Public License as published by
@@ -116,21 +116,30 @@ class csiactcopy(ctools.cscript): @@ -116,21 +116,30 @@ class csiactcopy(ctools.cscript):
116 self._log_value(gammalib.VERBOSE, 'Already exists', is_file) 116 self._log_value(gammalib.VERBOSE, 'Already exists', is_file)
117 self._log_value(gammalib.VERBOSE, 'Overwrite', clobber) 117 self._log_value(gammalib.VERBOSE, 'Overwrite', clobber)
118 118
119 - # check if file could be skipped because clobber=no 119 + # Check if file could be skipped because clobber=no
120 if is_file and clobber == False: 120 if is_file and clobber == False:
121 self._log_value(gammalib.VERBOSE, 'Copying', 'Skip (clobber=no)') 121 self._log_value(gammalib.VERBOSE, 'Copying', 'Skip (clobber=no)')
122 122
123 - # check if file could be skipped because it is the same file 123 + # ... check if file could be skipped because it is the same file as
  124 + # inferred from the file path and name (the file is in fact not
  125 + # checked) ...
124 elif is_file and os.path.samefile(destination, source): 126 elif is_file and os.path.samefile(destination, source):
125 self._log_value(gammalib.VERBOSE, 'Copying', 'Skip (same file)') 127 self._log_value(gammalib.VERBOSE, 'Copying', 'Skip (same file)')
126 128
127 - else:  
128 - # Create directory if not existent 129 + # ... otherwise copy file
  130 + else:
  131 + # Create directory if it does not exist
129 dest_dir = os.path.dirname(destination) 132 dest_dir = os.path.dirname(destination)
130 if not os.path.isdir(dest_dir): 133 if not os.path.isdir(dest_dir):
131 os.makedirs(dest_dir) 134 os.makedirs(dest_dir)
132 -  
133 - # Copy file (if source not identical to destination) 135 +
  136 + # If destination file exists then delete it. Make sure that file
  137 + # is writable for that
  138 + if os.path.isfile(destination):
  139 + os.chmod(destination, 420)
  140 + os.remove(destination)
  141 +
  142 + # Copy file
134 shutil.copy2(source, destination) 143 shutil.copy2(source, destination)
135 144
136 # Get filesize 145 # Get filesize
@@ -138,7 +147,7 @@ class csiactcopy(ctools.cscript): @@ -138,7 +147,7 @@ class csiactcopy(ctools.cscript):
138 147
139 # Logging 148 # Logging
140 self._log_value(gammalib.VERBOSE, 'Copying', 'Done!') 149 self._log_value(gammalib.VERBOSE, 'Copying', 'Done!')
141 - 150 +
142 # Return 151 # Return
143 return filesize 152 return filesize
144 153