File indexing completed on 2024-11-26 02:34:35
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 """
0013 Just a draft of the real program...It is very ugly still.
0014 """
0015
0016
0017 from os.path import basename
0018 from optparse import OptionParser
0019 from re import search
0020 from sys import exit
0021 from urllib2 import Request,build_opener,urlopen
0022
0023 import os
0024 if "RELMON_SA" in os.environ:
0025 from authentication import X509CertOpen
0026 from definitions import server
0027 from utils import wget
0028 else:
0029 from Utilities.RelMon.authentication import X509CertOpen
0030 from Utilities.RelMon.definitions import server
0031 from Utilities.RelMon.utils import wget
0032
0033 def extract_list(page_html,the_server,display_url):
0034 contents=[]
0035 for line in page_html.split("<tr><td>")[1:]:
0036 name=""
0037
0038 link_start=line.find("href='")+6
0039 link_end=line.find("'>")
0040
0041 name_start=link_end+2
0042 name_end=line.find("</a>")
0043 if display_url:
0044 contents.append(the_server+line[link_start:link_end])
0045 else:
0046 contents.append(line[name_start:name_end])
0047 return contents
0048
0049 def get_page(url):
0050 """ Get the web page listing the rootfiles. Use the X509 auth.
0051 """
0052 opener=build_opener(X509CertOpen())
0053 datareq = Request(url)
0054 datareq.add_header('authenticated_wget', "The ultimate wgetter")
0055 filename=basename(url)
0056 return opener.open(datareq).read()
0057
0058 if __name__=="__main__":
0059
0060 parser = OptionParser(usage="usage: %prog [options] dirtolist")
0061
0062 parser.add_option("-d","--dev",
0063 action="store_true",
0064 dest="development",
0065 default=False,
0066 help="Select the development GUI instance.")
0067
0068 parser.add_option("--offline",
0069 action="store_true",
0070 dest="offline",
0071 default=False,
0072 help="Select the Offline GUI instance.")
0073
0074 parser.add_option("-o","--online",
0075 action="store_true",
0076 dest="online",
0077 default=False,
0078 help="Select the Online GUI instance.")
0079
0080 parser.add_option("-r","--relval",
0081 action="store_true",
0082 dest="relval",
0083 default=True,
0084 help="Select the RelVal GUI instance.")
0085
0086 parser.add_option("-u","--show_url",
0087 action="store_true",
0088 dest="show_url",
0089 default=False,
0090 help="Show the full URL of the file.")
0091
0092 parser.add_option("-g","--get",
0093 action="store_true",
0094 dest="get",
0095 default=False,
0096 help="Get the files.")
0097
0098 parser.add_option("-p","--path",
0099 action="store",
0100 dest="path",
0101 default="",
0102 help="The path to be matched before getting.")
0103
0104 (options, args) = parser.parse_args()
0105
0106 if not(options.development or options.offline or options.online or options.relval):
0107 print("Select development or online instance!")
0108 exit(-1)
0109
0110 lenargs=len(args)
0111 if lenargs>1:
0112 print("Please specify only one directory to list!")
0113 exit(-1)
0114
0115 dirtolist=""
0116 if lenargs==1:
0117 dirtolist=args[0]
0118
0119 mode="relval"
0120 if options.online:
0121 mode="online"
0122 if options.development:
0123 mode="dev"
0124
0125
0126 directory="%s/dqm/%s/data/browse/%s" %(server,mode,dirtolist)
0127 print("peeping ",directory)
0128 contents=extract_list(get_page(directory),server,options.show_url)
0129
0130 if len(contents)==0:
0131 print("No contents found!")
0132
0133 for content in contents:
0134 if not options.get and search(options.path,content):
0135 print(content)
0136 if options.get and options.show_url and len(options.path)>0 and search(options.path,content):
0137 if not search('pre',options.path) and search('pre',content):
0138 continue
0139 bcontent=basename(content)
0140 print("Getting %s" %bcontent)
0141 wget(content)
0142 print("Got %s!!" %bcontent)
0143
0144