-
Notifications
You must be signed in to change notification settings - Fork 2
/
get_site_log.py
executable file
·88 lines (77 loc) · 2.21 KB
/
get_site_log.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/usr/bin/env python
#
# get_site_log.py
#
##BRIEF
# get_site_log.py will look up a sitelog at a given database,
# grab the sitelog and convert it to XML. Both sitelog and
# XML files are stored in a local directory
#
##AUTHOR
# Ronni Grapenthin
#
##DATE
# 2015-05-13
#
##DETAILS
#
##CHANGELOG
#
###########################################################################
import sys, getopt
import util.util as util
site = ''
archive = ''
url = ''
def usage():
print "Usage: get_site_log -s <site-id> [-a <archive> -u <archive-url>]\n\
get_site_log, GPStools\n\n\
Author: rn grapenthin, New Mexico Tech\n\n\
OPTIONS:\n\
-a, --archive\tarchive-id - valid choices: %s.\n\
-h, --help\t\tprint this help\n\
-s, --site\t\t4 character site-id\n\
-u, --url\t\tdatabase url.\n\n\
Report bugs to [email protected]\n\
" % (", ".join(util.databases.keys()))
############# ############# #############
############# MAIN STUFF
############# ############# #############
if __name__ == '__main__':
try:
#":" and "=" indicate that these parameters take arguments! Do not simply delete these!
opts, args = getopt.getopt(sys.argv[1:], "a:hs:u:",["archive=", "help", "site=", "url="])
except getopt.GetoptError as e:
sys.stderr.write("Error: {0} \n\n".format(e.msg))
usage()
sys.exit(2)
##interpret command line
for opt, arg in opts:
#HELP
if opt in ("-h", "--help"):
usage()
sys.exit(2)
#archive
elif opt in ("-a", "--archive"):
archive = arg.lower()
#site
elif opt in ("-s", "--site"):
site = arg.lower()
#url
elif opt in ("-u", "--url"):
url = arg
#unknown
else:
assert False, "unhandled option: `%s'" % opt
##consistency checks
if not site:
sys.stderr.write("\nError: `site' not specified.\n\n" )
usage()
sys.exit(2)
if archive and not url:
if not util.databases.get(archive):
sys.stderr.write("Error: Archive %s not in local database, must provide URL\n" % (archive))
usage()
sys.exit(2)
##invoke util function to do the heavy lifting
util.get_site_log(archive=archive, site=site, url=url)