diff --git a/Documents/script_notes.txt b/Documents/script_notes.txt deleted file mode 100644 index d2e42511..00000000 --- a/Documents/script_notes.txt +++ /dev/null @@ -1,47 +0,0 @@ -scripts notes from brian: - -addFromConfig.py: key -addVerboseProvenance.py: never worked -clearProcessingFlag.py: key -configFromDB.py: used to work, super-convenient -coveragePlot.py: works, but has some bugs. Doesn't catch most recent files reliably or somtehing. But see note on htmlCoverage -CreateDB.py: key -dataToIncoming.py: concept, never actually used. supposed to be one script + config file, but we wound up using separate scripts for everything -dbOnlyFiles.py: supposed to show files in db but not on disk, but not in use -DBRunner.py: really useful. Give Db, process, date range, and runs them into the current directory. "dumb runner" -deleteAllDBFiles.py: does what it sounds, sorta useful -deleteAllDBProducts.py: ditto -deleteDBFile.py: usable, deletes single file from db (also from disk?), relatively common -deleteFromDBifNotOnDisk.py: says on tin, probably not ued -flushProcessQueue.py: key -histogramCodes.py: may or may not still work, read logs to find out what codes take a long time to run -hopeCoverageHTML.py: delete -hope_query.py: delete -htmlCoverage.py: either this or coveragePlot works, not both. -link_missing_ql_mag_l2_mag.py: QL "required,", L2 "optional". We don't support "either or but prefer this one", so this links them together and the wrapper handles the actual priority -magephem_dataToIncoming.py: what it says on tin -magephem_def_dataToIncoming.py: what it says on tin -magephem-pre-CoverageHTML.py: probably works -makeLatestSymlinks.py: highest file version, makes symlinks into file dir -missingFilesByProduct.py: attempt to reprocess files that are missing, 90% solution, not used much, but did work -missingFiles.py: prints out what's missing, based on noncontiguous date ranges, maybe works, maybe not -possibleProblemDates.py: a database scrub/validation routine, useful but sharp edges -printInfo.py: key, table of info about files or products or processes -printProcessQueue.py: does that, kinda useful -processQueueHTML.py: probably broken, same thing, but HTML, merge these? -ProcessQueue.py: the main thing -purgeFileFromDB.py: different than delete how? This might be the one to use. purge deletes it and everything that depends on it. delete might not, which might leave loose ends. -QCEmailer_conf.txt: quality control loop stuff -README.txt: whatever -reprocessByAll.py: should work, probably doesn't -reprocessByCode.py: "" -reprocessByDate.py: This code works and is likely the one that should be used most of the time for reprocessing files. (BAL email 2018/7/11: "used as the default for do everything on a date range, maybe tha all one should go away") -reprocessByInstrument.py: "" -reprocessByProduct.py: does work, used all the time, beaten it to a pulp to make it work but haven't done that on the others (BAL email 2018/7/11: "I use this a lot for individual processing") -updateCode.py: new version of code, rerun based on that, better done through config files (although can't be done that way) and then run reprocessByCode -updateProducts.py: probably broken -updateSHAsum.py: meant to update database with new shasum if file has changed and want to keep it there -weeklyReport.py: unused, probably broken, delete -writeDBhtml.py: "" -writeProcessConf.py: probably not used -writeProductsConf.py: probably not used diff --git a/docs/scripts.rst b/docs/scripts.rst index 877be1fc..b3d94ba2 100644 --- a/docs/scripts.rst +++ b/docs/scripts.rst @@ -1,5 +1,17 @@ +******************** dbprocessing Scripts -==================== +******************** + +.. contents:: + :depth: 1 + :local: + +Maintained scripts +================== +These scripts are of general use in dbprocessing and either are fully +tested and verified to work, or are moving to that status. They are +maintained as part of dbprocessing. They are in the ``scripts`` +directory. addFromConfig.py ---------------- @@ -16,16 +28,6 @@ format and capability. .. option:: -v, --verify Verify the config file then stop -addVerboseProvenance.py ------------------------ -.. program:: addVerboseProvenance - -Go into the database and get the verbose provenance for a file -then add that to the global attrs for the file. -Either putout to the same file or a different file - -.. warning:: This code has not been fully tested or used. - clearProcessingFlag.py ---------------------- .. program:: clearProcessingFlag @@ -50,12 +52,15 @@ Build a config file from an existing database. .. warning:: This is untested and not fully useful yet. +.. _scripts_coveragePlot: + coveragePlot.py --------------- .. program:: coveragePlot -Creates a coverage plot based on config file input. This script is useful for -determining which files may be missing from a processing chain. +Creates a coverage plot based on config file input. This script is +useful for determining which files may be missing from a processing +chain. See note on :ref:`scripts_htmlCoverage`. .. option:: configfile The config file to read. @@ -82,12 +87,8 @@ This is the first step in the setup of a new processing chain. The name of the database to create -dataToIncoming.py ------------------ -Concept, never actually used. supposed to be one script + config file, but we wound up using separate scripts for everything - -dbOnlyFiles.py: ---------------- +dbOnlyFiles.py +-------------- .. program:: dbOnlyFiles.py Show files in database but not on disk. Additionally, this can remove files from the db that are only in the db. @@ -164,22 +165,16 @@ triggering such processing. (0: interface; 1: quality; 2: revision). Mutually exclusive with -u, -v. (Default: run all but do not increment version.) -deleteAllDBFiles.py: --------------------- +deleteAllDBFiles.py +------------------- .. program:: deleteAllDBFiles Deletes all file entries in the database. .. option:: -m , --mission Selected mission database -deleteAllDBProducts.py: ------------------------ -.. program:: deleteAllDBProducts - -Doesn't work, maybe should? - -deleteFromDBifNotOnDisk.py: ---------------------------- +deleteFromDBifNotOnDisk.py +-------------------------- .. program:: deleteFromDBifNotOnDisk Finds all files that are in the DB but not found on the DB @@ -188,33 +183,23 @@ Finds all files that are in the DB but not found on the DB .. option:: --fix Remove the files from the DB (make a backup first) .. option:: --echo Echo sql queries for debugging -flushProcessQueue.py: ---------------------- +flushProcessQueue.py +-------------------- .. program:: flushProcessQueue Clears the ProcessQueue of a database. .. option:: Database The name of the database to wipe the ProcesQueue of. -histogramCodes.py: ------------------- +histogramCodes.py +----------------- may or may not still work, read logs to find out what codes take a long time to run -hopeCoverageHTML.py: --------------------- -delete - -hope_query.py: --------------- -delete +.. _scripts_htmlCoverage: -htmlCoverage.py: ----------------- -either this or coveragePlot works, not both. - -link_missing_ql_mag_l2_mag.py: ------------------------------- -QL "required,", L2 "optional". We don't support "either or but prefer this one", so this links them together and the wrapper handles the actual priority +htmlCoverage.py +--------------- +either this or :ref:`scripts_coveragePlot` works, not both. .. _scripts_linkUningested: @@ -239,20 +224,8 @@ on next run). lead to odd results. Multiple products can be specified by specifying more than once. -magephem_dataToIncoming.py: ---------------------------- -What it says on tin. Delete? - -magephem_def_dataToIncoming.py: -------------------------------- -What it says on tin. Delete? - -magephem-pre-CoverageHTML.py: ------------------------------ -Probably works. Delete? - -makeLatestSymlinks.py: ----------------------- +makeLatestSymlinks.py +--------------------- .. program:: makeLatestSymlinks In a given directory, make symlinks to all the newest versions of files into another directory @@ -286,20 +259,20 @@ Will display all possible changes and prompt for confirmation. Process possible changes without asking for confirmation. -missingFilesByProduct.py: -------------------------- +missingFilesByProduct.py +------------------------ Attempt to reprocess files that are missing, 90% solution, not used much, but did work -missingFiles.py: ----------------- +missingFiles.py +--------------- .. program:: missingFiles Prints out what's missing, based on noncontiguous date ranges .. warning:: Maybe works, maybe not -possibleProblemDates.py: ------------------------- +possibleProblemDates.py +----------------------- .. program:: possibleProblemDates A database scrub/validation routine. @@ -308,24 +281,24 @@ A database scrub/validation routine. .. option:: --fix Fix the issues (make a backup first) .. option:: --echo Echo sql queries for debugging -.. warning:: Worth looking into and cleaning up a bit +.. warning:: Worth looking into and cleaning up a bit; may have sharp edges. -printInfo.py: -------------- +printInfo.py +------------ .. program:: printInfo Prints a table of info about files or products or processes. -.. option:: Database The name of the database to print table of -.. option:: Field Either Product or Mission (more to come) +.. option:: database The name of the database to print table of +.. option:: field Either Product or Mission (more to come) -printProcessQueue.py: ---------------------- +printProcessQueue.py +-------------------- .. program:: printProcessQueue Prints the process queue. -.. option:: Database The name of the database to print the queue of +.. option:: database The name of the database to print the queue of .. option:: -o, --output The name of the file to output to(if blank, print to stdout) .. option:: --html Output in HTML @@ -335,17 +308,20 @@ ProcessQueue.py The main thing -purgeFileFromDB.py: -------------------- +purgeFileFromDB.py +------------------ .. program:: purgeFileFromDB -Deletes individual files from the database. +Deletes individual files from the database. Pending note on this +"different than delete how? This might be the one to use. purge +deletes it and everything that depends on it. delete might not, which +might leave loose ends." Not clear which "delete" this refers to. .. option:: -m , --mission Selected mission database .. option:: -r, --recursive Recursive removal -reprocessByAll.py: ------------------- +reprocessByAll.py +----------------- .. program:: reprocessByAll Goes through the database and adds all the files that are a certain level to the processqueue so that the next ProcessQueue -p will run them @@ -357,8 +333,8 @@ Goes through the database and adds all the files that are a certain level to the .. warning:: Should work, probably doesn't -reprocessByCode.py: -------------------- +reprocessByCode.py +------------------ .. program:: reprocessByCode Goes through the database and adds all the files that went into the code to the processqueue so that the next ProcessQueue -p will run them @@ -371,11 +347,17 @@ Goes through the database and adds all the files that went into the code to the .. warning:: Should work, probably doesn't -reprocessByDate.py: -------------------- +reprocessByDate.py +------------------ .. program:: reprocessByDate -Goes through the database and adds all the files that are in a date range to the processqueue so that the next ProcessQueue -p will run them +Goes through the database and adds all the files that are in a date +range to the processqueue so that the next ProcessQueue -p will run +them. + +This code works and is likely the one that should be used most of the +time for reprocessing files. (Used as the default for do everything on +a date range, maybe reprocessByAll should go away. .. option:: -s , --startDate Date to start reprocessing (e.g. 2012-10-02) .. option:: -e , --endDate Date to end reprocessing (e.g. 2012-10-25) @@ -383,8 +365,8 @@ Goes through the database and adds all the files that are in a date range to the .. option:: --echo Echo sql queries for debugging .. option:: --force Force the reprocessing. Speicify which version number to increment (1,2,3) -reprocessByInstrument.py: -------------------------- +reprocessByInstrument.py +------------------------ .. program:: reprocessByInstrument Goes through the database and adds all the files that are a certain instrument and level to the processqueue so that the next ProcessQueue -p will run them @@ -396,11 +378,15 @@ Goes through the database and adds all the files that are a certain instrument a .. option:: --echo Echo sql queries for debugging .. option:: --force Force the reprocessing. Specify which version number to increment (1,2,3) -reprocessByProduct.py: ----------------------- -.. program:: reprocessByProduct. +reprocessByProduct.py +--------------------- +.. program:: reprocessByProduct + +Goes through the database and adds all the files that are a certain product and put then to the processqueue so that the next ProcessQueue -p will run them. -Goes through the database and adds all the files that are a certain product and put then to the processqueue so that the next ProcessQueue -p will run them +This reprocessing script works and is used all the time; it's been +tested much more heavily than the others and is used all the time for +individual processing. .. option:: -s , --startDate Date to start reprocessing (e.g. 2012-10-02) .. option:: -e , --endDate Date to end reprocessing (e.g. 2012-10-25) @@ -408,16 +394,8 @@ Goes through the database and adds all the files that are a certain product and .. option:: --echo Echo sql queries for debugging .. option:: --force Force the reprocessing. Specify which version number to increment (1,2,3) -updateCode.py: --------------- -New version of code, rerun based on that, better done through config files (although can't be done that way) and then run reprocessByCode - -updateProducts.py: ------------------- -probably broken - -updateSHAsum.py: ----------------- +updateSHAsum.py +--------------- .. program:: updateSHAsum Goes into the database and update the shasum entry for a file that is changed after ingestion. @@ -439,18 +417,71 @@ has been created with the older algorithm. Selected mission database -weeklyReport.py: ----------------- -unused, probably broken, delete -writeDBhtml.py: +Examples +======== +These scripts are meant as reference for specific tasks that might be +required for a particular mission. They may not be fully tested or may +be mission-specific. They are not generally maintained; some are +candidates for eventually transferring to maintained scripts. They are +in the directory ``examples/scripts``. + +addVerboseProvenance.py +----------------------- +.. program:: addVerboseProvenance + +Go into the database and get the verbose provenance for a file +then add that to the global attrs for the CDF file. +Either put out to the same file or a different file + +.. warning:: This code has not been fully tested or used; never worked. + +dataToIncoming.py +----------------- +Concept, never actually used. supposed to be one script + config file +to handle all incoming data for RBSP-ECT, but we wound up using +separate scripts for everything + +hopeCoverageHTML.py +------------------- +delete + +hope_query.py +------------- +delete + +link_missing_ql_mag_l2_mag.py +----------------------------- +RBSP-ECT had some inputs available initially in a quicklook format and +then later in a definitive level 2 format. The database treated QL as +"required,", L2 "optional". We don't support "either or but prefer +this one", so this links them together and the wrapper handles the +actual priority + +magephem-pre-CoverageHTML.py +---------------------------- +Probably works. Delete? + +updateCode.py +------------- +New version of code, rerun based on that, better done through config files (although can't be done that way) and then run reprocessByCode + +updateProducts.py +----------------- +probably broken + +weeklyReport.py --------------- unused, probably broken, delete -writeProcessConf.py: --------------------- +writeDBhtml.py +-------------- +unused, probably broken, delete + +writeProcessConf.py +------------------- probably not used -writeProductsConf.py: ---------------------- +writeProductsConf.py +-------------------- probably not used diff --git a/examples/README.txt b/examples/README.txt new file mode 100644 index 00000000..cd455d3c --- /dev/null +++ b/examples/README.txt @@ -0,0 +1,12 @@ +This directory contains examples of how to set up dbprocessing for a +project, including configuration and scripts that are specific to +missions. Some examples may be out-of-date for current dbprocessing. + +This directory contains miscellaneous bits for sharing between developers. +It is included in the source tarball but not in binary distributions. + +scripts: + Scripts used to interface between dbprocessing and other parts of + a mission's processing, or to perform specific tasks. As these are + made more general and/or fully tested, they may be moved to the + main scripts directory. diff --git a/scripts/addVerboseProvenance.py b/examples/scripts/addVerboseProvenance.py similarity index 100% rename from scripts/addVerboseProvenance.py rename to examples/scripts/addVerboseProvenance.py diff --git a/scripts/dataToIncoming.py b/examples/scripts/dataToIncoming.py similarity index 100% rename from scripts/dataToIncoming.py rename to examples/scripts/dataToIncoming.py diff --git a/scripts/hopeCoverageHTML.py b/examples/scripts/hopeCoverageHTML.py similarity index 100% rename from scripts/hopeCoverageHTML.py rename to examples/scripts/hopeCoverageHTML.py diff --git a/scripts/hope_query.py b/examples/scripts/hope_query.py similarity index 100% rename from scripts/hope_query.py rename to examples/scripts/hope_query.py diff --git a/scripts/link_missing_ql_mag_l2_mag.py b/examples/scripts/link_missing_ql_mag_l2_mag.py similarity index 100% rename from scripts/link_missing_ql_mag_l2_mag.py rename to examples/scripts/link_missing_ql_mag_l2_mag.py diff --git a/scripts/magephem-pre-CoverageHTML.py b/examples/scripts/magephem-pre-CoverageHTML.py similarity index 100% rename from scripts/magephem-pre-CoverageHTML.py rename to examples/scripts/magephem-pre-CoverageHTML.py diff --git a/scripts/updateCode.py b/examples/scripts/updateCode.py similarity index 100% rename from scripts/updateCode.py rename to examples/scripts/updateCode.py diff --git a/scripts/updateProducts.py b/examples/scripts/updateProducts.py similarity index 100% rename from scripts/updateProducts.py rename to examples/scripts/updateProducts.py diff --git a/scripts/weeklyReport.py b/examples/scripts/weeklyReport.py similarity index 100% rename from scripts/weeklyReport.py rename to examples/scripts/weeklyReport.py diff --git a/scripts/writeDBhtml.py b/examples/scripts/writeDBhtml.py similarity index 100% rename from scripts/writeDBhtml.py rename to examples/scripts/writeDBhtml.py diff --git a/scripts/writeProcessConf.py b/examples/scripts/writeProcessConf.py similarity index 100% rename from scripts/writeProcessConf.py rename to examples/scripts/writeProcessConf.py diff --git a/scripts/writeProductsConf.py b/examples/scripts/writeProductsConf.py similarity index 100% rename from scripts/writeProductsConf.py rename to examples/scripts/writeProductsConf.py diff --git a/scripts/CreateDB.py b/scripts/CreateDB.py index 2c052b6e..9a5617f4 100755 --- a/scripts/CreateDB.py +++ b/scripts/CreateDB.py @@ -10,8 +10,8 @@ """ from __future__ import division # may not be needed but start with it +import argparse import os -from optparse import OptionParser from sqlalchemy import schema, types from sqlalchemy.engine import create_engine @@ -66,16 +66,15 @@ def createDB(self): if __name__ == "__main__": - usage = "usage: %prog [options] filename" - parser = OptionParser(usage=usage) - parser.add_option("-d", "--dialect", dest="dialect", default='sqlite', - help="sqlalchemy dialect (sqlite or postgresql)") + parser = argparse.ArgumentParser() + parser.add_argument("-d", "--dialect", dest="dialect", default='sqlite', + help="sqlalchemy dialect (sqlite or postgresql)") + parser.add_argument('dbname', action='store', type=str, + help='Name of database (or sqlite file) to create.') - (options, args) = parser.parse_args() - if len(args) != 1: - parser.error("incorrect number of arguments") + options = parser.parse_args() - filename = args[0] + filename = options.dbname if options.dialect == 'sqlite': filename = os.path.abspath(filename) diff --git a/scripts/CreateDBsabrs.py b/scripts/CreateDBsabrs.py index abaa7140..8d6135dd 100644 --- a/scripts/CreateDBsabrs.py +++ b/scripts/CreateDBsabrs.py @@ -11,7 +11,6 @@ from __future__ import division # may not be needed but start with it import os -from optparse import OptionParser import sqlalchemy from sqlalchemy import schema, types diff --git a/scripts/Graph.py b/scripts/Graph.py deleted file mode 100644 index 9c8d104e..00000000 --- a/scripts/Graph.py +++ /dev/null @@ -1,65 +0,0 @@ -class Graph: - def __init__(self,name=""): - self.name = name - self.list_neighbor = {} - self.list_node = {} - - def __str__(self): - nodes = self.nodes() - for n in nodes: - result = "\n" + "{0}, neighbors: {1}".format(n, self.neighbors(n)) - return result - - def add_node(self,node): - self.list_node[node] = True - - def add_edge(self,node,nodebis): - try : - self.list_neighbor[node].append(nodebis) - except : - self.list_neighbor[node] = [] - self.list_neighbor[node].append(nodebis) - #try : (can be added for undirected edges) - # self.list_neighbor[nodebis].append(node) - #except : - # self.list_neighbor[nodebis] = [] - # self.list_neighbor[nodebis].append(node) - - def neighbors(self,node): - try : - return self.list_neighbor[node] - except : - return [] - - def contains(self,node): - nodes = self.nodes() - for n in nodes: - if n == node: - return True - else: - return False - - - def nodes(self): - return self.list_node.keys() - - def getNode(self, name): - nodes = self.nodes() - for n in nodes: - if n == name: - return n - else: - return None - - def delete_edge(self,node,nodebis): - self.list_neighbor[node].remove(nodebis) - self.list_neighbor[nodebis].remove(node) - - def delete_node(self,node): - del self.list_node[node] - try : - for nodebis in self.list_neighbor[node] : - self.list_neighbor[nodebis].remove(node) - del self.list_neighbor[node] - except : - return "error" diff --git a/scripts/ProcessQueue.py b/scripts/ProcessQueue.py index b221551c..dca40684 100755 --- a/scripts/ProcessQueue.py +++ b/scripts/ProcessQueue.py @@ -1,11 +1,10 @@ #!/usr/bin/env python from __future__ import print_function +import argparse import datetime import os import operator -from optparse import OptionParser -import pdb import traceback import subprocess @@ -29,43 +28,37 @@ -s -> skip run timebase -o -> only run listed processes """ - parser = OptionParser(usage=usage) - parser.add_option("-i", "", dest="i", action="store_true", - help="ingest mode", default=False) - parser.add_option("-p", "", dest="p", action="store_true", - help="process mode", default=False) - parser.add_option("-s", "", dest="s", action="store_true", - help="Skip run timebase processes", default=False) - parser.add_option("-o", "--only", dest="o", type="string", - help='Run only listed processes (either id or name)', default = None) - parser.add_option("-m", "--mission", dest="mission", - help="selected mission database", default=None) - parser.add_option("-d", "--dryrun", dest="dryrun", action="store_true", - help="only do a dryrun processing or ingesting", default=False) - parser.add_option("-r", "--report", dest="report", action="store_true", - help="Make the html report", default=False) - parser.add_option("-l", "--log-level", dest="loglevel", - help="Set the logging level", default="debug") - parser.add_option("-n", "--num-proc", dest="numproc", type='int', - help="Number of processes to run in parallel", default=2) - parser.add_option("", "--echo", dest="echo", action="store_true", - help="Start sqlalchemy with echo in place for debugging", default=False) - parser.add_option("", "--glb", dest="glob", type="string", - help='Glob to use when reading files from incoming: default "*"', default="*") - - - (options, args) = parser.parse_args() - if len(args) != 0: - parser.error("incorrect number of arguments") - - if options.i and options.p: - parser.error("options -i and -p are mutually exclusive") - if options.i and options.s: - parser.error("options -i and -s are mutually exclusive") - if options.i and options.o: - parser.error("options -i and -o are mutually exclusive") - if not options.i and not options.p: - parser.error("either -i or -p must be specified") + parser = argparse.ArgumentParser() + action_group = parser.add_mutually_exclusive_group(required=True) + action_group.add_argument("-i", action="store_true", + help="ingest mode", default=False) + action_group.add_argument("-p", action="store_true", + help="process mode", default=False) + parser.add_argument("-s", dest="s", action="store_true", + help="Skip run timebase processes", default=False) + parser.add_argument("-o", "--only", dest="o", type=str, + help='Run only listed processes (either id or name)', default = None) + parser.add_argument("-m", "--mission", required=True, + help="selected mission database", default=None) + parser.add_argument("-d", "--dryrun", action="store_true", + help="only do a dryrun processing or ingesting", default=False) + parser.add_argument("-r", "--report", action="store_true", + help="Make the html report", default=False) + parser.add_argument("-l", "--log-level", dest="loglevel", + help="Set the logging level", default="debug") + parser.add_argument("-n", "--num-proc", dest="numproc", type=int, + help="Number of processes to run in parallel", default=2) + parser.add_argument("--echo", action="store_true", + help="Start sqlalchemy with echo in place for debugging", default=False) + parser.add_argument("--glb", dest="glob", type=str, + help='Glob to use when reading files from incoming: default "*"', default="*") + + options = parser.parse_args() + + if options.s and not options.p: + parser.error('-s requires -p') + if options.o and not options.p: + parser.error('-o requires -p') logname = os.path.basename(options.mission).replace('.', '_') DBlogging.change_logfile(logname) diff --git a/scripts/QCEmailer_conf.txt b/scripts/QCEmailer_conf.txt deleted file mode 100644 index 705f680c..00000000 --- a/scripts/QCEmailer_conf.txt +++ /dev/null @@ -1,23 +0,0 @@ - - -[QCEmail] -address = ectsoc@lanl.gov -imap = oppie-mail.lanl.gov:993 -password = PASSWORD -processed = Processed -sent = QCSent -smtp = oppie-mail.lanl.gov:25 -username = ectsoc - -[REPT] -rx = balarsen@lanl.gov, rfriedel@lanl.gov - -[MAGEIS] -rx = balarsen@lanl.gov, rfriedel@lanl.gov - -[HOPE] -rx = balarsen@lanl.gov, rfriedel@lanl.gov - -[SOC] -rx = balarsen@lanl.gov, rfriedel@lanl.gov - diff --git a/scripts/addFromConfig.py b/scripts/addFromConfig.py index b23bdea8..5b284db0 100755 --- a/scripts/addFromConfig.py +++ b/scripts/addFromConfig.py @@ -23,7 +23,7 @@ import shutil import sys import tempfile -from optparse import OptionParser +import argparse from ast import literal_eval as make_tuple from sqlalchemy.orm.exc import NoResultFound @@ -298,18 +298,17 @@ def addStuff(cfg, options): if __name__ == "__main__": - usage = "usage: %prog [options] -m mission_db filename" - parser = OptionParser(usage=usage) - parser.add_option("-m", "--mission", dest="mission", type="string", - help="mission to connect to", default='') - parser.add_option("-v", "--verify", dest="verify", action='store_true', - help="Don't do anything other than verify the config file", default=False) - - (options, args) = parser.parse_args() - if len(args) != 1: - parser.error("incorrect number of arguments") - - filename = os.path.expanduser(args[0]) + parser = argparse.ArgumentParser() + parser.add_argument("-m", "--mission", type=str, + help="mission to connect to", default='') + parser.add_argument("-v", "--verify", action='store_true', + help="Don't do anything other than verify the config file", default=False) + parser.add_argument('config_file', action='store', type=str, + help='Configuration file to read from') + + options = parser.parse_args() + + filename = os.path.expanduser(options.config_file) if not os.path.isfile(filename): parser.error("file: {0} does not exist or is not readable".format(filename)) diff --git a/scripts/configFromDB.py b/scripts/configFromDB.py index 3dea30c3..a33bab90 100755 --- a/scripts/configFromDB.py +++ b/scripts/configFromDB.py @@ -3,7 +3,7 @@ import ConfigParser import os -from optparse import OptionParser +import argparse from dbprocessing import DButils from dbprocessing import Utils @@ -102,29 +102,32 @@ """ if __name__ == "__main__": - usage = "usage: %prog [options] -m mission_db filename" - parser = OptionParser(usage=usage) + parser = argparse.ArgumentParser() parser.set_defaults(mission=None) parser.set_defaults(force=False) parser.set_defaults(satellite=None) parser.set_defaults(nocomments=False) - parser.add_option("-m", "--mission", dest="mission", type="string", - help="mission to connect to") - parser.add_option("-f", "--force", dest="force", action="store_true", - help="Force the processing, overwrite the outfile") - parser.add_option("-s", "--satellite", dest="satellite", type="string", - help="satellite to write to conf file (one per file)") - parser.add_option("-i", "--instrument", dest="instrument", type="string", - help="instrument to write to conf file (one per file)") - parser.add_option("-c", "--nocomments", dest="nocomments", action='store_true', - help="Do not add comments to the top of the config file") + parser.add_argument("-m", "--mission", dest="mission", type=str, + default=None, + help="mission to connect to") + parser.add_argument("-f", "--force", dest="force", action="store_true", + default=False, + help="Force the processing, overwrite the outfile") + parser.add_argument("-s", "--satellite", dest="satellite", type=str, + default=None, + help="satellite to write to conf file (one per file)") + parser.add_argument("-i", "--instrument", dest="instrument", type=str, + help="instrument to write to conf file (one per file)") + parser.add_argument("-c", "--nocomments", dest="nocomments", action='store_true', + default=False, + help="Do not add comments to the top of the config file") + parser.add_argument('config_file', action='store', type=str, + help='Configuration file to write') - (options, args) = parser.parse_args() - if len(args) != 1: - parser.error("incorrect number of arguments") + options = parser.parse_args() - filename = os.path.expandvars(os.path.expanduser(args[0])) + filename = os.path.expandvars(os.path.expanduser(options.config_file)) if os.path.isfile(filename) and not options.force: parser.error("file: {0} exists and will not be overwritten (use --force)".format(filename)) diff --git a/scripts/copyDatabase.py b/scripts/copyDatabase.py deleted file mode 100755 index 69f55074..00000000 --- a/scripts/copyDatabase.py +++ /dev/null @@ -1,77 +0,0 @@ -import sys -import os - -import collections -import datetime -import functools -import hashlib -import itertools -import math -import numpy -import os -import os.path -import struct -import warnings -import pkgutil - -import sqlalchemy -import sqlalchemy.engine.reflection -import sqlalchemy.sql - -from dbprocessing import DButils -from optparse import OptionParser - -def copyDB(DBname = None): - - - usage = \ - """ - Usage: %prog -m - -m -> selects mission - """ - parser = OptionParser(usage=usage) - parser.add_option("-m", "--mission", dest="mission", - help="selected mission database", default=None) - (options, args) = parser.parse_args() - if len(args) != 0: - parser.error("incorrect number of arguments") - - DButils.CreateDB(copiedDB_test.db) - #a = DButils.DButils('/home/natejm/dbprocessing/tests/testDB/testDB.sqlite') - #a.CreateDB(copiedDB_test.db) - - -""" - copyName = '/home/natejm/dbprocessing/tests/testDB/testDB_COPY.sqlite' - db_conn = sqlite3.connect(DBname) - cp_conn = sqlite3.connect(copyName) - c = db_conn.cursor() - cpy = cp_conn.cursor() - - c.execute("SELECT name FROM sqlite_master WHERE type='table';") - tables = c.fetchall() - - for table in tables: - c.execute("SELECT * FROM %s" %table) - rows = c.fetchall() - #print("testing: %s this is some %s testing you know.." %(rows, table)) - tableStr = 'CREATE TABLE IF NOT EXISTS %s' %table - tableStr= tableStr +'(None)' - cpy.execute(tableStr) - #print(rows) - for row in rows: - r = str(row) - s = 'ALTER TABLE %s' %table - s = s + ' ADD COLUMN %s' %r - #cpy.execute(s) - print('\n') - print(row) - - cp_conn.commit() - c.close() - cpy.close() - db_conn.close() - - -""" -copyDB('/home/natejm/dbprocessing/tests/testDB/testDB.sqlite') diff --git a/scripts/coveragePlot.py b/scripts/coveragePlot.py index fe4a85ab..f97ca66d 100755 --- a/scripts/coveragePlot.py +++ b/scripts/coveragePlot.py @@ -8,12 +8,12 @@ """ from __future__ import division +import argparse import ConfigParser import datetime import fnmatch import os import subprocess -from optparse import OptionParser import matplotlib @@ -163,14 +163,14 @@ def _combine_coverage(inval): if __name__ == "__main__": - usage = "usage: %prog [options] configfile" - parser = OptionParser(usage=usage) + parser = argparse.ArgumentParser() + parser.add_argument('configfile', action='store', type=str, + help='Plot configuration file to read') - (options, args) = parser.parse_args() - if len(args) != 1: - parser.error("incorrect number of arguments") + options = parser.parse_args() - conffile = os.path.expanduser(os.path.expandvars(os.path.abspath(args[0]))) + conffile = os.path.expanduser(os.path.expandvars(os.path.abspath( + options.configfile))) if not os.path.isfile(conffile): parser.error("could not read config file: {0}".format(conffile)) diff --git a/scripts/dbOnlyFiles.py b/scripts/dbOnlyFiles.py index 95682f48..1b4ad1a4 100755 --- a/scripts/dbOnlyFiles.py +++ b/scripts/dbOnlyFiles.py @@ -6,10 +6,10 @@ """ from __future__ import division +import argparse import bisect import datetime import os -from optparse import OptionParser from dateutil import parser as dup from dateutil.relativedelta import relativedelta @@ -19,31 +19,28 @@ from dbprocessing.Utils import progressbar if __name__ == "__main__": - usage = "%prog -m mission" - parser = OptionParser(usage=usage) - parser.add_option("-s", "--startDate", dest="startDate", type="string", - help="Date to start reprocessing (e.g. 2012-10-02)", default=None) - parser.add_option("-e", "--endDate", dest="endDate", type="string", - help="Date to end reprocessing (e.g. 2012-10-25)", default=None) - parser.add_option("-f", "--fix", dest="fix", action='store_true', - help="Fix the database exists_on_disk field ", default=False) - parser.add_option("-m", "--mission", dest="mission", - help="selected mission database", default=None) - parser.add_option("", "--echo", dest="echo", action='store_true', - help="echo sql queries for debugging", default=False) - parser.add_option("-n", "--newest", dest="newest", action='store_true', - help="Only check the newest files", default=False) - parser.add_option("", "--startID", dest="startID", type="int", - help="The File id to start on", default=1) - parser.add_option("-v", "--verbose", dest="verbose", action='store_true', - help="Print out each file as it is checked", default=False) - parser.add_option("-p", "--path", dest="path", action="store_true", - help="Print full file path of missing files", default=False) + parser = argparse.ArgumentParser() + parser.add_argument("-s", "--startDate", type=str, + help="Date to start reprocessing (e.g. 2012-10-02)", default=None) + parser.add_argument("-e", "--endDate", type=str, + help="Date to end reprocessing (e.g. 2012-10-25)", default=None) + parser.add_argument("-f", "--fix", action='store_true', + help="Fix the database exists_on_disk field ", default=False) + parser.add_argument("-m", "--mission", + help="selected mission database", required=True) + parser.add_argument("--echo", action='store_true', + help="echo sql queries for debugging", default=False) + parser.add_argument("-n", "--newest", action='store_true', + help="Only check the newest files", default=False) + parser.add_argument("--startID", type=int, + help="The File id to start on", default=1) + parser.add_argument("-v", "--verbose", action='store_true', + help="Print out each file as it is checked", default=False) + parser.add_argument("-p", "--path", action="store_true", + help="Print full file path of missing files", default=False) - (options, args) = parser.parse_args() - if len(args) != 0: - parser.error("incorrect number of arguments") + options = parser.parse_args() if options.startDate is not None: startDate = dup.parse(options.startDate) diff --git a/scripts/deleteAllDBFiles.py b/scripts/deleteAllDBFiles.py index 7fc5898f..72cf3298 100755 --- a/scripts/deleteAllDBFiles.py +++ b/scripts/deleteAllDBFiles.py @@ -2,22 +2,15 @@ from __future__ import print_function -from optparse import OptionParser +import argparse from dbprocessing import DButils if __name__ == "__main__": - usage = \ - """ - Usage: %prog -m - -m -> selects mission - """ - parser = OptionParser(usage=usage) - parser.add_option("-m", "--mission", dest="mission", - help="selected mission database", default=None) - (options, args) = parser.parse_args() - if len(args) != 0: - parser.error("incorrect number of arguments") + parser = argparse.ArgumentParser() + parser.add_argument("-m", "--mission", dest="mission", + help="selected mission database", required=True) + options = parser.parse_args() a = DButils.DButils(options.mission) f = a.getAllFilenames() diff --git a/scripts/deleteAllDBProducts.py b/scripts/deleteAllDBProducts.py deleted file mode 100755 index a675528f..00000000 --- a/scripts/deleteAllDBProducts.py +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/env python - -from __future__ import print_function - -from dbprocessing import DButils - - -if __name__ == "__main__": - a = DButils.DButils('rbsp') - a.openDB() - a._createTableObjects() - prod_ids = zip(*a.getProductNames())[4] - - for ff in f: - a._purgeFileFromDB(ff[0]) - print('deleted {0} files'.format(len(f))) - diff --git a/scripts/deleteFromDB.py b/scripts/deleteFromDB.py deleted file mode 100644 index 97470476..00000000 --- a/scripts/deleteFromDB.py +++ /dev/null @@ -1,143 +0,0 @@ -""" -UNFINISHED -TODO: For all files before date, check the graph and see - if they can be deleted without conflict. -""" - -import sys -import os -import sqlite3 -import re -import Graph - -from dbprocessing import DButils - -def create_connection(db_file): - """ create a database connection to the SQLite database - specified by the db_file - :param db_file: database file - :return: Connection object or None - """ - try: - conn = sqlite3.connect(db_file) - return conn - except Error as e: - print(e) - - return None - -def delete_before_date(conn, date): - """ - Delete all files before certain date - :param conn: Connection to the SQLite database - :param date: Date before which files are to be deleted - :return: - """ - numDel = 0 - d = ''.join(date) - d = re.sub('-', '', d) - d = int(d) # Converts date string into int. - - graph = create_graph(conn) - - sql = 'DELETE FROM file WHERE utc_file_date=?' - cur = conn.cursor() - cur.execute("SELECT file_id,utc_file_date FROM file") - files = cur.fetchall() - count = 0 - filesToBeDeleted = [] - for file in files: #Creates list of all files before date - f = ''.join(file[1]) - f = re.sub('-', '', f) - f = int(f) - if f <= d: - #cur.execute(sql, file[1]) - filesToBeDeleted.append(f) - count += 1 - """ - TODO: Check to see if files in ftbd have connections in graph. - If it has neighbors, delete only if neighbors are also in ftbd, - otherwise if no neighbors just delete & update tables. - - for f in filesToBeDeleted: - node = graph.getNode(str(f[0])) - neighbors = graph.neighbors(node) - if neighbors == {}: - cur.execute(sql, f[1]) - numDel += 1 - else: - for n in neighbors: - if n in filesToBeDeleted: - cur.execute(sql, f[i]) - cur.execute(sql, n) - numDel += 2 - """ - - print('{0} files before {1}, {2} deleted.'.format(count,date,numDel)) - -def delete_all_files(conn): - """ - Delete all rows in the tasks table - :param conn: Connection to the SQLite database - :return: - """ - sql = 'DELETE FROM file' - cur = conn.cursor() - cur.execute(sql) - -def create_graph(conn): - """ - Creates a graph with directed edge from all source files - to the result files within filefilelink. - :param conn: Connection to the SQLite database - :return: Directed Graph. - """ - c = conn.cursor() - c.execute("SELECT source_file, resulting_file FROM filefilelink") - rows = c.fetchall() - count = 0 - graph = Graph.Graph() - - for r in rows: - if not graph.contains(r[0]): - graph.add_node(r[0]) - - if not graph.contains(r[1]): - graph.add_node(r[1]) - - graph.add_edge(r[0], r[1]) - verts = graph.nodes() - - for a in verts: - print(a) - print(graph.neighbors(a)) - print("____________") - - return graph - -def adjust_links(conn, graph): - """ - Checks the file links to make sure deleted file - doesn't affect other files, and adjusts - the table if files are to be deleted. - :param conn: Connection to the SQLite database - :param fileNum: Number of the file in question - :return: boolean: Whether file can be deleted. - """ - graph = self.create_graph(conn) - -def main(): - - database = '/home/natejm/dbprocessing/tests/testDB/testDB2.sqlite' - # create a database connection - conn = create_connection(database) - with conn: - delete_before_date(conn, '2016-01-01'); - #adjust_links(conn, 0) - create_graph(conn) - -if __name__ == '__main__': - main() - - - diff --git a/scripts/fast_data.py b/scripts/fast_data.py index f7253fd8..5d70da98 100644 --- a/scripts/fast_data.py +++ b/scripts/fast_data.py @@ -1,9 +1,9 @@ #!/usr/bin/env python +import argparse import datetime import itertools import os -from optparse import OptionParser import warnings import networkx @@ -113,38 +113,35 @@ def reap(dbu, graph, participants, dofiles=False, dorecords=False, verbose=False if __name__ == '__main__': - usage = "usage: %prog -m database -d YYYY-MM-DD [--reap-files] [--reap-records] [--verbose]" - parser = OptionParser(usage=usage) - parser.add_option( + parser = argparse.ArgumentParser() + parser.add_argument( "-m", "--mission", - dest="mission", + required=True, help="selected mission database",) - parser.add_option( - "-d", + parser.add_argument( "--cutoff", - dest="cutoff", + required=True, help="What date to use as the fast data cut off",) - parser.add_option( + parser.add_argument( "--reap-files", dest="files", action='store_true', help="Removes all Level0 files, and all of their children, that are not the newest version and are newer than the cut off date. It will still keep the records of the files in the dbprocessing database, but sets exists_on_disk to false.", default=False) - parser.add_option( + parser.add_argument( "--reap-records", dest="records", action='store_true', help="Removes any file records that are marked as not exists_on_disk, and will sanity check that none of its children are still on disk. It also removes the corresponding file_file_links and file_code_links.", default=False) - parser.add_option( + parser.add_argument( "--verbose", - dest="verbose", action='store_true', help="Prints names of files that will be deleted", default=False) - (options, args) = parser.parse_args() + options = parser.parse_args() if options.mission is None: parser.error("Mission needs to be specified") @@ -153,7 +150,7 @@ def reap(dbu, graph, participants, dofiles=False, dorecords=False, verbose=False cut_date = datetime.datetime.strptime( options.cutoff, "%Y-%m-%d").date() except TypeError as err: - parser.error("Must pass a cutoff date") + parser.error("Must pass a cutoff date in form YYYY-MM-DD") except ValueError as err: parser.error(err.message) diff --git a/scripts/histogramCodes.py b/scripts/histogramCodes.py index 3295e8dd..81f620d5 100755 --- a/scripts/histogramCodes.py +++ b/scripts/histogramCodes.py @@ -1,9 +1,9 @@ #!/usr/bin/env python +import argparse import itertools import glob import os -from optparse import OptionParser import re import sys import traceback @@ -15,13 +15,11 @@ if __name__ == '__main__': - usage = "usage: %prog logfile [[logfile]...]" - parser = OptionParser(usage=usage) + parser = argparse.ArgumentParser() + parser.add_argument('logfile', action='store', type=str, nargs='+', + help='Name of dbprocessing log to parse.') - (options, args) = parser.parse_args() - - if len(args) < 1: - parser.error("incorrect number of arguments") + options = parser.parse_args() """ @@ -29,9 +27,7 @@ make histograms by code """ - files = args - if not files: - parser.error("No files matching {0} found".format(args[0])) + files = options.logfile lines = [] # read in each file and add to lines the lines that fit the format: diff --git a/scripts/htmlCoverage.py b/scripts/htmlCoverage.py index ac4f5d60..3b17ef41 100755 --- a/scripts/htmlCoverage.py +++ b/scripts/htmlCoverage.py @@ -1,12 +1,12 @@ #!/usr/bin/env python from __future__ import print_function +import argparse import datetime import glob import os import sys import re -from optparse import OptionParser import tempfile import shutil import time @@ -197,16 +197,14 @@ def makeHeader(): if __name__ == "__main__": - usage = "usage: %prog [options] -m mission_db outhtmlbase\n outhtmlbase is th base name _mission.html is appended" - parser = OptionParser(usage=usage) - parser.add_option("-m", "--mission", dest="mission", type="string", - help="mission to connect to", default='~ectsoc/RBSP_processing.sqlite') - parser.add_option("-d", "--deltadays", dest="deltadays", type="int", - help="days past last file to make table", default=3) - - (options, args) = parser.parse_args() - if len(args) != 1: - parser.error("incorrect number of arguments") + parser = argparse.ArgumentParser() + parser.add_argument("-m", "--mission", type=str, + help="mission to connect to", default='~ectsoc/RBSP_processing.sqlite') + parser.add_argument("-d", "--deltadays", type=int, + help="days past last file to make table", default=3) + parser.add_argument('outbase', type=str, + help='Output filename base; _mission.html is appended.') + options = parser.parse_args() Time1 = time.time() info, dbu = getInfo(options.mission) @@ -214,7 +212,7 @@ def makeHeader(): for sat in info: filename = makeHTML(dbu, info, sat, delta_days=options.deltadays) - outname = args[0] + '_{0}.html'.format(sat) + outname = options.outbase + '_{0}.html'.format(sat) shutil.move(filename, outname) os.chmod(outname, 0664) Time1 = EventTimer ('Created: {0}'.format(outname), Time1) diff --git a/scripts/magephem_dataToIncoming.py b/scripts/magephem_dataToIncoming.py deleted file mode 100755 index 2b2d0317..00000000 --- a/scripts/magephem_dataToIncoming.py +++ /dev/null @@ -1,55 +0,0 @@ -#!/usr/bin/python - -import datetime -import itertools -import os -import re -import shutil -import subprocess - -import dbprocessing.DButils as DBUtils -import dbprocessing.DBlogging as DBlogging - -""" -make a meta kernel each day that is dated 2 weeks out -1) figure out what files we have -2) figure out what 2 weeks from today is -3) make a list of all dates that would be today through 2 weeks -4) if we do not have that file make it - - if yes, done, if no runnewMetaKernel.py and drop in incoming -""" - -dbu = DBUtils.DButils(os.path.expanduser('/home/ectsoc/PROCESSING_DB/magephem_pre.sqlite')) - -mission_path = dbu.getMissionDirectory() -g_inc_path = dbu.getIncomingPath() - -filesa = dbu.getFilesByProduct('rbspa_pre_kernel') -filesb = dbu.getFilesByProduct('rbspb_pre_kernel') - -#files = sorted(files, key=lambda x: x.utc_file_date)[-1] -dbu.closeDB() - -filesa = set(v.filename for v in filesa) -filesb = set(v.filename for v in filesb) -files = filesa.union(filesb) - -dates = [datetime.datetime.utcnow().date() + datetime.timedelta(days=v) for v in range(21)] - -files_2weeks = [] -for dt in dates: - files_2weeks.append('Setup_{0}.ker'.format(dt.strftime('%Y%m%d'))) -files_2weeks = set(files_2weeks) - -files_to_make = files_2weeks.difference(files) - -for f in files_to_make: - cmd = [os.path.expanduser('~/.local/bin/newMetaKernel.py'), '-p', - os.path.join(g_inc_path, f)] - print(' '.join(cmd)) - subprocess.check_call(cmd, shell=False) - - - - - diff --git a/scripts/magephem_def_dataToIncoming.py b/scripts/magephem_def_dataToIncoming.py deleted file mode 100755 index b584030e..00000000 --- a/scripts/magephem_def_dataToIncoming.py +++ /dev/null @@ -1,56 +0,0 @@ -#!/usr/bin/python - -import datetime -import itertools -import os -import re -import shutil -import subprocess - -import dbprocessing.DButils as DBUtils -import dbprocessing.DBlogging as DBlogging - -""" -make a meta kernel each day that is dated 2 weeks out -1) figure out what files we have -2) figure out what 2 weeks from today is -3) make a list of all dates that would be today through 2 weeks -4) if we do not have that file make it - - if yes, done, if no runnewMetaKernel.py and drop in incoming -""" - -dbu = DBUtils.DButils(os.path.expanduser('/home/ectsoc/PROCESSING_DB/magephem_def.sqlite')) - -mission_path = dbu.getMissionDirectory() -g_inc_path = dbu.getIncomingPath() - -filesa = dbu.getFilesByProduct('rbspa_def_kernel') - -#files = sorted(files, key=lambda x: x.utc_file_date)[-1] -dbu.closeDB() - -files = set(v.filename for v in filesa) - -dt = datetime.datetime(2012, 8, 31) -dates = [] -while dt < datetime.datetime.today(): - dates.append(dt) - dt += datetime.timedelta(days=1) - -files_2weeks = [] -for dt in dates: - files_2weeks.append('rbspa_def_kernel_{0}.ker'.format(dt.strftime('%Y%m%d'))) -files_2weeks = set(files_2weeks) - -files_to_make = files_2weeks.difference(files) - -for f in files_to_make: - cmd = [os.path.expanduser('~/.local/bin/newMetaKernel.py'), '-d', - os.path.join(g_inc_path, f)] - print(' '.join(cmd)) - subprocess.check_call(cmd, shell=False) - - - - - diff --git a/scripts/makeLatestSymlinks.py b/scripts/makeLatestSymlinks.py index 82750b88..e31a8961 100755 --- a/scripts/makeLatestSymlinks.py +++ b/scripts/makeLatestSymlinks.py @@ -6,12 +6,12 @@ from __future__ import print_function +import argparse import ConfigParser import datetime import glob from pprint import pprint import os -from optparse import OptionParser import sys import re import traceback @@ -193,24 +193,20 @@ def readconfig(config_filepath): if __name__ == '__main__': - usage = "usage: %prog config" - parser = OptionParser(usage=usage) - parser.add_option("", "--verbose", - dest="verbose", action='store_true', - help="Print out verbose information", default=False) - parser.add_option("-l", "--list", - dest="list", action='store_true', - help="Instead of syncing list the sections of the conf file", default=False) - parser.add_option("-f", "--filter", - dest="filter", + parser = argparse.ArgumentParser() + parser.add_argument("--verbose", + action='store_true', + help="Print out verbose information", default=False) + parser.add_argument("-l", "--list", + action='store_true', + help="Instead of syncing list the sections of the conf file", default=False) + parser.add_argument("-f", "--filter", help="Comma seperated list of strings that must be in the sync conf name (e.g. -f hope,rbspa)", default=None) + parser.add_argument('config', type=str, help='Configuration file') - (options, args) = parser.parse_args() + options = parser.parse_args() - if len(args) != 1: - parser.error("incorrect number of arguments") - - conffile = os.path.abspath(os.path.expanduser((os.path.expandvars(args[0])))) + conffile = os.path.abspath(os.path.expanduser((os.path.expandvars(options.config)))) if not os.path.isfile(conffile): parser.error("Config file not readable ({0})".format(conffile)) diff --git a/scripts/missingFiles.py b/scripts/missingFiles.py index 49c0f712..ff290e89 100755 --- a/scripts/missingFiles.py +++ b/scripts/missingFiles.py @@ -6,10 +6,10 @@ """ +import argparse import datetime import fnmatch import os -from optparse import OptionParser import subprocess from dateutil import parser as dup @@ -21,18 +21,16 @@ if __name__ == "__main__": - parser = OptionParser() - parser.add_option("-s", "--startDate", dest="startDate", type="string", - help="Date to start search (e.g. 2012-10-02 or 20121002)", default=None) - parser.add_option("-e", "--endDate", dest="endDate", type="string", - help="Date to end search (e.g. 2012-10-25 or 20121025)", default=None) - parser.add_option("-m", "--mission", dest="mission", - help="selected mission database **required**", default=None) + parser = argparse.ArgumentParser() + parser.add_argument("-s", "--startDate", dest="startDate", type=str, + help="Date to start search (e.g. 2012-10-02 or 20121002)", default=None) + parser.add_argument("-e", "--endDate", dest="endDate", type=str, + help="Date to end search (e.g. 2012-10-25 or 20121025)", default=None) + parser.add_argument("-m", "--mission", dest="mission", required=True, + help="selected mission database **required**", default=None) - (options, args) = parser.parse_args() - if len(args) != 0: - parser.error("incorrect number of arguments") + options = parser.parse_args() if options.startDate is not None: startDate = dup.parse(options.startDate) diff --git a/scripts/missingFilesByProduct.py b/scripts/missingFilesByProduct.py index e246a79a..6868b83b 100755 --- a/scripts/missingFilesByProduct.py +++ b/scripts/missingFilesByProduct.py @@ -6,10 +6,10 @@ """ +import argparse import datetime import fnmatch from operator import itemgetter -from optparse import OptionParser import sys import warnings @@ -20,30 +20,30 @@ from dbprocessing import DButils from dbprocessing import inspector -usage = "%prog -m mission product_id [-s startDate] [-e endDate] [-f filter] [-p] [--parent=parent_id]" warnings.filterwarnings("ignore") if __name__ == "__main__": - parser = OptionParser(usage=usage) - parser.add_option("-s", "--startDate", dest="startDate", type="string", - help="Date to start search (e.g. 2012-10-02 or 20121002)", default=None) - parser.add_option("-e", "--endDate", dest="endDate", type="string", - help="Date to end search (e.g. 2012-10-25 or 20121025)", default=None) - parser.add_option("-m", "--mission", dest="mission", - help="selected mission database **required**", default=None) - parser.add_option("-f", "--filter", dest='filter', - help="Filter to use on filename (space separated globs)", default=None) - parser.add_option("-p", "--process", dest='process', action='store_true', default=False, - help="Add those dates to the process queue for the specified DB") - parser.add_option("", "--parent", dest='parent', type='int', default=None, - help="The parent product ID to enable processing of the missing files") - parser.add_option("", "--echo", dest='echo', default=False, action='store_true', - help="But the database in echo mode") + parser = argparse.ArgumentParser() + parser.add_argument("-s", "--startDate", type=str, + help="Date to start search (e.g. 2012-10-02 or 20121002)", default=None) + parser.add_argument("-e", "--endDate", type=str, + help="Date to end search (e.g. 2012-10-25 or 20121025)", default=None) + parser.add_argument("-m", "--mission", required=True, + help="selected mission database **required**", default=None) + parser.add_argument("-f", "--filter", + help="Filter to use on filename (space separated globs)", default=None) + parser.add_argument("-p", "--process", action='store_true', default=False, + help="Add those dates to the process queue for the specified DB") + parser.add_argument("--parent", type=int, default=None, + help="The parent product ID to enable processing of the missing files") + parser.add_argument("--echo", default=False, action='store_true', + help="But the database in echo mode") + parser.add_argument('product_id', action='store', type=int, + help='Product ID to check.') - (options, args) = parser.parse_args() - if len(args) != 1: - parser.error("incorrect number of arguments") + options = parser.parse_args() + print(options) if options.startDate is not None: startDate = dup.parse(options.startDate) @@ -73,7 +73,7 @@ # this is the possible dates for a product dates = sorted(dates) - product_id = args[0] + product_id = options.product_id dbfiles = dbu.getFilesByProductDate(product_id, [startDate, endDate], diff --git a/scripts/newestVersionProblemFinder.py b/scripts/newestVersionProblemFinder.py index 3cdad368..c2cb5e48 100755 --- a/scripts/newestVersionProblemFinder.py +++ b/scripts/newestVersionProblemFinder.py @@ -4,7 +4,7 @@ Run both the old and new methods of finding newestVersion and report differences """ -from optparse import OptionParser +import argparse from operator import itemgetter from datetime import date @@ -108,18 +108,16 @@ def oldGetFilesByProduct(dbu, prod_id, newest_version=False): return sq.all() if __name__ == "__main__": - parser = OptionParser() - parser.add_option("-m", "--mission", dest="mission", - help="selected mission database") - parser.add_option("--settest", dest="settest", default=True, action="store_true", - help="Run the tests that compare the results of the \ - old and new implementations of newest_version") - parser.add_option("--errortest", dest="errortest", default=True, action="store_true", - help="Check if any file has a newer file_create_date but lower version number") - - (options, args) = parser.parse_args() - if len(args) != 0: - parser.error("incorrect number of arguments") + parser = argparse.ArgumentParser() + parser.add_argument("-m", "--mission", dest="mission", required=True, + help="selected mission database") + parser.add_argument("--settest", dest="settest", default=True, action="store_true", + help="Run the tests that compare the results of the \ + old and new implementations of newest_version") + parser.add_argument("--errortest", dest="errortest", default=True, action="store_true", + help="Check if any file has a newer file_create_date but lower version number") + + options = parser.parse_args() dbu = DButils.DButils(options.mission) @@ -154,4 +152,4 @@ def oldGetFilesByProduct(dbu, prod_id, newest_version=False): files2 = dbu.getFiles(product=f.product_id, startDate=f.utc_file_date, endDate=f.utc_file_date) for f2 in files2: if f.file_create_date < f2.file_create_date: - print('{0} is the "Newest Version", however was created after {1}'.format(f.filename, f2.filename)) \ No newline at end of file + print('{0} is the "Newest Version", however was created after {1}'.format(f.filename, f2.filename)) diff --git a/scripts/possibleProblemDates.py b/scripts/possibleProblemDates.py index ae6c73b1..c20682bf 100755 --- a/scripts/possibleProblemDates.py +++ b/scripts/possibleProblemDates.py @@ -2,8 +2,8 @@ from __future__ import division +import argparse import datetime -from optparse import OptionParser from sqlalchemy import func @@ -124,23 +124,14 @@ def noNewestVersion(dbu, fix=False): if __name__ == "__main__": - usage = "%prog" - parser = OptionParser(usage=usage) - parser.add_option("-m", "--mission", dest="mission", - help="selected mission", default=None) - parser.add_option("", "--fix", dest="fix", action='store_true', - help="Fix the issues (make a backup first)", default=False) - parser.add_option("", "--echo", dest="echo", action='store_true', - help="enable sqlalchemy echo mode for debugging", default=False) - (options, args) = parser.parse_args() - - - if len(args) != 0: - parser.error("incorrect number of arguments") - - if options.mission is None: - parser.error("-m must be specified") - + parser = argparse.ArgumentParser() + parser.add_argument("-m", "--mission", required=True, + help="selected mission", default=None) + parser.add_argument("--fix", action='store_true', + help="Fix the issues (make a backup first)", default=False) + parser.add_argument("--echo", action='store_true', + help="enable sqlalchemy echo mode for debugging", default=False) + options = parser.parse_args() dbu = DButils.DButils(options.mission, echo=options.echo) diff --git a/scripts/printInfo.py b/scripts/printInfo.py index df28f475..2a363393 100755 --- a/scripts/printInfo.py +++ b/scripts/printInfo.py @@ -1,10 +1,10 @@ #!/usr/bin/env python +import argparse import datetime import itertools import glob import os -from optparse import OptionParser import re import sys import traceback @@ -26,23 +26,25 @@ def getProductString(p, basepath): if __name__ == '__main__': - usage = "usage: %prog database field \n Field can be: Product, Mission (more to come)" - parser = OptionParser(usage=usage) - parser.add_option("-p", "--product", dest="product", - help='Product id (or name) to use, only used for "File"', default=None) - parser.add_option("-s", "--startDate", dest="startDate", type="string", - help='Date to start printing, only used for "File" (e.g. 2012-10-02)', default=None) - parser.add_option("-e", "--endDate", dest="endDate", type="string", + parser = argparse.ArgumentParser() + parser.add_argument("-p", "--product", + help='Product id (or name) to use, only used for "File"', default=None) + parser.add_argument("-s", "--startDate", dest="startDate", type=str, + help='Date to start printing, only used for "File" (e.g. 2012-10-02)', default=None) + parser.add_argument("-e", "--endDate", dest="endDate", type=str, help='Date to end printing, only used for "File" (e.g. 2012-10-25)', default=None) + parser.add_argument( + 'database', action='store', type=str, + help='Name of database (or sqlite file), i.e. mission, to open.') + parser.add_argument( + 'field', action='store', type=str, + help='Field to print (Product, Mission; more to come)') - (options, args) = parser.parse_args() + options = parser.parse_args() - if len(args) != 2: - parser.error("incorrect number of arguments") - - mission = args[0] - field = args[1].capitalize() + mission = options.database + field = options.field.capitalize() dbu = DButils.DButils(mission) diff --git a/scripts/printProcessQueue.py b/scripts/printProcessQueue.py index 261d5273..3cbae91d 100755 --- a/scripts/printProcessQueue.py +++ b/scripts/printProcessQueue.py @@ -1,8 +1,8 @@ #!/usr/bin/env python from __future__ import print_function +import argparse import datetime -from optparse import OptionParser from dbprocessing import DButils @@ -63,18 +63,18 @@ def output_text(items): return output if __name__ == '__main__': - parser = OptionParser() - parser.add_option("", "--html", dest="html", action="store_true", - help="Output in html", default=False) - parser.add_option("-o", "--output", dest="output", - help="Write output to a file") - - (options, args) = parser.parse_args() - - if( len(args) != 1 ): - parser.error("Must pass a mission DB") - - dbu = DButils.DButils(args[0]) + parser = argparse.ArgumentParser() + parser.add_argument("--html", action="store_true", + help="Output in html", default=False) + parser.add_argument("-o", "--output", + help="Write output to a file") + parser.add_argument( + 'database', action='store', type=str, + help='Name of database (or sqlite file), i.e. mission, to open.') + + options = parser.parse_args() + + dbu = DButils.DButils(options.database) items = dbu.Processqueue.getAll() traceback = [] for v in items: @@ -90,4 +90,4 @@ def output_text(items): else: output = open(options.output, 'w') output.write(out) - output.close() \ No newline at end of file + output.close() diff --git a/scripts/purgeFileFromDB.py b/scripts/purgeFileFromDB.py index 87482b3d..aac16eb1 100755 --- a/scripts/purgeFileFromDB.py +++ b/scripts/purgeFileFromDB.py @@ -2,25 +2,24 @@ from __future__ import print_function -from optparse import OptionParser +import argparse from dbprocessing import DButils if __name__ == '__main__': usage = "usage: %prog -m database filename [filename [filename] ...]" - parser = OptionParser(usage=usage) - parser.add_option("-r", "--recursive", dest="recursive", action="store_true", - help="Recursive removal", default=False) - parser.add_option("-v", "--verbose", dest="verbose", action="store_true", - help="Verbose", default=False) - parser.add_option("-m", "--mission", dest="mission", - help="selected mission database", default=None) - (options, args) = parser.parse_args() - - if len(args) < 1: - parser.error("incorrect number of arguments") + parser = argparse.ArgumentParser() + parser.add_argument("-r", "--recursive", action="store_true", + help="Recursive removal", default=False) + parser.add_argument("-v", "--verbose", action="store_true", + help="Verbose", default=False) + parser.add_argument("-m", "--mission", required=True, + help="selected mission database", default=None) + parser.add_argument("filename", nargs='+', + help="file(s) to purge", default=None) + options = parser.parse_args() dbu = DButils.DButils(options.mission) - dbu._purgeFileFromDB(args, recursive=options.recursive, verbose=options.verbose) - dbu.closeDB() \ No newline at end of file + dbu._purgeFileFromDB(options.filename, recursive=options.recursive, verbose=options.verbose) + dbu.closeDB() diff --git a/scripts/reprocessByCode.py b/scripts/reprocessByCode.py index 2688502d..5f2a1855 100755 --- a/scripts/reprocessByCode.py +++ b/scripts/reprocessByCode.py @@ -16,7 +16,7 @@ ## startDate - date to start the reprocess ## endDate - date to end the reprocess -from optparse import OptionParser +import argparse from dateutil import parser as dup @@ -25,19 +25,19 @@ if __name__ == "__main__": - parser = OptionParser() - parser.add_option("-s", "--startDate", dest="startDate", type="string", - help="Date to start reprocessing (e.g. 2012-10-02)", default=None) - parser.add_option("-e", "--endDate", dest="endDate", type="string", - help="Date to end reprocessing (e.g. 2012-10-25)", default=None) - parser.add_option("", "--force", dest="force", type="int", + parser = argparse.ArgumentParser() + parser.add_argument("-s", "--startDate", type=str, + help="Date to start reprocessing (e.g. 2012-10-02)", default=None) + parser.add_argument("-e", "--endDate", type=str, + help="Date to end reprocessing (e.g. 2012-10-25)", default=None) + parser.add_argument("--force", type=int, help="Force the reprocessing, specify which version number {0},{1},{2}", default=None) - parser.add_option("-m", "--mission", dest="mission", + parser.add_argument("-m", "--mission", required=True, help="selected mission database", default=None) + parser.add_argument('code', action='store', + help='Name or ID of code.') - (options, args) = parser.parse_args() - if len(args) != 1: - parser.error("incorrect number of arguments") + options = parser.parse_args() if options.startDate is not None: startDate = dup.parse(options.startDate) @@ -52,9 +52,9 @@ if options.force not in [None, 0, 1, 2]: parser.error("invalid force option [0,1,2]") - num = db.reprocessByCode(args[0], startDate=startDate, endDate=endDate, incVersion=options.force) + num = db.reprocessByCode(options.code, startDate=startDate, endDate=endDate, incVersion=options.force) - print('Added {0} files to be reprocessed for code {1}'.format(num, args[0])) - DBlogging.dblogger.info('Added {0} files to be reprocessed for code {1}'.format(num, args[0])) + print('Added {0} files to be reprocessed for code {1}'.format(num, options.code)) + DBlogging.dblogger.info('Added {0} files to be reprocessed for code {1}'.format(num, options.code)) diff --git a/scripts/reprocessByDate.py b/scripts/reprocessByDate.py index 73fd88cb..edf1de56 100755 --- a/scripts/reprocessByDate.py +++ b/scripts/reprocessByDate.py @@ -7,7 +7,7 @@ """ from __future__ import print_function -from optparse import OptionParser +import argparse from dateutil import parser as dup @@ -15,34 +15,25 @@ import dbprocessing.dbprocessing as dbprocessing if __name__ == "__main__": - usage = "%prog -s yyyymmdd -e yyyymmdd -m database" - parser = OptionParser(usage=usage) - parser.add_option("-s", "--startDate", dest="startDate", type="string", + parser = argparse.ArgumentParser() + parser.add_argument("-s", "--startDate", dest="startDate", type=str, required=True, help="Date to start reprocessing (e.g. 2012-10-02)", default=None) - parser.add_option("-e", "--endDate", dest="endDate", type="string", - help="Date to end reprocessing (e.g. 2012-10-25)", default=None) - parser.add_option("", "--force", dest="force", type="int", - help="Force the reprocessing, specify which version number {0},{1},{2}", default=None) - parser.add_option("-m", "--mission", dest="mission", - help="selected mission database", default=None) - parser.add_option("", "--echo", dest="echo", action='store_true', - help="echo sql queries for debugging", default=False) - parser.add_option("", "--level", dest="level", type='float', - help="The data level to reprocess", default=None) - - (options, args) = parser.parse_args() - if len(args) != 0: - parser.error("incorrect number of arguments") - - if options.startDate is not None: - startDate = dup.parse(options.startDate) - else: - parser.error("-s must be specified") - - if options.endDate is not None: - endDate = dup.parse(options.endDate) - else: - parser.error("-e must be specified") + parser.add_argument("-e", "--endDate", dest="endDate", type=str, required=True, + help="Date to end reprocessing (e.g. 2012-10-25)", default=None) + parser.add_argument("--force", dest="force", type=int, + help="Force the reprocessing, specify which version number {0},{1},{2}", default=None) + parser.add_argument("-m", "--mission", required=True, + help="selected mission database", default=None) + parser.add_argument("--echo", dest="echo", action='store_true', + help="echo sql queries for debugging", default=False) + parser.add_argument("--level", dest="level", type=float, + help="The data level to reprocess", default=None) + + options = parser.parse_args() + + startDate = dup.parse(options.startDate) + + endDate = dup.parse(options.endDate) if options.force not in [None, 0, 1, 2]: parser.error("invalid force option [0,1,2]") diff --git a/scripts/reprocessByInstrument.py b/scripts/reprocessByInstrument.py index 0d5de44f..370dd315 100755 --- a/scripts/reprocessByInstrument.py +++ b/scripts/reprocessByInstrument.py @@ -8,8 +8,7 @@ - -from optparse import OptionParser +import argparse from dateutil import parser as dup @@ -18,21 +17,21 @@ if __name__ == "__main__": - parser = OptionParser() - parser.add_option("-s", "--startDate", dest="startDate", type="string", - help="Date to start reprocessing (e.g. 2012-10-02)", default=None) - parser.add_option("-e", "--endDate", dest="endDate", type="string", - help="Date to end reprocessing (e.g. 2012-10-25)", default=None) - parser.add_option("", "--force", dest="force", type="int", - help="Force the reprocessing, specify which version number {0},{1},{2}", default=None) - parser.add_option("-l", "--level", dest="level", type="float", - help="The level to reprocess for the given instrument", default=None) - parser.add_option("-m", "--mission", dest="mission", - help="selected mission database", default=None) - - (options, args) = parser.parse_args() - if len(args) != 1: - parser.error("incorrect number of arguments") + parser = argparse.ArgumentParser() + parser.add_argument("-s", "--startDate", type=str, + help="Date to start reprocessing (e.g. 2012-10-02)", default=None) + parser.add_argument("-e", "--endDate", type=str, + help="Date to end reprocessing (e.g. 2012-10-25)", default=None) + parser.add_argument("--force", type=int, + help="Force the reprocessing, specify which version number {0},{1},{2}", default=None) + parser.add_argument("-l", "--level", type=float, + help="The level to reprocess for the given instrument", default=None) + parser.add_argument("-m", "--mission", required=True, + help="selected mission database", default=None) + parser.add_argument('instrument', action='store', + help='Name or ID of instrument.') + + options = parser.parse_args() if options.startDate is not None: startDate = dup.parse(options.startDate) @@ -48,11 +47,11 @@ if options.force not in [None, 0, 1, 2]: parser.error("invalid force option [0,1,2]") - num = db.reprocessByInstrument(args[0], level=options.level, + num = db.reprocessByInstrument(options.instrument, level=options.level, startDate=startDate, endDate=endDate, incVersion=options.force) - print('Added {0} files to be reprocessed for product {1}'.format(num, args[0])) - DBlogging.dblogger.info('Added {0} files to be reprocessed for product {1}'.format(num, args[0])) + print('Added {0} files to be reprocessed for product {1}'.format(num, options.instrument)) + DBlogging.dblogger.info('Added {0} files to be reprocessed for product {1}'.format(num, options.instrument)) diff --git a/scripts/reprocessByProduct.py b/scripts/reprocessByProduct.py index 4935699a..9c9310bf 100755 --- a/scripts/reprocessByProduct.py +++ b/scripts/reprocessByProduct.py @@ -8,9 +8,8 @@ from __future__ import print_function - +import argparse import datetime -from optparse import OptionParser from dateutil import parser as dup from dateutil.relativedelta import relativedelta @@ -21,21 +20,21 @@ if __name__ == "__main__": usage = "%prog [-s yyyymmdd] [-e yyyymmdd] -m product_id [[product_id] ...]" - parser = OptionParser(usage=usage) - parser.add_option("-s", "--startDate", dest="startDate", type="string", + parser = argparse.ArgumentParser() + parser.add_argument("-s", "--startDate", type=str, help="Date to start reprocessing (e.g. 2012-10-02)", default=None) - parser.add_option("-e", "--endDate", dest="endDate", type="string", + parser.add_argument("-e", "--endDate", type=str, help="Date to end reprocessing (e.g. 2012-10-25)", default=None) - parser.add_option("", "--force", dest="force", type="int", + parser.add_argument("--force", type=int, help="Force the reprocessing, specify which version number {0},{1},{2}", default=None) - parser.add_option("-m", "--mission", dest="mission", + parser.add_argument("-m", "--mission", required=True, help="selected mission database", default=None) - parser.add_option("", "--echo", dest="echo", action='store_true', + parser.add_argument("--echo", dest="echo", action='store_true', help="echo sql queries for debugging", default=False) + parser.add_argument('product', action='store', nargs='+', + help='Name or ID of product.') - (options, args) = parser.parse_args() - if len(args) < 1: - parser.error("incorrect number of arguments") + options = parser.parse_args() if options.startDate is not None: startDate = dup.parse(options.startDate) @@ -62,7 +61,7 @@ print(startDate, endDate) - for prod in args: + for prod in options.product: num = db.reprocessByProduct(prod, startDate=startDate, endDate=endDate, incVersion=options.force) if num is None: num = 0 diff --git a/scripts/scrubber.py b/scripts/scrubber.py index 2aee643a..0cd6039c 100644 --- a/scripts/scrubber.py +++ b/scripts/scrubber.py @@ -1,6 +1,6 @@ #!/usr/bin/env python -from optparse import OptionParser +import argparse from dbprocessing import DButils @@ -31,17 +31,16 @@ def version_number_check(self): if __name__ == '__main__': - usage = "usage: %prog -m database" - parser = OptionParser(usage=usage) - parser.add_option( + parser = argparse.ArgumentParser() + parser.add_argument( "-m", "--mission", - dest="mission", + required=True, help="selected mission database", default=None) - (options, args) = parser.parse_args() + options = parser.parse_args() scrubber = scrubber(options.mission) scrubber.parents_are_newest() - scrubber.version_number_check() \ No newline at end of file + scrubber.version_number_check() diff --git a/scripts/testInspector.py b/scripts/testInspector.py index 5b5d5e5b..7f0e601d 100755 --- a/scripts/testInspector.py +++ b/scripts/testInspector.py @@ -1,26 +1,26 @@ #!/usr/bin/env python +import argparse import imp -from optparse import OptionParser from dbprocessing import inspector, DButils from dbprocessing.Utils import strargs_to_args if __name__ == '__main__': usage = "usage: %prog -m mission -i inspector -p product_id -f file [-a args]" - parser = OptionParser(usage=usage) - parser.add_option("-m", "--mission", dest="mission", + parser = argparse.ArgumentParser() + parser.add_argument("-m", "--mission", required=True, help="selected mission database") - parser.add_option("-f", "--file", dest="file", + parser.add_argument("-f", "--file", required=True, help="The file to test the inspector on") - parser.add_option("-i", "--inspector", dest="inspector", + parser.add_argument("-i", "--inspector", required=True, help="The inspector to test") - parser.add_option("-p", "--product", dest="product", + parser.add_argument("-p", "--product", required=True, help="The product the file belongs to") - parser.add_option("-a", "--args", dest="args", + parser.add_argument("-a", "--args", dest="args", help="kwargs to pass to the inspector(optional)", default=None) - (options, args) = parser.parse_args() + options = parser.parse_args() dbu = DButils.DButils(options.mission) @@ -31,4 +31,4 @@ df = inspect.Inspector(options.file, dbu, options.product, **kwargs) else: df = inspect.Inspector(options.file, dbu, options.product, ) - print(df) \ No newline at end of file + print(df) diff --git a/scripts/updateSHAsum.py b/scripts/updateSHAsum.py index 7a852a3f..6633eadd 100755 --- a/scripts/updateSHAsum.py +++ b/scripts/updateSHAsum.py @@ -1,7 +1,7 @@ #!/usr/bin/env python +import argparse import os -from optparse import OptionParser from dbprocessing import DButils @@ -19,16 +19,14 @@ def updateSHA(dbu, filename): if __name__ == '__main__': usage = "usage: %prog infile" - parser = OptionParser(usage=usage) - parser.add_option("-m", "--mission", dest="mission", - help="selected mission database", default=None) - - (options, args) = parser.parse_args() - - if len(args) != 1: - parser.error("incorrect number of arguments") - - infile = os.path.expanduser(os.path.expandvars(args[0])) + parser = argparse.ArgumentParser() + parser.add_argument("-m", "--mission", required=True, + help="selected mission database", default=None) + parser.add_argument('infile', action='store', + help='File to update.') + options = parser.parse_args() + + infile = os.path.expanduser(os.path.expandvars(options.infile)) if not os.path.isfile(infile): parser.error("Input file {0} did not exist".format(infile)) diff --git a/setup.py b/setup.py index 4391004c..e338121d 100644 --- a/setup.py +++ b/setup.py @@ -7,25 +7,19 @@ from distutils.core import setup scripts = ('scripts/addFromConfig.py', 'scripts/missingFilesByProduct.py', - 'scripts/addVerboseProvenance.py', 'scripts/missingFiles.py', + 'scripts/missingFiles.py', 'scripts/clearProcessingFlag.py', 'scripts/possibleProblemDates.py', 'scripts/configFromDB.py', 'scripts/printInfo.py', 'scripts/coveragePlot.py', 'scripts/printProcessQueue.py', 'scripts/CreateDB.py', 'scripts/ProcessQueue.py', - 'scripts/dataToIncoming.py', 'scripts/purgeFileFromDB.py', - 'scripts/dbOnlyFiles.py', 'scripts/QCEmailer_conf.txt', + 'scripts/purgeFileFromDB.py', + 'scripts/dbOnlyFiles.py', 'scripts/DBRunner.py', 'scripts/deleteAllDBFiles.py', 'scripts/reprocessByCode.py', - 'scripts/deleteAllDBProducts.py', 'scripts/reprocessByDate.py', + 'scripts/reprocessByDate.py', 'scripts/flushProcessQueue.py', 'scripts/reprocessByInstrument.py', 'scripts/histogramCodes.py', 'scripts/reprocessByProduct.py', - 'scripts/hopeCoverageHTML.py', 'scripts/updateCode.py', - 'scripts/hope_query.py', 'scripts/updateProducts.py', 'scripts/htmlCoverage.py', 'scripts/updateSHAsum.py', - 'scripts/link_missing_ql_mag_l2_mag.py', 'scripts/weeklyReport.py', - 'scripts/magephem_dataToIncoming.py', 'scripts/writeDBhtml.py', - 'scripts/magephem_def_dataToIncoming.py', 'scripts/writeProcessConf.py', - 'scripts/magephem-pre-CoverageHTML.py', 'scripts/writeProductsConf.py', 'scripts/makeLatestSymlinks.py', 'scripts/testInspector.py', 'scripts/replaceArgsWithRootdir.py', 'scripts/printRequired.py', 'scripts/changeProductDir.py')