def get_face_image(): fid = None sid = None args = get_input_args('hf:s:') for k in args.keys(): if k == '-f': fid = get_abs_path(args['-f']) elif k == '-s': sid = get_abs_path(args['-s']) elif k == '-h': print_help(HELP_MENU) return fid, sid
def process_input_args(self, opts, args=None): if args: for k in args.keys(): if k == '-u': if os.path.isfile(args['-u']): self._url_file = get_abs_path(args['-u']) else: self._url = re.sub('/$', '', args['-u']) elif k == '-x': self._xval = args['-x'] elif k == '-d': self._pr.add_level(PR_LVL_DBG) self._pr.set_funcname(True) elif k == '-y': self._byname = args['-y'] elif k == '-h': print_help(self.HELP_MENU) # get url_base from xval if self._xval: self._url_base, self._class = \ XBaseClass.get_base_class_from_xval(self._xval) if not all((self._url_base, self._class)): print_exit('[WebImageCrawler] Error, invalid -x val!') # get class from url if all((self._url, not self._class)): base, num = get_url_base_and_num(self._url) if base: self._class = XBaseClass.get_class_from_base(base) else: self._class = XBaseClass.get_class_from_url(self._url) # get class from url_base if all((not self._class, self._url_base)): self._class = XBaseClass.get_class_from_base(self._url_base) return args
def process_input(self, opts, args=None): if args: for k in args.keys(): if k == '-v': self._pr.add_level(PR_LVL_ALL) elif k == '-o': self._order = True elif k == '-r': self._recursion_path = True elif k == '-l': self._local_path = get_abs_path(args['-l']) elif k == '-y': self._remote_path = args['-y'] elif k == '-m': mode = args['-m'].lower() if mode in self.UPLOAD_MODES: self._upload_mode = self.UPLOAD_MODES[mode] elif k == '-c': self._cmd = args['-c'].lower() elif k == '-f': self._ftype = args['-f'] elif k == '-x': self._xftype = args['-x'] elif k == '-h': print_help(self.HELP_MENU) return args
def process_input(self, opts, args=None): if args: for k in args.keys(): if k == '-s': self._src = re.sub('/$', '', args['-s']) elif k == '-t': self._tgt = get_abs_path(args['-t']) elif k == '-h': print_help(self.HELP_MENU) return args
def get_input(self): args = get_input_args('hs:t:v') for k in args.keys(): # src path if k == '-s': self._src = get_abs_path(args['-s']) # dst path elif k == '-t': self._dst = get_abs_path(args['-t']) # show elif k == '-v': self._show = True elif k == '-h': print_help(self.HELP_MENU) # start to check args. # start id is must be set, otherwise return.. if not self._src: return False # next to start if _end is not set. if not self._dst: self._dst = get_current_path() print('warnning: no found -t, output to: %s' % self._dst) return True
def get_user_opt(self): args = get_input_args('hcf:r:s:t:') for k in args.keys(): if k == r'-h': print_help(self.HELP_MENU) elif k == r'-c': self._combine_files = True elif k == r'-f': fmt = args['-f'].lower() if fmt == TYPE_TXT or fmt == TYPE_CSV: self._fmt = fmt else: print_exit("Error, unsupport format!") elif k == r'-r': if args['-r'] == r'True': self._sort_reverse = True else: self._sort_reverse = False elif k == r'-s': # set _src to list if self._src is None: self._src = list() # get src files fs = self.get_src_files(get_abs_path(args['-s'])) if fs: # add fs to _src for f in fs: self._src.append(f) elif k == r'-t': ftype = get_filetype(get_abs_path(args['-t'])) if ftype in [TYPE_TXT, TYPE_CSV]: self._tgt = get_abs_path(args['-t']) self._combine_files = True self._fmt = ftype else: self._tgt = get_abs_path(args['-t'])
) pr = PyPrint('PyFile') args = get_input_args('hr:f:s:c:m:', True) for k in args.keys(): if k == '-r': remove_small_file(args['-r']) elif k == '-f': values = args['-f'].split(',') n = len(values) if n < 2: print_exit('input error, -h for help') elif any((not values[0], not values[1])): print_exit('input error, -h for help') # get args. path = get_abs_path(values[0]) wd = values[1] if n == 2: result = find(path, wd) elif n > 2: ftype = values[2] result = find(path, wd, ftype) # print result for key, values in result.iteritems(): pr.pr_info(key) for val in values: pr.pr_info(val) elif k == '-s': values = args['-s'].split(',') n = len(values) if n < 3:
def process_input(self, opts, args=None): if args: for k in args.keys(): if k == '-u': self._url = re.sub('/$', '', args['-u']) elif k == '-n': self._num = int(args['-n']) elif k == '-p': self._path = get_abs_path(args['-p']) elif k == '-R': self._ex_re_image_url = get_abs_path(args['-R']) elif k == '-t': try: n = int(args['-t']) except ValueError as e: print_exit('%s, -h for help!' % str(e)) if n: self._thread_max = n elif k == '-v': self._view = True elif k == '-x': self._xval = args['-x'] elif k == '-m': dl_image_funcs = { 'wget': self.wget_url_image, 'rtrv': self.retrieve_url_image, 'rget': self.requests_get_url_image, 'uget': self.urlopen_get_url_image, } if args['-m'] in dl_image_funcs.keys(): self._dl_image = dl_image_funcs[args['-m']] elif k == '-d': try: self.__dbg = int(args['-d']) except ValueError as e: self._pr.pr_err(str(e)) else: self._pr.add_level(PR_LVL_DBG) self._pr.set_funcname(True) if self.__dbg >= 0x02: WebContent.pr.add_level(PR_LVL_DBG) WebContent.pr.set_funcname(True) else: WebContent.pr.clear_level(PR_LVL_DBG) WebContent.pr.set_funcname(False) elif k == '-h': print_help(self.HELP_MENU) # check url if self._url: base, num = get_url_base_and_num(self._url) if base: self._url_base = base if num: self._url = num self._pr.pr_dbg('get base: %s, url: %s' % (base, self._url)) else: print_exit('[WebImage] Error, no set url, -h for help!') if self._url_base: pattern = re.compile('http[s]?://.+\.(com|cn|net)') if isinstance(self._url_base, list): for base in self._url_base: www_com = pattern.match(base) else: www_com = pattern.match(self._url_base) if www_com: self._com = www_com.group() return args
' -R path: reclaim image format', ' path: path of dir or file', ' -o path,rename,nz: rename image to order', ' path : path of images', ' rename: the format of image to be rename', ' nz : True is set %0d, False is set %d', ' -i img: show detail info of image file', ' img: the path of image file.', ) Img = PyImage() xval = None args = get_input_args('hc:r:R:x:o:i:') for k in args.keys(): if k == '-c': result = Img.image_file(get_abs_path(args['-c'])) print(result) elif k == '-r': data = args['-r'].split(',') path = data[0] if len(data) >= 3: w = data[1] h = data[2] Img.remove_small_image(path, int(w), int(h)) else: Img.remove_small_image(path) elif k == '-R': path = args['-R'] if Img.image_file(path): Img.reclaim_image(path) else:
df = None view = False args = get_input_args('hp:u:d:v') for k in args.keys(): if k == '-u': url = args['-u'] elif k == '-v': view = True wc.pr.level = PR_LVL_ALL elif k == '-d': df_funcs = { 'wget': wc.wget_url_file, 'rtrv': wc.retrieve_url_file, 'rget': wc.requests_get_url_file, 'uget': wc.urlopen_get_url_file, 'html': wc.get_url_content, } w = args[k] if w in df_funcs: df = df_funcs[w] else: print_exit('-d %s error, -h for help!' % args['-d']) elif k == '-p': path = get_abs_path(args['-p']) elif k == '-h': print_help(HELP_MENU) # run cmd if all((df, url)): df(url=url, path=path, view=view)