def main(args): # Connect to the database db = database.Database() db.connect() try: if args.from_file is not None: # Re-create parser, so we can read arguments from file file_parser = utils.DefaultArguments() add_arguments(file_parser) if args.pulsar_name is not None: raise errors.BadInputError("When adding pulsars from " "a file, a pulsar name should " "_not_ be provided on the command " "line. (The value %s was given on " "the command line)." % args.pulsar_name) if args.from_file == '-': psrlist = sys.stdin else: if not os.path.exists(args.from_file): raise errors.FileError("The pulsar list (%s) does " "not appear to exist." % args.from_file) psrlist = open(args.from_file, 'r') numfails = 0 numadded = 0 for line in psrlist: # Strip comments line = line.partition('#')[0].strip() if not line: # Skip empty line continue try: customargs = copy.deepcopy(args) arglist = shlex.split(line.strip()) file_parser.parse_args(arglist, namespace=customargs) pulsar_id = add_pulsar(customargs.pulsar_name, customargs.aliases, db) print "Successfully inserted new pulsar. " \ "Returned pulsar_id: %d" % pulsar_id numadded += 1 except errors.ToasterError: numfails += 1 traceback.print_exc() if args.from_file != '-': psrlist.close() if numadded: notify.print_success("\n\n===================================\n" "%d pulsars successfully added\n" "===================================\n" % numadded) if numfails: raise errors.ToasterError( "\n\n===================================\n" "The adding of %d pulsars failed!\n" "Please review error output.\n" "===================================\n" % numfails) else: pulsar_id = add_pulsar(args.pulsar_name, args.aliases, db) print "Successfully inserted new pulsar. " \ "Returned pulsar_id: %d" % pulsar_id finally: # Close DB connection db.close()
def main(): db = database.Database() db.connect() try: if args.from_file is not None: if args.from_file == '-': tellist = sys.stdin else: if not os.path.exists(args.from_file): raise errors.FileError("The telescope list (%s) does " \ "not appear to exist." % args.from_file) tellist = open(args.from_file, 'r') numfails = 0 numadded = 0 for line in tellist: # Strip comments line = line.partition('#')[0].strip() if not line: # Skip empty line continue try: customargs = copy.deepcopy(args) arglist = shlex.split(line.strip()) parser.parse_args(arglist, namespace=customargs) if customargs.name is None or customargs.itrf_x is None or \ customargs.itrf_y is None or customargs.itrf_z is None or \ customargs.abbrev is None or customargs.code is None: raise errors.BadInputError("Telescopes " \ "must have a name, IRTF coordinates (X,Y,Z), " \ "an abbreviation, and a site code. " \ "One of these is missing.") telescope_id = add_telescope(db, customargs.name, \ customargs.itrf_x, customargs.itrf_y, \ customargs.itrf_x, customargs.abbrev, \ customargs.code, customargs.aliases) print "Successfully inserted new telescope. " \ "Returned telescope_id: %d" % telescope_id numadded += 1 except errors.ToasterError: numfails += 1 traceback.print_exc() if args.from_file != '-': tellist.close() if numadded: notify.print_success("\n\n===================================\n" \ "%d telescopes successfully added\n" \ "===================================\n" % numadded) if numfails: raise errors.ToasterError(\ "\n\n===================================\n" \ "The adding of %d telescopes failed!\n" \ "Please review error output.\n" \ "===================================\n" % numfails) else: if args.name is None or args.itrf_x is None or \ args.itrf_y is None or args.itrf_z is None or \ args.abbrev is None or args.code is None: raise errors.BadInputError("Telescopes " \ "must have a name, IRTF coordinates (X,Y,Z), " \ "an abbreviation, and a site code. " \ "One of these is missing.") telescope_id = add_telescope(db, args.name, \ args.itrf_x, args.itrf_y, \ args.itrf_x, args.abbrev, \ args.code, args.aliases) print "Successfully inserted new telescope. " \ "Returned telescope_id: %d" % telescope_id finally: db.close()
def main(args): # Allow reading input from stdin if ((args.template is None) or (args.template == '-')) and (args.from_file is None): warnings.warn("No input file or --from-file argument given " "will read from stdin.", errors.ToasterWarning) args.template = None # In case it was set to '-' args.from_file = '-' # Connect to the database db = database.Database() db.connect() try: if args.from_file is not None: # Re-create parser, so we can read arguments from file parser = utils.DefaultArguments() add_arguments(parser) if args.template is not None: raise errors.BadInputError("When loading templates from a file, " "a template value should _not_ be " "provided on the command line. (The " "value %s was given on the command " "line)." % args.template) if args.from_file == '-': templatelist = sys.stdin else: if not os.path.exists(args.from_file): raise errors.FileError("The template list (%s) does " "not appear to exist." % args.from_file) templatelist = open(args.from_file, 'r') numfails = 0 numloaded = 0 for line in templatelist: # Strip comments line = line.partition('#')[0].strip() if not line: # Skip empty line continue try: customargs = copy.deepcopy(args) arglist = shlex.split(line.strip()) parser.parse_args(arglist, namespace=customargs) fn = customargs.template template_id = load_template(fn, customargs.comments, customargs.is_master, db) print "%s has been loaded to the DB. template_id: %d" % \ (fn, template_id) numloaded += 1 except errors.ToasterError: numfails += 1 traceback.print_exc() if args.from_file != '-': templatelist.close() if numloaded: notify.print_success("\n\n===================================\n" "%d templates successfully loaded\n" "===================================\n" % numloaded) if numfails: raise errors.ToasterError( "\n\n===================================\n" "The loading of %d templates failed!\n" "Please review error output.\n" "===================================\n" % numfails) else: fn = args.template template_id = load_template(fn, args.comments, args.is_master, db) print "%s has been loaded to the DB. template_id: %d" % \ (fn, template_id) finally: # Close DB connection db.close()
def main(args): # Connect to the database db = database.Database() db.connect() try: if args.from_file is not None: # Re-create parser, so we can read arguments from file parser = utils.DefaultArguments() add_arguments(parser) if args.from_file == '-': obssyslist = sys.stdin else: if not os.path.exists(args.from_file): raise errors.FileError("The obssystem list (%s) does " \ "not appear to exist." % args.from_file) obssyslist = open(args.from_file, 'r') numfails = 0 numadded = 0 for line in obssyslist: # Strip comments line = line.partition('#')[0].strip() if not line: # Skip empty line continue try: customargs = copy.deepcopy(args) arglist = shlex.split(line.strip()) parser.parse_args(arglist, namespace=customargs) if customargs.telescope is None or customargs.backend is None or \ customargs.frontend is None or customargs.band is None or \ customargs.clock is None: raise errors.BadInputError("Observing systems " \ "must have a telescope, backend, frontend, " \ "band descriptor, and clock file! At least " \ "one of these is missing.") tinfo = cache.get_telescope_info(customargs.telescope) telescope_id = tinfo['telescope_id'] if customargs.name is None: customargs.name = "%s_%s_%s" % \ (tinfo['telescope_abbrev'].upper(), \ customargs.backend.upper(), \ customargs.frontend.upper()) obssystem_id = add_obssystem(db, customargs.name, telescope_id, \ customargs.frontend, customargs.backend, \ customargs.band, customargs.clock) print "Successfully inserted new observing system. " \ "Returned obssystem_id: %d" % obssystem_id numadded += 1 except errors.ToasterError: numfails += 1 traceback.print_exc() if args.from_file != '-': obssyslist.close() if numadded: notify.print_success("\n\n===================================\n" \ "%d obssystems successfully added\n" \ "===================================\n" % numadded) if numfails: raise errors.ToasterError(\ "\n\n===================================\n" \ "The adding of %d obssystems failed!\n" \ "Please review error output.\n" \ "===================================\n" % numfails) else: if args.telescope is None or args.backend is None or \ args.frontend is None or args.band is None or \ args.clock is None: raise errors.BadInputError("Observing systems " \ "must have a telescope, backend, frontend, " \ "band descriptor, and clock file! At least " \ "one of these is missing.") tinfo = cache.get_telescope_info(args.telescope) telescope_id = tinfo['telescope_id'] if args.name is None: args.name = "%s_%s_%s" % \ (tinfo['telescope_abbrev'].upper(), \ args.backend.upper(), \ args.frontend.upper()) obssystem_id = add_obssystem(db, args.name, telescope_id, \ args.frontend, args.backend, args.band, args.clock) print "Successfully inserted new observing system. " \ "Returned obssystem_id: %d" % obssystem_id finally: db.close()
def main(args): if (args.rawfile_id is None) and (args.from_file is None): warnings.warn("No input file or --from-file argument given " \ "will read from stdin.", \ errors.ToasterWarning) args.rawfile = None # In case it was set to '-' args.from_file = '-' # Connect to the database db = database.Database() db.connect() print args.from_file try: if args.from_file is not None: # Re-create parser, so we can read arguments from file parser = utils.DefaultArguments() add_arguments(parser) if args.rawfile_id is not None: raise errors.BadInputError("When diagnosing rawfiles " \ "using a file, a rawfile should _not_ " \ "be provided on the command line. (The " \ "value %s was given on the command line)." % \ args.rawfile_id) if args.from_file == '-': rawlist = sys.stdin else: if not os.path.exists(args.from_file): raise errors.FileError("The rawfile list (%s) does " \ "not appear to exist." % args.from_file) rawlist = open(args.from_file, 'r') numfails = 0 numdiagnosed = 0 for line in rawlist: # Strip comments line = line.partition('#')[0].strip() if not line: # Skip empty line continue try: customargs = copy.deepcopy(args) arglist = shlex.split(line.strip()) parser.parse_args(arglist, namespace=customargs) diag = diagnose_rawfile(customargs.rawfile_id, \ customargs.diagnostic, customargs.value, \ existdb=db) if customargs.insert: insert_rawfile_diagnostics(customargs.rawfile_id, \ [diag], existdb=db) else: print str(diag) except errors.ToasterError: numfails += 1 traceback.print_exc() if args.from_file != '-': rawlist.close() if numdiagnosed: notify.print_success("\n\n===================================\n" \ "%d rawfiles successfully diagnosed\n" \ "===================================\n" % numadded) if numfails: raise errors.ToasterError(\ "\n\n===================================\n" \ "The diagnosis of %d rawfiles failed!\n" \ "Please review error output.\n" \ "===================================\n" % numfails) else: if not args.rawfile_id: raise ValueError("A rawfile ID number must be provided!") diag = diagnose_rawfile(args.rawfile_id, \ args.diagnostic, args.value, \ existdb=db) if args.insert: insert_rawfile_diagnostics(args.rawfile_id, \ [diag], existdb=db) else: print str(diag) finally: db.close()
def main(args): # Allow arguments to be read from stdin if ((args.rawfile is None) or (args.rawfile == '-')) and \ (args.from_file is None): warnings.warn("No input file or --from-file argument given " "will read from stdin.", errors.ToasterWarning) args.rawfile = None # In case it was set to '-' args.from_file = '-' # Connect to the database db = database.Database() db.connect() try: if args.from_file is not None: # Re-create parser, so we can read arguments from file file_parser = utils.DefaultArguments() add_arguments(file_parser) if args.rawfile is not None: raise errors.BadInputError("When loading rawfiles from " "a file, a rawfile value should " "_not_ be provided on the command " "line. (The value %s was given " "on the command line)." % args.rawfile) if args.from_file == '-': rawlist = sys.stdin else: if not os.path.exists(args.from_file): raise errors.FileError("The rawfile list (%s) does " "not appear to exist." % args.from_file) rawlist = open(args.from_file, 'r') numfails = 0 numloaded = 0 for line in rawlist: # Strip comments line = line.partition('#')[0].strip() if not line: # Skip empty line continue try: # parsing arguments is overkill at the moment # since 'load_rawfile.py' doesn't take any # arguments, but this makes the code more future-proof customargs = copy.deepcopy(args) arglist = shlex.split(line.strip()) file_parser.parse_args(arglist, namespace=customargs) fn = customargs.rawfile rawfile_id = load_rawfile(fn, db) print "%s has been loaded to the DB. rawfile_id: %d" % \ (fn, rawfile_id) numloaded += 1 except errors.ToasterError: numfails += 1 traceback.print_exc() if args.from_file != '-': rawlist.close() if numloaded: notify.print_success( "\n\n===================================\n" "%d rawfiles successfully loaded\n" "===================================\n" % numloaded) if numfails: raise errors.ToasterError( "\n\n===================================\n" "The loading of %d rawfiles failed!\n" "Please review error output.\n" "===================================\n" % numfails) else: fn = args.rawfile rawfile_id = load_rawfile(fn, db) print "%s has been loaded to the DB. rawfile_id: %d" % \ (fn, rawfile_id) finally: # Close DB connection db.close()