Commit 8bc425826c088600e83815dc44fa636b248dd0df
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 | 2 | # ========================================================================== |
| 3 | 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 | 7 | # This program is free software: you can redistribute it and/or modify |
| 8 | 8 | # it under the terms of the GNU General Public License as published by |
| ... | ... | @@ -116,21 +116,30 @@ class csiactcopy(ctools.cscript): |
| 116 | 116 | self._log_value(gammalib.VERBOSE, 'Already exists', is_file) |
| 117 | 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 | 120 | if is_file and clobber == False: |
| 121 | 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 | 126 | elif is_file and os.path.samefile(destination, source): |
| 125 | 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 | 132 | dest_dir = os.path.dirname(destination) |
| 130 | 133 | if not os.path.isdir(dest_dir): |
| 131 | 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 | 143 | shutil.copy2(source, destination) |
| 135 | 144 | |
| 136 | 145 | # Get filesize |
| ... | ... | @@ -138,7 +147,7 @@ class csiactcopy(ctools.cscript): |
| 138 | 147 | |
| 139 | 148 | # Logging |
| 140 | 149 | self._log_value(gammalib.VERBOSE, 'Copying', 'Done!') |
| 141 | - | |
| 150 | + | |
| 142 | 151 | # Return |
| 143 | 152 | return filesize |
| 144 | 153 | ... | ... |