00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 """
00016 Just a draft of the real program...It is very ugly still.
00017 """
00018
00019
00020 from os.path import basename
00021 from optparse import OptionParser
00022 from re import search
00023 from sys import exit
00024 from urllib2 import Request,build_opener,urlopen
00025
00026 import os
00027 if os.environ.has_key("RELMON_SA"):
00028 from authentication import X509CertOpen
00029 from definitions import server
00030 from utils import wget
00031 else:
00032 from Utilities.RelMon.authentication import X509CertOpen
00033 from Utilities.RelMon.definitions import server
00034 from Utilities.RelMon.utils import wget
00035
00036 def extract_list(page_html,the_server,display_url):
00037 contents=[]
00038 for line in page_html.split("<tr><td>")[1:]:
00039 name=""
00040
00041 link_start=line.find("href='")+6
00042 link_end=line.find("'>")
00043
00044 name_start=link_end+2
00045 name_end=line.find("</a>")
00046 if display_url:
00047 contents.append(the_server+line[link_start:link_end])
00048 else:
00049 contents.append(line[name_start:name_end])
00050 return contents
00051
00052 def get_page(url):
00053 """ Get the web page listing the rootfiles. Use the X509 auth.
00054 """
00055 opener=build_opener(X509CertOpen())
00056 datareq = Request(url)
00057 datareq.add_header('authenticated_wget', "The ultimate wgetter")
00058 filename=basename(url)
00059 return opener.open(datareq).read()
00060
00061 if __name__=="__main__":
00062
00063 parser = OptionParser(usage="usage: %prog [options] dirtolist")
00064
00065 parser.add_option("-d","--dev",
00066 action="store_true",
00067 dest="development",
00068 default=False,
00069 help="Select the development GUI instance.")
00070
00071 parser.add_option("--offline",
00072 action="store_true",
00073 dest="offline",
00074 default=False,
00075 help="Select the Offline GUI instance.")
00076
00077 parser.add_option("-o","--online",
00078 action="store_true",
00079 dest="online",
00080 default=False,
00081 help="Select the Online GUI instance.")
00082
00083 parser.add_option("-r","--relval",
00084 action="store_true",
00085 dest="relval",
00086 default=True,
00087 help="Select the RelVal GUI instance.")
00088
00089 parser.add_option("-u","--show_url",
00090 action="store_true",
00091 dest="show_url",
00092 default=False,
00093 help="Show the full URL of the file.")
00094
00095 parser.add_option("-g","--get",
00096 action="store_true",
00097 dest="get",
00098 default=False,
00099 help="Get the files.")
00100
00101 parser.add_option("-p","--path",
00102 action="store",
00103 dest="path",
00104 default="",
00105 help="The path to be matched before getting.")
00106
00107 (options, args) = parser.parse_args()
00108
00109 if not(options.development or options.offline or options.online or options.relval):
00110 print "Select development or online instance!"
00111 exit(-1)
00112
00113 lenargs=len(args)
00114 if lenargs>1:
00115 print "Please specify only one directory to list!"
00116 exit(-1)
00117
00118 dirtolist=""
00119 if lenargs==1:
00120 dirtolist=args[0]
00121
00122 mode="relval"
00123 if options.online:
00124 mode="online"
00125 if options.development:
00126 mode="dev"
00127
00128
00129 directory="%s/dqm/%s/data/browse/%s" %(server,mode,dirtolist)
00130 print "peeping ",directory
00131 contents=extract_list(get_page(directory),server,options.show_url)
00132
00133 if len(contents)==0:
00134 print "No contents found!"
00135
00136 for content in contents:
00137 if not options.get and search(options.path,content):
00138 print content
00139 if options.get and options.show_url and len(options.path)>0 and search(options.path,content):
00140 if not search('pre',options.path) and search('pre',content):
00141 continue
00142 bcontent=basename(content)
00143 print "Getting %s" %bcontent
00144 wget(content)
00145 print "Got %s!!" %bcontent
00146
00147