12 from optparse
import OptionParser
16 def __init__(self, path, referenceDate, versionsToKeep, noOutput):
20 if referenceDate !=
None:
45 for currentDir, directories, files
in os.walk(path):
65 rootFiles.append(file)
74 for file
in rootFiles:
75 fullFilePath = os.path.join(currentDir, file)
78 self.OutdatedFiles.setdefault(currentDir, []).
append(file)
81 upToDateFiles.append(file)
84 if self.OutdatedFiles.has_key(currentDir):
91 subsystemRunNumberGroups = {}
93 for file
in rootFiles:
96 fileNameSplit = re.split(
'_', file)
98 key = fileNameSplit[2] +
'_' + fileNameSplit[3][:10]
99 subsystemRunNumberGroups.setdefault(key, []).
append(file)
102 for key
in subsystemRunNumberGroups.iterkeys():
110 subsystemRunNumberGroups[key].
sort()
121 self.
VersionedFilesSize += os.path.getsize(os.path.join(currentDir, fileToBeDeleted)) / 1024.
131 directories = sorted(self.OutdatedFiles.keys() + self.VersionedFiles.keys())
132 for directory
in directories:
133 print(
'DIR: ' +
'"' + directory +
'"')
136 if self.OutdatedFiles.has_key(directory):
137 print(
'\t' +
'Outdated files to be deleted:')
143 if self.VersionedFiles.has_key(directory):
144 print(
'\t' +
'Versioned files:')
146 print(
'\t\t' +
'ToBe Deleted:')
148 print(
'\t\t\t' + file)
149 print(
'\t\t' +
'ToBe Kept:')
151 print(
'\t\t\t' + file)
156 print(
'The space freed by outdated files is: ' +
'"' +
159 print(
'The space freed by versioned files is: ' +
'"' +
162 print(
'The total space freed is: ' +
'"' +
169 usage = sys.argv[0] +
' [options] PATH_TO_ANALYSE'
170 parser = OptionParser(usage=usage)
172 parser.add_option(
'-d',
175 dest=
'ReferenceDate',
176 metavar=
'YYYY-MM-DD',
177 help=
'All the ROOT files older than [YYYY-MM-DD] will be marked for deletion. If the '
178 'user does not specify this option no date filter will be applied at all')
179 parser.add_option(
'-v',
180 '--versions_to_keep',
182 dest=
'VersionsToKeep',
183 metavar=
'VERSIONS_TO_KEEP',
184 help=
'Specify number of versions to keep. If a ROOT file has many versions only the most '
185 'recent [VERSIONS_TO_KEEP] of them will be kept. The others will be marked for '
186 'deletion. It the user does not specify this option no version filter will be applied '
188 parser.add_option(
'-q',
193 help=
'If this flag is specified no output is printed to STDOUT.')
194 parser.add_option(
'-f',
200 help=
'Print all ROOT files selected for deletion to a [LOG_FILE]. If [LOG_FILE] already '
201 'exists it will be deleted.')
204 (options, args) = parser.parse_args()
218 print(
'Wrong number of positional arguments. You have to specify only PATH_TO_ANALYSE!\n')
228 dateSplit = self.ReferenceDate.split(
'-')
230 self.
ReferenceDate = datetime.date(int(dateSplit[0]), int(dateSplit[1]), int(dateSplit[2]))
232 print(
'"' + self.
ReferenceDate +
'" - Wrong date format (please use YYYY-MM-DD) or nonexistent date!')
237 print(
'Number of versions to keep should be a positive integer. '
245 if __name__ ==
'__main__':
249 rootFilesFilter =
RootFilesFilter(args.PathToAnalyse, args.ReferenceDate, args.VersionsToKeep, args.Quiet)
250 rootFilesFilter.find_files()
251 rootFilesFilter.show_selected_files()
252 rootFilesFilter.show_some_statistics()
def _select_root_files_only
std::string print(const Track &, edm::Verbosity=edm::Concise)
Track print utility.
def show_selected_files
sorting does not do what you want does not mean that sorting is not working.
def _select_outdated_files
def _select_versioned_files