def main(): # Collect input files infiles = set(args.infiles) for glob_expr in args.glob_exprs: infiles.update(glob.glob(glob_expr)) infiles = list(infiles) if not infiles: sys.stderr.write("You didn't provide any files to load. " \ "You should consider including some next time...\n") sys.exit(1) # Enter information in rawfiles table # create diagnostic plots and metrics. # Also fill-in raw_diagnostics and raw_diagnostic_plots tables for fn in infiles: try: if config.cfg.verbosity: print "Checking %s (%s)" % (fn, utils.give_utc_now()) # Check the file and parse the header params = utils.prep_file(fn) # Find where the file will be moved to. destdir = utils.get_archive_dir(fn, params=params) utils.print_info("%s will get archived to %s (%s)" % \ (fn, destdir, utils.give_utc_now()), 1) utils.print_info("Finished with %s - pre-check successful (%s)" % \ (fn, utils.give_utc_now()), 1) except errors.ToasterError, msg: sys.stderr.write("Pre-check of %s failed!\n%s\nSkipping...\n" % \ (fn, msg))
def load_template(fn, comments, is_master=False, existdb=None): # Connect to the database db = existdb or database.Database() db.connect() try: # Now load the template file into database notify.print_info("Working on %s (%s)" % (fn, utils.give_utc_now()), 1) # Check the template and parse the header params = datafile.prep_file(fn) # Move the file destdir = datafile.get_archive_dir(fn, params=params) newfn = datafile.archive_file(fn, destdir) # Register the template into the database template_id = populate_templates_table(db, newfn, params, comments=comments) mastertemp_id, tempfn = general.get_master_template(params['pulsar_id'], params['obssystem_id']) if mastertemp_id is None: # If this is the only template for this pulsar # make sure it will be set as the master is_master = True if is_master: notify.print_info("Setting %s as master template (%s)" % (newfn, utils.give_utc_now()), 1) general.set_as_master_template(template_id, db) notify.print_info("Finished with %s - template_id=%d (%s)" % (fn, template_id, utils.give_utc_now()), 1) finally: if not existdb: # Close DB connection db.close() return template_id