def __init__(self): self.closed = False self.command = str() self.args = defaultdict(list) self.command_history = list() self.valid_commands = {} self.valid_commands["init"] = Init() self.valid_commands["push"] = Push() self.valid_commands["pull"] = Pull() self.valid_commands["config"] = Config() self.valid_commands["dir"] = Dir() self.valid_commands["purgue"] = Purgue()
def check_empty(dirobj, dirid, delete_sql): empty = True #look for file records to delete c.execute( 'select id, name from files where parentid = ? and size is not null and size > 1', (dirid, )) filerows = c.fetchall() for filerow in filerows: fileid = filerow[0] #build path filepath = dirobj.path + filerow[1] #if file exists if (not os.path.exists(filepath)): #append delete file sql print('file missing', fileid, filepath) delete_sql.append('delete from files where id = ' + str(fileid)) else: empty = False #look for frame records to delete c.execute('select id, name from frame where parentid = ?', (dirid, )) framerows = c.fetchall() for framerow in framerows: frameid = framerow[0] #build path framepath = dirobj.path + framerow[1] #if frame exists if (not os.path.exists(framepath)): print('frame missing', frameid, framepath) #append delete frame sql delete_sql.append('delete from frame where id = ' + str(frameid)) else: empty = False #look for empty subdirs c.execute('select id, name from directory where parent = ?', (dirid, )) subdirrows = c.fetchall() for subdirrow in subdirrows: subdirid = subdirrow[0] subdirobj = Dir(dirobj.path + subdirrow[1]) if (not check_empty(subdirobj, subdirid, delete_sql)): empty = False if (empty): if (not os.path.exists(dirobj.path)): print('dir missing', dirid, dirobj.path) else: print('dir unused', dirid, dirobj.path) delete_sql.append('delete from directory where id = ' + str(dirid)) return empty
def save_all_photos(self): gabp = GetAllBlogPages(self.url) while self.i < len(gabp.get_all_pages()): print('====================正在保存第', self.i + 1, '页=============================') page_url = gabp.get_all_pages()[self.i] opbl = OnePageBlogLink(page_url) blog_page_urls = opbl.get_blog_page_urls() # 保存一个页面上的所有blog链接到的图片 for blog_page_url_num in range(0, len(blog_page_urls)): Dir().ch_dir(self.path) Dir().make_dir( opbl.get_blog_page_contents()[1][blog_page_url_num][0]) new_path = os.path.join( self.path, opbl.get_blog_page_contents()[1][blog_page_url_num][0]) Dir().ch_dir(new_path) photo_urls = gbpl( blog_page_urls[blog_page_url_num]).get_photo_urls() sp().save_one_page_photos(photo_urls) self.i += 1
def browse_repo(self, rel=None): """Browse remote repo function.""" self.c.screen.clear() self.base_status("browse loading...", text_only=True) _directory = Dir(self._client) files = _directory.list(rel) if files is None: msg = os.path.join(self._base, rel) + " - Not under version control." logger.warning(msg) self.base_status(msg, text_only=True) self.history = self.history[:-1] else: self.base_status(os.path.join(self._base, rel if rel else '')) self.c.print_remote_files(files)
def get_dir_from_id(dirid): dirobj = None #recursive cte to fetch all parent dirs #print('recursing with:', dirid) c.execute( 'with parents(id, name, parent) as (select par.id, par.name, par.parent from directory par where par.id = ? union all select child.id, child.name, child.parent from directory child inner join parents par on par.parent = child.id) select id, name from parents', (dirid, )) rows = c.fetchall() if (len(rows) > 0): dirpath = '' for r in rows: #print('row', r, r[1]) dirpath = str(r[1]) + os.sep + dirpath dirpath = os.sep + 'media' + os.sep + dirpath #print(dirpath) dirobj = Dir(dirpath) return dirobj
def get_un_use_code_files(a_project_path, a_zh_un_check_enable): c__dir = Dir(a_project_path) c_files = c__dir.files() h_files = [] check_files = [] for c_file in c_files: match = False if a_zh_un_check_enable: match = zhPattern.search(unicode(c_file.name)) not_system_file = ('xcodeproj' not in c_file.name) and ('xcworkspace' not in c_file.name) not_node_module = 'node_modules' not in c_file.path if 'Pod' not in c_file.path and ( not match) and not_system_file and not_node_module: is_png = 'png' == c_file.get_extension() is_jpg = 'jpg' == c_file.get_extension() if not (is_jpg or is_png): check_files.append(c_file) # 过滤pod if 'h' == c_file.get_extension(): h_files.append(c_file) i = 0 progress_index = 0 total = len(h_files) print("Total \'.h\' Files Count:%d" % total) while i < len(h_files): progress_index += 1 progress.show_progress(progress_index, total) h_file = h_files[i] contain = has_code_file_contain(h_file, check_files) if contain: i -= 1 h_files.remove(h_file) i += 1 return h_files
def __init__(self, vim): self.vim = vim self._client = Client(debug_fn=self.log, log_fn=self.log) self.files = Dir() self._last_input_reload = time() self.cwd = os.getcwd()
def get_un_use_images(a_project_path, a_zh_un_check_enable, image_analyse_check_as_line=False): c__dir = Dir(a_project_path) c_files = c__dir.files() img_files = [] check_files = [] for c_file in c_files: match = False if a_zh_un_check_enable: match = zhPattern.search(unicode(c_file.name)) not_system_file = ('xcodeproj' not in c_file.name) and ('xcworkspace' not in c_file.name) not_node_module = 'node_modules' not in c_file.path if 'Pod' not in c_file.path and ( not match) and not_system_file and not_node_module: is_png = 'png' == c_file.get_extension() is_jpg = 'jpg' == c_file.get_extension() if is_png or is_jpg: is_app_icon = 'AppIcon' in c_file.path is_launch = 'LaunchImage' in c_file.path if not (is_app_icon or is_launch): img_files.append(c_file) else: check_files.append(c_file) i = 0 progress_index = 0 count = len(img_files) print("Total Image Files Count: %d" % len(check_files)) while i < len(img_files): progress_index += 1 progress.show_progress(progress_index, count) # 逐文件排查 img_file = img_files[i] contain = False if not isinstance(img_file, File): contain = True else: image_name = img_file.name.partition('.')[0] if "@2x" in image_name or "@3x" in image_name: image_name = image_name.partition('@')[0] for check_file in check_files: if 'js' == check_file.get_extension(): simple_contain_str = img_file.name if "@2x" in simple_contain_str: simple_contain_str = simple_contain_str.replace( "@2x", "") if "@3x" in simple_contain_str: simple_contain_str = simple_contain_str.replace( "@3x", "") contain = check_file.has_contain( simple_contain_str, image_analyse_check_as_line) if contain: break # Json 内部查找,并且过滤到 .xcassets 内的 Content.json 的配置文件 if 'json' in check_file.name and 'Content' not in check_file.name: # 查找 json 串 "image_name" simple_contain_str = "\"" + image_name + "\"" contain = check_file.has_contain( simple_contain_str, image_analyse_check_as_line) if contain: break # 查找json 串:\"image_name\" simple_contain_str = "\\\"" + image_name + "\\\"" contain = check_file.has_contain( simple_contain_str, image_analyse_check_as_line) if contain: break else: # 查找 @"image_name" contain_str = "@\"" + image_name + "\"" contain = check_file.has_contain( contain_str, image_analyse_check_as_line) if contain: break if contain: img_files.remove(img_file) else: i += 1 return img_files
def process_dir(dirobj, parentid): print(indent(dirobj.depth, ' ') + '/' + dirobj.name) log = { 'name': dirobj.name, 'files': [], 'dirs': [], 'warnings': [], 'errors': [] } if (not os.path.exists(dirobj.path)): log['errors'].append('dir must exist') return log if (dirobj.parent == None): log['errors'].append('dir must have parent') return log #conditionally process mask dir if (is_mask_dir(dirobj)): return process_mask_dir(dirobj) if (parentid == None and dirobj.parent.name != MOUNT_ROOT): parentid = get_parent_id(dirobj) if (parentid == None): log['errors'].append('dir must have parent id') return log log['parentid'] = parentid dirid = get_dir_id(dirobj.name, parentid) #if no dirid then create dir if (dirid == None): log['db'] = 'INSERT' c.execute('insert into directory (parent, name) values (?, ?)', (parentid, dirobj.name)) dirid = c.lastrowid log['id'] = dirid #process frames or files first if (dirobj.parent.name == 'frames' or dirobj.parent.name == 'thumbs'): process_frames(dirobj, dirid, log) else: log['files'] = process_files(dirobj, dirid) subdirnames = [] for subdirname in os.listdir(dirobj.path): if (os.path.isdir(dirobj.path + subdirname) and not subdirname in EXCLUDED_DIRS): subdirnames.append(subdirname) subdirnames = sorted(subdirnames, key=lambda s: s.lower().translate(STRIP_PUNC)) #process subdirs for subdirname in subdirnames: subdir = Dir(dirobj.path + subdirname) logsubdir = process_dir(subdir, dirid) log['dirs'].append(logsubdir) return log
help="skip frame processing if frame dir exists", action="store_true") parser.add_argument( '-d', '--delete_sql', help= "look for empty dirs and generate delete sql (not compatible with -n)", action="store_true") parser.add_argument('-c', '--copy_log', help="copy log to logviewer", action="store_true") args = parser.parse_args() try: startdirobj = Dir(args.startdir) except IndexError: sys.exit('Not a valid directory name (must start with a /)') print('startdir =', startdirobj.path) print('startdepth =', startdirobj.depth) conn = sqlite3.connect(SQLITE3_DB_PATH) c = conn.cursor() if (args.startparentid != None): startparentid = args.startparentid else: startparentid = get_parent_id(startdirobj) print('startparentid =', startparentid)