def find_all_in_dir(self, parent_it, dir_path, file_pattern, search_pattern, options, replace_flg = False): if search_pattern == "": return d_list = [] f_list = [] path_list = [] for root, dirs, files in os.walk(unicode(dir_path, 'utf-8')): for d in dirs: d_list.append(os.path.join(root, d)) for f in files: f_list.append(os.path.join(root, f)) if options['INCLUDE_SUBFOLDER'] == True: path_list = f_list else: for f in f_list: if os.path.dirname(f) not in d_list: path_list.append(f) for file_path in path_list: if fnmatch.fnmatch(file_path, unicode(file_pattern, 'utf-8')): if os.path.isfile(file_path): #print file_path pipe = subprocess.PIPE p1 = subprocess.Popen(["file", "-i", file_path], stdout=pipe) p2 = subprocess.Popen(["grep", "text"], stdin=p1.stdout, stdout=pipe) output = p2.communicate()[0] if output: temp_doc = gedit.Document() file_uri = "file://" + urllib.pathname2url(file_path.encode('utf-8')) temp_doc.load(file_uri, gedit.encoding_get_from_charset('utf-8'), 0, False) f_temp = open(file_path, 'r') try: text = unicode(f_temp.read(), 'utf-8') except: text = f_temp.read() f_temp.close() temp_doc.set_text(text) self.advanced_find_all_in_doc(parent_it, temp_doc, search_pattern, options, replace_flg) self._results_view.show_find_result() self.show_bottom_panel()
from gettext import gettext as _ import gtk import gedit import functools import gconf # All encodings names enclist_func = lambda i=0: [gedit.encoding_get_from_index(i)] + enclist_func( i + 1) if gedit.encoding_get_from_index(i) else [] shown_enc = gconf.client_get_default().get( "/apps/gedit-2/preferences/encodings/shown_in_menu") # show the full list of encodings if not they not configured in the Open/Save Dialog enclist = sorted(([ gedit.encoding_get_from_charset(enc.to_string()) for enc in shown_enc.get_list() ] if shown_enc else enclist_func()) + [gedit.encoding_get_utf8()], key=lambda enc: enc.to_string()) ui_str = """<ui> <menubar name="MenuBar"> <menu name="FileMenu" action="File"> <placeholder name="FileOps_2"> <menu name="FileEncodingMenu" action="FileEncoding"> <placeholder name="EncodingListHolder"/> <separator/> %s </menu> </placeholder> </menu>
# TODO: # fix document_loaded: assertion `(tab->priv->state == GEDIT_TAB_STATE_LOADING) || (tab->priv->state == GEDIT_TAB_STATE_REVERTING)' failed from gettext import gettext as _ import gtk import gedit import functools import gconf # All encodings names enclist_func = lambda i=0: [gedit.encoding_get_from_index(i)] + enclist_func(i+1) if gedit.encoding_get_from_index(i) else [] shown_enc = gconf.client_get_default().get("/apps/gedit-2/preferences/encodings/shown_in_menu") # show the full list of encodings if not they not configured in the Open/Save Dialog enclist = sorted(([gedit.encoding_get_from_charset(enc.to_string()) for enc in shown_enc.get_list()] if shown_enc else enclist_func()) + [gedit.encoding_get_utf8()], key=lambda enc: enc.to_string()) ui_str = """<ui> <menubar name="MenuBar"> <menu name="FileMenu" action="File"> <placeholder name="FileOps_2"> <menu name="FileEncodingMenu" action="FileEncoding"> <placeholder name="EncodingListHolder"/> <separator/> %s </menu> </placeholder> </menu> </menubar>
def find_all_in_dir(self, parent_it, dir_path, file_pattern, search_pattern, find_options, replace_flg=False): #start_time = time.time() if search_pattern == "": return #d_list = [] file_list = [] if find_options['INCLUDE_SUBFOLDER'] == True: grep_cmd = ['grep', '-E', '-l', '-R', search_pattern, dir_path] else: grep_cmd = ['grep', '-E', '-l', search_pattern, dir_path] p = subprocess.Popen(grep_cmd, stdout=subprocess.PIPE) for f in p.stdout: if self.check_file_pattern(f, unicode(file_pattern, 'utf-8')): file_list.append(f[:-1]) ''' for root, dirs, files in os.walk(unicode(dir_path, 'utf-8')): for d in dirs: d_list.append(os.path.join(root, d)) for f in files: if self.check_file_pattern(f, unicode(file_pattern, 'utf-8')): if find_options['INCLUDE_SUBFOLDER'] == True: file_list.append(os.path.join(root, f)) else: if os.path.dirname(f) not in d_list: file_list.append(os.path.join(root, f)) self.find_ui.do_events() #''' #mid_time = time.time() #print 'Use ' + str(mid_time-start_time) + ' seconds to find files.' for file_path in file_list: if os.path.isfile(file_path): temp_doc = gedit.Document() #file_uri = "file://" + urllib.pathname2url(file_path.encode('utf-8')) #file_uri = ('file://' + file_path).encode('utf-8') file_uri = gnomevfs.get_uri_from_local_path(file_path) try: temp_doc.load(file_uri, gedit.encoding_get_from_charset('utf-8'), 0, False) except: print 'Can not open ' + file_uri + '.' continue f_temp = open(file_path, 'r') try: text = unicode(f_temp.read(), 'utf-8') except: text = f_temp.read() f_temp.close() temp_doc.set_text(text) self.advanced_find_all_in_doc(parent_it, temp_doc, search_pattern, find_options, replace_flg) self.find_ui.do_events()
def gedit_prefs_manager_get_shown_in_menu_encodings(self): list = gconf.client_get_default().get_list(self.shown_in_menu, gconf.VALUE_STRING) encs = [] for enc in list: encs.append(gedit.encoding_get_from_charset(enc)) return encs