self.conn.commit()
-def usage():
- """Print help text."""
-
- print("""
-USAGE:
- {0} -d FILE [OPTIONS]
- {0} -h
-
-OPTIONS:
- -a PATH Read webservers response and add data to the database. If PATH is
- "-" then read from stdin. If PATH is a file, read from file. If
- file ends with ".gz" then transparently decompress it. If PATH is
- a directory, read all files ending with ".html" or ".html.gz".
- -d FILE Use given sqlite3 database.
- -h Print this help text.
- -q COND Query for datasets where the given WHERE SQL-condition holds.
-""")
-
-
def printDataset(db, id):
"""Print info for a dataset of given ID."""
db.add_purpose(id, num, purpose, date, status)
+def usage():
+ """Print help text."""
+
+ print("""
+USAGE:
+ {0} [OPTIONS] COMMAND [ARGS...]
+ {0} -d FILE -a PATH [PATH...]
+ {0} -d FILE -q COND -l
+ {0} -h
+
+COMMAND:
+ -a Read webservers response and add data to the database. If PATH is
+ "-" then read from stdin. If PATH is a file, read from file. If
+ file ends with ".gz" then transparently decompress it. If PATH is
+ a directory, read all files ending with ".html" or ".html.gz".
+ -h Print this help text.
+ -l List the selected datasets.
+
+OPTIONS:
+ -d FILE Use given sqlite3 database.
+ -q COND Use this WHERE SQL-condition to select some datasets.
+""")
+
+
if __name__ == "__main__":
- add = None
dbfn = None
query = None
+ cmd = None
try:
- opts, args = getopt.getopt(sys.argv[1:], "a:d:hq:")
+ opts, args = getopt.getopt(sys.argv[1:], "ad:hq:l")
for opt, arg in opts:
- if opt == "-a":
- add = arg
+ if opt in ["-a", "-l"]:
+ cmd = opt
elif opt == "-d":
dbfn = arg
elif opt == "-h":
usage()
sys.exit(os.EX_USAGE)
+ if cmd is None:
+ print("No command given.", file=sys.stderr)
+ sys.exit(os.EX_USAGE)
+
if dbfn is None:
print("No database given.", file=sys.stderr)
sys.exit(os.EX_USAGE)
db = Database(dbfn)
- if add is not None:
- processAdd(db, add)
+ if cmd == "-a":
+ for arg in args:
+ processAdd(db, arg)
- if query is not None:
- success = processQuery(db, query)
- if not success:
- sys.exit(1)
+ if cmd == "-l":
+ if query is None:
+ print("No query option given.", file=sys.stderr)
+ sys.exit(os.EX_USAGE)
+ processQuery(db, query)
sys.exit(os.EX_OK)