Logo Search packages:      
Sourcecode: harvestman version File versions  Download package

def HarvestMan::config::HarvestManStateObject::parse_arguments (   self  ) 

Parse the command line arguments 

Definition at line 586 of file config.py.

00586                              :
        """ Parse the command line arguments """

        # This function has 3 return values
        # -1 => no cmd line arguments/invalid cmd line arguments
        # ,so force program to read config file.
        # 0 => existing project file supplied in cmd line
        # 1 => all options correctly read from cmd line

        # if no cmd line arguments, then use config file,
        # return -1
        if len(sys.argv)==1:
            return -1

        # Otherwise parse the arguments, the command line arguments
        # are the same as the variables(dictionary keys) of this class.
        # Description
        # Options needing no arguments
        #
        # -h => prints help
        # -v => prints version info

        soptions = 'hvNp:c:b:C:P:V:t:f:l:w:r:n:d:T:R:u:Y:U:W:s:V:M:S:'
        longoptions = [ "configfile=", "projectfile=",
                        "project=", "help","nocrawl",
                        "version", "basedir=",
                        "verbosity=", "depth=","urlfilter=",
                        "maxthreads=","maxfiles=","timelimit=",
                        "retry=","connections=","subbdomain=",
                        "localize=","fetchlevel=","proxy=",
                        "proxyuser=","proxypass=","urlserver=",
                        "cache=","urlslist=","urltree="
                        ]

        arguments = sys.argv[1:]
        try:
            optlist, args = getopt.getopt(arguments, soptions, longoptions)
        except getopt.GetoptError, e:
            sys.exit('Error: ' + str(e))

        if args:
            self.set_option_xml('url',self.process_value(args[0]))
            args.pop(0)
            for idx in range(0,len(args),2):
                item, value = args[idx], args[idx+1]
                optlist.append((item,value))

        # print optlist
        
        for option, value in optlist:
            # first parse arguments with no options
            if option in ('-h', '--help'):
                self.print_help()
                sys.exit(0)
            elif option in ('-v', '--version'):
                self.print_version_info()
                sys.exit(0)
            elif option in ('-C', '--configfile'):
                if self.check_value(value):
                    self.set_option('files.configfile', self.process_value(value))
                    # No need to parse further values
                    return -1
            elif option in ('-P', '--projectfile'):
                if self.check_value(value):
                    self.set_option('files.projectfile', self.process_value(value))
                    import utils 

                    projector = utils.HarvestManProjectManager()

                    if projector.read_project() == 0:
                        # No need to parse further values
                        return 0

            elif option in ('-b', '--basedir'):
                if self.check_value(value): self.set_option_xml('basedir', self.process_value(value))
            elif option in ('-p', '--project'):
                if self.check_value(value): self.set_option_xml('name', self.process_value(value))
            elif option in ('-r', '--retry'):
                if self.check_value(value): self.set_option_xml('retries_value', self.process_value(value))
            elif option in ('-l', '--localize'):
                if self.check_value(value): self.set_option_xml('localise_value', self.process_value(value))
            elif option in ('--f', '--fetchlevel'):
                if self.check_value(value): self.set_option_xml('fetchlevel_value', self.process_value(value))
            elif option in ('-T', '--maxthreads'):
                if self.check_value(value): self.set_option_xml('trackers_value', self.process_value(value))
            elif option in ('-M', '--maxfiles'):
                if self.check_value(value): self.set_option_xml('maxfiles_value', self.process_value(value))
            elif option in ('-t', '--timelimit'):
                if self.check_value(value): self.set_option_xml('timelimit_value', self.process_value(value))
            elif option in ('-w','--workers'):
                self.set_option_xml('workers_status',1)
                if self.check_value(value): self.set_option_xml('workers_size', self.process_value(value))                
            elif option in ('-u', '--urlfilter'):
                if self.check_value(value): self.set_option_xml('urlfilter', self.process_value(value))
            elif option in ('-d', '--depth'):
                if self.check_value(value): self.set_option_xml('depth_value', self.process_value(value))
            elif option in ('-R', '--robots'):
                if self.check_value(value): self.set_option_xml('robots_value', self.process_value(value))
            elif option in ('--urllistfile'):
                if self.check_value(value): self.set_option_xml('urllistfile', self.process_value(value))
            elif option in ('--urltreefile'):
                if self.check_value(value): self.set_option_xml('urltreefile', self.process_value(value))
            elif option in ('-N','--nocrawl'):
                self.nocrawl = True
            elif option in ('-Y', '--proxy'):
                if self.check_value(value):
                    # Set proxyencrypted flat to False
                    self.proxyenc=False
                    self.set_option_xml('proxyserver', self.process_value(value))
            elif option in ('-U', '--proxyuser'):
                if self.check_value(value): self.set_option_xml('proxyuser', self.process_value(value))                
            elif option in ('-W', '--proxypass'):
                if self.check_value(value): self.set_option_xml('proxypasswd', self.process_value(value))
            elif option in ('-s', '--urlserver'):
                if self.check_value(value): self.set_option_xml('urlserver_status', self.process_value(value))
            elif option in ('-S', '--subdomain'):
                if self.check_value(value): self.set_option_xml('subdomain_value', self.process_value(value))                
                
            elif option in ('-c', '--cache'):
                if self.check_value(value): self.set_option_xml('cache_status', self.process_value(value))
            elif option in ('-n', '--connections'):
                if self.check_value(value): self.set_option_xml('connections_value', self.process_value(value))
            elif option in ('-V','--verbosity'):
                if self.check_value(value): self.set_option_xml('verbosity_value', self.process_value(value))
            else:
                print 'Ignoring invalid option ', option

        if self.nocrawl:
            self.pagecache = False
            self.rawsave = True
            self.localise = 0
            # Set project name to ''
            self.set_option_xml('name','')
            # Set basedir to dot
            self.set_option_xml('basedir','.')
            
        # Error in option value
        if self._error:
            print self._error, value
            return -1

        return 1


Generated by  Doxygen 1.6.0   Back to index