CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Public Attributes | Private Member Functions
dqmdata_cleaner.CommandLineArgsCollector Class Reference

Public Member Functions

def __init__
 

Public Attributes

 ArgumentsOK
 
 PathToAnalyse
 
 Quiet
 
 ReferenceDate
 
 VersionsToKeep
 

Private Member Functions

def _check_arguments
 

Detailed Description

Definition at line 166 of file dqmdata_cleaner.py.

Constructor & Destructor Documentation

def dqmdata_cleaner.CommandLineArgsCollector.__init__ (   self)

Definition at line 168 of file dqmdata_cleaner.py.

169  def __init__(self):
170  usage = sys.argv[0] + ' [options] PATH_TO_ANALYSE'
171  parser = OptionParser(usage=usage)
172 
173  parser.add_option('-d',
174  '--date',
175  type='string',
176  dest='ReferenceDate',
177  metavar='YYYY-MM-DD',
178  help='All the ROOT files older than [YYYY-MM-DD] will be marked for deletion. If the '
179  'user does not specify this option no date filter will be applied at all')
180  parser.add_option('-v',
181  '--versions_to_keep',
182  type='int',
183  dest='VersionsToKeep',
184  metavar='VERSIONS_TO_KEEP',
185  help='Specify number of versions to keep. If a ROOT file has many versions only the most '
186  'recent [VERSIONS_TO_KEEP] of them will be kept. The others will be marked for '
187  'deletion. It the user does not specify this option no version filter will be applied '
188  'at all')
189  parser.add_option('-q',
190  '--quiet',
191  dest='Quiet',
192  action='store_true',
193  default=False,
194  help='If this flag is specified no output is printed to STDOUT.')
195  parser.add_option('-f',
196  '--file',
197  type='string',
198  dest='LogFile',
199  metavar='LOG_FILE',
200  default=None,
201  help='Print all ROOT files selected for deletion to a [LOG_FILE]. If [LOG_FILE] already '
202  'exists it will be deleted.')
203 
204  # parse the user specified arguments
205  (options, args) = parser.parse_args()
206  self.ReferenceDate = options.ReferenceDate
207  self.VersionsToKeep = options.VersionsToKeep
208  self.Quiet = options.Quiet
210  self.ArgumentsOK = self._check_arguments(parser, args)
211 

Member Function Documentation

def dqmdata_cleaner.CommandLineArgsCollector._check_arguments (   self,
  parser,
  args 
)
private

Definition at line 212 of file dqmdata_cleaner.py.

213  def _check_arguments(self, parser, args):
214 
215  # check self.PathToAnalyse
216  if len(args) == 1:
217  self.PathToAnalyse = args[0]
218  else:
219  print('Wrong number of positional arguments. You have to specify only PATH_TO_ANALYSE!\n')
220  parser.print_help()
221  return False
222 
223  if not os.path.exists(self.PathToAnalyse): # check whether self.PathToAnalyse exists
224  print('The path "' + self.PathToAnalyse + '" does not exists or in not readable!')
225  return False
226 
227  # check self.ReferenceDate - it should be a valid date string
228  if self.ReferenceDate != None:
229  dateSplit = self.ReferenceDate.split('-')
230  try: # convert self.ReferenceDate to datetime.date object
231  self.ReferenceDate = datetime.date(int(dateSplit[0]), int(dateSplit[1]), int(dateSplit[2]))
232  except:
233  print('"' + self.ReferenceDate + '" - Wrong date format (please use YYYY-MM-DD) or nonexistent date!')
234  return False
235 
236  # check self.VersionsToKeep
237  if (self.VersionsToKeep != None) and (self.VersionsToKeep < 1):
238  print('Number of versions to keep should be a positive integer. '
239  'The value you specified is "' + str(self.VersionsToKeep) + '"')
240  return False
241 
242  # if this is reached the argumnts are OK
243  return True
244 
std::string print(const Track &, edm::Verbosity=edm::Concise)
Track print utility.
Definition: print.cc:10

Member Data Documentation

dqmdata_cleaner.CommandLineArgsCollector.ArgumentsOK

Definition at line 209 of file dqmdata_cleaner.py.

dqmdata_cleaner.CommandLineArgsCollector.PathToAnalyse

Definition at line 216 of file dqmdata_cleaner.py.

dqmdata_cleaner.CommandLineArgsCollector.Quiet

Definition at line 207 of file dqmdata_cleaner.py.

dqmdata_cleaner.CommandLineArgsCollector.ReferenceDate

Definition at line 205 of file dqmdata_cleaner.py.

dqmdata_cleaner.CommandLineArgsCollector.VersionsToKeep

Definition at line 206 of file dqmdata_cleaner.py.