def reduce_rawfile(args, leftover_args=[], existdb=None): if args.rawfile is not None: notify.print_info("Loading rawfile %s" % args.rawfile, 1) args.rawfile_id = load_rawfile.load_rawfile(args.rawfile, existdb) elif args.rawfile_id is None: # Neither a rawfile, nor a rawfile_id was provided raise errors.BadInputError("Either a rawfile, or a rawfile_id " "_must_ be provided!") if args.parfile is not None: notify.print_info("Loading parfile %s" % args.parfile, 1) args.parfile_id = load_parfile.load_parfile(args.parfile, existdb=existdb) if args.template is not None: notify.print_info("Loading template %s" % args.template, 1) args.template_id = load_template.load_template(args.template, existdb=existdb) rawfile_info = rawfiles_general.get_rawfile_info(args.rawfile_id, existdb=existdb) if args.use_parfile: if args.parfile_id is None: args.parfile_id = parfiles_general.get_master_parfile( rawfile_info['pulsar_id'])[0] if args.parfile_id is None: raise errors.NoMasterError("A master parfile is required " "in the database if no parfile is " "provided on the command line.") else: args.parfile_id = None if args.template_id is None: args.template_id = templates_general.get_master_template( rawfile_info['pulsar_id'], rawfile_info['obssystem_id'], existdb=existdb)[0] if args.template_id is None: raise errors.NoMasterError("A master template is required " "in the database if no template is " "provided on the command line.") notify.print_info("Using the following IDs:\n" " rawfile_id: %s\n" " parfile_id: %s\n" " template_id: %s" % (args.rawfile_id, args.parfile_id, args.template_id), 1) # Load manipulator manip = manipulators.load_manipulator(args.manip_name) manip.parse_args(leftover_args) # Run pipeline core pipeline_core(manip, args.rawfile_id, args.parfile_id, args.template_id, existdb)
def load_parfile(fn, is_master=False, existdb=None): # Connect to the database db = existdb or database.Database() db.connect() try: # Now load the parfile file into database notify.print_info("Working on %s (%s)" % (fn, utils.give_utc_now()), 1) # Check the parfile and parse it params = general.prep_parfile(fn) # Archive the parfile destdir = os.path.join(config.cfg.data_archive_location, 'parfiles', params['name']) newfn = datafile.archive_file(fn, destdir) # Register the parfile into the database parfile_id = populate_parfiles_table(db, newfn, params) masterpar_id, parfn = general.get_master_parfile(params['pulsar_id']) if masterpar_id is None: # If this is the only parfile 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 parfile (%s)" % (newfn, utils.give_utc_now()), 1) general.set_as_master_parfile(parfile_id, db) notify.print_info("Finished with %s - parfile_id=%d (%s)" % (fn, parfile_id, utils.give_utc_now()), 1) finally: if not existdb: # Close DB connection db.close() return parfile_id