def __init__(self): usage = "usage: %prog [options] arg" self.parser = OptionParser(usage) self.parser.add_option("-u", "--url", action="store", \ type="string", dest="url", help="URL input") self.parser.add_option("-r", "--regexp", action="store", \ type="string", dest="regexp", \ help="add a regular expression keyword to operate with in searching. Use expression with quotes. \ Example: --regexp=\"public(ation)?s?\"") self.parser.add_option("-q", "--quiet", action="store_true", \ dest="quiet", default=False, help="don't print result. Often used in combination with -v/-d") self.parser.add_option("-v", "--verbose", action="store_true", \ dest="verbose", default=False, help="print status messages to stdout") self.parser.add_option("-p", "--page", action="store_true", \ dest="page", default=False, help="use this option when deliverable page url entered \ (in option --url=deliverable_page) to search for files and descriptions only.") self.parser.add_option("-f", "--file", dest="readfile", \ help="read URLs from FILE", metavar="FILE") self.parser.add_option("-s", "--store", action="store_true", \ dest="storefile", default=False, help="store XML to file. Format of filename: input.url.adress.xml") self.parser.add_option("-d","--debug",action="store_true",\ default=False,help="print debug messages") (self.options, self.args) = self.parser.parse_args() # Verify input options and data ######################################################### # check input if not self.options.url and not self.options.readfile: self.parser.error("no input specified.") elif self.options.url and self.options.readfile: self.parser.error("options -f and -u are mutually exclusive.") elif self.options.quiet and self.options.storefile: self.parser.error("options -q and -s are mutually exclusive.") # check url if self.options.url: if not is_url_valid(self.options.url): self.parser.error("wrong URL format.") else: if not os.path.isfile(self.options.readfile): self.parser.error("input file doesn't exist.") # check added keyword (RE) if self.options.regexp != None: try: re.search(self.options.regexp, "deliverables") except: self.parser.error("Bad keyword format. Has to be python-like RE with quotes.") # check internet connection if not os.popen("ping www.google.com -c 2"): self.parser.error("Internet connection failed.")
def __init__(self): usage = "usage: %prog [options] arg" self.parser = OptionParser(usage) self.parser.add_option("-u", "--url", action="store", \ type="string", dest="url", help="URL input") self.parser.add_option("-r", "--regexp", action="store", \ type="string", dest="regexp", \ help="add a regular expression keyword to operate with in searching. Use expression with quotes. \ Example: --regexp=\"public(ation)?s?\"" ) self.parser.add_option("-q", "--quiet", action="store_true", \ dest="quiet", default=False, help="don't print result. Often used in combination with -v/-d") self.parser.add_option("-v", "--verbose", action="store_true", \ dest="verbose", default=False, help="print status messages to stdout") self.parser.add_option("-p", "--page", action="store_true", \ dest="page", default=False, help="use this option when deliverable page url entered \ (in option --url=deliverable_page) to search for files and descriptions only." ) self.parser.add_option("-f", "--file", dest="readfile", \ help="read URLs from FILE", metavar="FILE") self.parser.add_option("-s", "--store", action="store_true", \ dest="storefile", default=False, help="store XML to file. Format of filename: input.url.adress.xml") self.parser.add_option("-d","--debug",action="store_true",\ default=False,help="print debug messages") (self.options, self.args) = self.parser.parse_args() # Verify input options and data ######################################################### # check input if not self.options.url and not self.options.readfile: self.parser.error("no input specified.") elif self.options.url and self.options.readfile: self.parser.error("options -f and -u are mutually exclusive.") elif self.options.quiet and self.options.storefile: self.parser.error("options -q and -s are mutually exclusive.") # check url if self.options.url: if not is_url_valid(self.options.url): self.parser.error("wrong URL format.") else: if not os.path.isfile(self.options.readfile): self.parser.error("input file doesn't exist.") # check added keyword (RE) if self.options.regexp != None: try: re.search(self.options.regexp, "deliverables") except: self.parser.error( "Bad keyword format. Has to be python-like RE with quotes." ) # check internet connection if not os.popen("ping www.google.com -c 2"): self.parser.error("Internet connection failed.")
# End of class Deliverables if __name__ == '__main__': optPars = OptHandler() options = optPars.getOptions() deliv = Deliverables(options) if options.readfile: #process link from a file print("Processing links from file") f = open(deliv.opt.readfile) link = True while link: try: link = f.readline().strip() if not is_url_valid(link): print("Not valid link: " + link) continue print("Start processing: " + link) deliv = Deliverables(options,link) res = deliv.main() #print("Deliv page: "+"".join(deliv.links)) if type(res)!=RRSProject: #doslo k chybe print res[1] except Exception as e: print "Error" + str(e) f.close() else: res = deliv.main()
# End of class Deliverables if __name__ == '__main__': optPars = OptHandler() options = optPars.getOptions() deliv = Deliverables(options) if options.readfile: #process link from a file print("Processing links from file") f = open(deliv.opt.readfile) link = True while link: try: link = f.readline().strip() if not is_url_valid(link): print("Not valid link: " + link) continue print("Start processing: " + link) deliv = Deliverables(options, link) res = deliv.main() #print("Deliv page: "+"".join(deliv.links)) if type(res) != RRSProject: #doslo k chybe print res[1] except Exception as e: print "Error" + str(e) f.close() else: res = deliv.main()