def set_code_mode(self, codemode): if not self.gtksourceview_mode: return # Non-code is the default if not codemode: return self.input_view.modify_font(pango.FontDescription("monospace")) fs = Filesystem.getInstance() try: mimetype = fs.get_file_sync(self.__filename).mimetype except FileStatError as e: mimetype = None target_lang = None if gtksourceview2_avail: import gtksourceview2 langman = gtksourceview2.language_manager_get_default() for language_id in langman.get_language_ids(): language = langman.get_language(language_id) for langmime in language.get_mime_types(): if mimetype == langmime: target_lang = language break if target_lang: break self.input.set_highlight_syntax(True) else: import gtksourceview target_lang = gtksourceview.SourceLanguagesManager().get_language_from_mime_type(mimetype) self.input.set_highlight(True) if target_lang: self.input.set_language(target_lang)
def set_code_mode(self, codemode): if not self.gtksourceview_mode: return # Non-code is the default if not codemode: return self.input_view.modify_font(pango.FontDescription("monospace")) fs = Filesystem.getInstance() try: mimetype = fs.get_file_sync(self.__filename).mimetype except FileStatError as e: mimetype = None target_lang = None if gtksourceview2_avail: import gtksourceview2 langman = gtksourceview2.language_manager_get_default() for language_id in langman.get_language_ids(): language = langman.get_language(language_id) for langmime in language.get_mime_types(): if mimetype == langmime: target_lang = language break if target_lang: break self.input.set_highlight_syntax(True) else: import gtksourceview target_lang = gtksourceview.SourceLanguagesManager( ).get_language_from_mime_type(mimetype) self.input.set_highlight(True) if target_lang: self.input.set_language(target_lang)
class PathCompleter(Completer): def __init__(self): super(PathCompleter, self).__init__() def completions(self, text, cwd): expanded = path_expanduser(text) fullpath = FilePath(expanded, cwd) try: isdir = stat.S_ISDIR(os.stat(fullpath).st_mode) except OSError, e: isdir = False fs = Filesystem.getInstance() if isdir and fullpath.endswith('/'): for fpath in iterd_sorted(fullpath, fpath=True): yield _mkfile_completion(text, fpath) return (src_dpath, src_prefix) = os.path.split(fullpath) try: for fpath in iterd_sorted(src_dpath, fpath=True): fname = unix_basename(fpath) if fname.startswith(src_prefix): try: yield _mkfile_completion(text, fpath) except OSError, e: pass except OSError, e: pass
def execute(self, context, args, options=[]): fs = Filesystem.getInstance() if len(args) == 1: path = path_join(context.cwd, args[0]) else: path = context.cwd if '-a' not in options: ignorecheck = True else: ignorecheck = False for (dirpath, subdirs, fnames) in os.walk(path): filtered_dirs = [] if ignorecheck: for i,dpath in enumerate(subdirs): try: dstat = fs.get_file_sync(dpath) if dstat.hidden: filtered_dirs.append(i) except FileStatError as e: continue for c,i in enumerate(filtered_dirs): del subdirs[i-c] for fname in fnames: fpath = path_join(dirpath, fname) fobj = fs.get_file_sync(fpath) if ignorecheck and fobj.hidden: continue yield fobj
def _resolve_verb_completion(self, text, completion): fs = Filesystem.getInstance() target = completion.target if not (isinstance(target, File) and not target.is_directory): return False # Determine whether this input matches an executable file return fs.path_executable_match(text, target.path)
def ls(context, *args): _("""List contents of a directory.""") show_all = '-a' in context.options long_fmt = '-l' in context.options process_input = '-i' in context.options fs = Filesystem.getInstance() if process_input and input is not None: args = list(args) args.extend(context.input) if len(args) == 0: for x in fs.ls_dir(context.cwd, show_all): yield x elif len(args) == 1: path = FilePath(args[0], context.cwd) fobj = fs.get_file_sync(path) if fobj.is_directory: for x in fs.ls_dir(path, show_all): yield x else: yield fobj return else: # Generate list of sorted File objects from arguments for x in sorted(xmap(lambda arg: fs.get_file_sync(FilePath(arg, context.cwd)), args), lambda a,b: locale.strcoll(a.path, b.path)): yield x
def completions(self, text, cwd, context=None): bc = BuiltinCompleter() for completion in bc.completions(text, cwd, context=context): yield completion aliases = AliasRegistry.getInstance() for alias in aliases: compl = self._match(alias.name, text, alias) if compl: yield compl textpath = FilePath(text, cwd) expanded_textpath = path_expanduser(textpath) (text_dpath, text_prefix) = os.path.split(expanded_textpath) if text.find('/') >= 0 or text.startswith('.' + os.sep): pc = PathCompleter() for completion in pc.completions(text, cwd): fobj = completion.target if fobj.is_directory or fobj.is_executable: yield completion else: fs = Filesystem.getInstance() for dpath in fs.get_path_generator(): if not os.access(dpath, os.X_OK): continue for fpath in iterd_sorted(dpath): fname = unix_basename(fpath) if not fname.startswith(text_prefix): continue fobj = fs.get_file_sync(fpath) if fobj.is_executable: yield _mkfile_completion(text, fpath, fobj)
def get_hosts(self): if self.__monitor is None: self.__monitor = Filesystem.getInstance().get_monitor( self.__path, self.__on_hostchange) if self.__hostcache is None: self.__on_hostchange() return self.__hostcache
def ls(context, *args): _("""List contents of a directory.""") show_all = '-a' in context.options long_fmt = '-l' in context.options process_input = '-i' in context.options fs = Filesystem.getInstance() if process_input and input is not None: args = list(args) args.extend(context.input) if len(args) == 0: for x in fs.ls_dir(context.cwd, show_all): yield x elif len(args) == 1: path = FilePath(args[0], context.cwd) fobj = fs.get_file_sync(path) if fobj.is_directory: for x in fs.ls_dir(path, show_all): yield x else: yield fobj return else: # Generate list of sorted File objects from arguments for x in sorted( xmap(lambda arg: fs.get_file_sync(FilePath(arg, context.cwd)), args), lambda a, b: locale.strcoll(a.path, b.path)): yield x
def load_plugins(): fs = Filesystem.getInstance() syspath = fs.get_system_conf_dir() if syspath: sys_pluginpath = os.path.join(syspath, 'plugins') _load_plugins_in_dir(sys_pluginpath) custom_path = fs.makedirs_p(os.path.join(fs.get_conf_dir(), "plugins")) _load_plugins_in_dir(custom_path)
def set_code_mode(self, codemode): if not self.gtksourceview_mode: return # Non-code is the default if not codemode: return self.input_view.modify_font(pango.FontDescription("monospace")) fs = Filesystem.getInstance() try: mimetype = fs.get_file_sync(self.__filename).mimetype except FileStatError, e: mimetype = None
def load(): if is_unix(): import hotwire_ui.adaptors.aliases_unix fs = Filesystem.getInstance() if fs.executable_on_path('hotwire-ssh'): import hotwire_ui.adaptors.ssh if fs.executable_on_path('hotwire-sudo'): import hotwire_ui.adaptors.sudo import hotwire.sysdep.unix_completers import hotwire_ui.adaptors.edit import hotwire_ui.adaptors.view
def __init__(self, *args, **kwargs): if not 'column_types' in kwargs.iterkeys(): kwargs['column_types'] = [gobject.TYPE_PYOBJECT] self.__fs = Filesystem.getInstance() self.__basedir = None self.__windows_basedir = None super(FilePathRenderer, self).__init__(*args, **kwargs) self._table.enable_model_drag_source( gtk.gdk.BUTTON1_MASK, [('text/uri-list', 0, 0)], gtk.gdk.ACTION_DEFAULT | gtk.gdk.ACTION_COPY) #self._table.enable_model_drag_dest([('text/uri-list', 0, 0)], # gtk.gdk.ACTION_DEFAULT | gtk.gdk.ACTION_COPY) self._table.connect("drag-data-get", self.__on_drag_data_get)
def __init__(self, *args, **kwargs): if not 'column_types' in kwargs.iterkeys(): kwargs['column_types'] = [gobject.TYPE_PYOBJECT] self.__fs = Filesystem.getInstance() self.__basedir = None self.__windows_basedir = None super(FilePathRenderer, self).__init__(*args, **kwargs) self._table.enable_model_drag_source(gtk.gdk.BUTTON1_MASK, [('text/uri-list', 0, 0)], gtk.gdk.ACTION_DEFAULT | gtk.gdk.ACTION_COPY) #self._table.enable_model_drag_dest([('text/uri-list', 0, 0)], # gtk.gdk.ACTION_DEFAULT | gtk.gdk.ACTION_COPY) self._table.connect("drag-data-get", self.__on_drag_data_get)
def _mkfile_completion(text, fpath, fileobj=None): if not isinstance(text, unicode): text = unicode(text, "utf-8") if not isinstance(fpath, unicode): fpath = unicode(fpath, "utf-8") fs = Filesystem.getInstance() fname = unix_basename(fpath) if text.endswith("/"): textbase = "" else: textbase = unix_basename(text) fobj = fileobj or fs.get_file_sync(fpath) startidx = fpath.rindex(fname) suffix = quote_arg(fpath[startidx + len(textbase) :]) if fobj.test_directory(follow_link=True): suffix += "/" return Completion(suffix, fobj, fname)
def _mkfile_completion(text, fpath, fileobj=None): if not isinstance(text, unicode): text = unicode(text, 'utf-8') if not isinstance(fpath, unicode): fpath = unicode(fpath, 'utf-8') fs = Filesystem.getInstance() fname = unix_basename(fpath) if text.endswith('/'): textbase = '' else: textbase = unix_basename(text) fobj = fileobj or fs.get_file_sync(fpath) startidx = fpath.rindex(fname) suffix = quote_arg(fpath[startidx + len(textbase):]) if fobj.test_directory(follow_link=True): suffix += '/' return Completion(suffix, fobj, fname)
def _mkfile_completion(text, fpath, fileobj=None): if not isinstance(text, str): text = str(text, 'utf-8') if not isinstance(fpath, str): fpath = str(fpath, 'utf-8') fs = Filesystem.getInstance() fname = unix_basename(fpath) if text.endswith('/'): textbase = '' else: textbase = unix_basename(text) fobj = fileobj or fs.get_file_sync(fpath) startidx = fpath.rindex(fname) suffix = quote_arg(fpath[startidx+len(textbase):]) if fobj.test_directory(follow_link=True): suffix += '/' return Completion(suffix, fobj, fname)
def sechash(context, *files): _("""Create a secure hash (default SHA1) from objects or file arguments.""") alg = ('-5' in context.options) and md5 or sha fs = Filesystem.getInstance() if (not files) and context.input: for val in context.input: valstr = str(val) hashval = alg.new() hashval.update(valstr) yield hashval.hexdigest() for arg in files: fpath = FilePath(arg, context.cwd) stream = open(fpath) hashval = alg.new() buf = stream.read(4096) while buf: hashval.update(buf) buf = stream.read(4096) stream.close() yield hashval.hexdigest()
def sechash(context, *files): _("""Create a secure hash (default SHA1) from objects or file arguments.""" ) alg = ('-5' in context.options) and md5 or sha fs = Filesystem.getInstance() if (not files) and context.input: for val in context.input: valstr = str(val) hashval = alg.new() hashval.update(valstr) yield hashval.hexdigest() for arg in files: fpath = FilePath(arg, context.cwd) stream = open(fpath) hashval = alg.new() buf = stream.read(4096) while buf: hashval.update(buf) buf = stream.read(4096) stream.close() yield hashval.hexdigest()
def execute(self, context, args, options=[]): if len(args) == 0 and context.input is None: raise ValueError(_("Must specify at least one file")) mkfile = lambda arg: FilePath(arg, context.cwd) sources = map(mkfile, args) if context.input is not None: sources.extend(imap(lambda f: f.path, context.input)) sources_total = len(sources) undo_targets = [] self._status_notify(context, sources_total, 0) fs = Filesystem.getInstance() recursive = '-r' in options force = '-f' in options if '-u' in options: for i,arg in enumerate(sources): if recursive: shutil.rmtree(arg, ignore_errors=force) else: try: os.unlink(arg) except: if not force: raise self._status_notify(context,sources_total,i+1) return [] else: try: for i,arg in enumerate(sources): try: fs.move_to_trash(arg) except: if not force: raise undo_targets.append(arg) self._status_notify(context,sources_total,i+1) self._note_modified_paths(context, sources) finally: context.push_undo(lambda: fs.undo_trashed(undo_targets)) return []
def execute(self, context, args, options=[]): if len(args) == 0 and context.input is None: raise ValueError(_("Must specify at least one file")) mkfile = lambda arg: FilePath(arg, context.cwd) sources = map(mkfile, args) if context.input is not None: sources.extend(imap(lambda f: f.path, context.input)) sources_total = len(sources) undo_targets = [] self._status_notify(context, sources_total, 0) fs = Filesystem.getInstance() recursive = '-r' in options force = '-f' in options if '-u' in options: for i, arg in enumerate(sources): if recursive: shutil.rmtree(arg, ignore_errors=force) else: try: os.unlink(arg) except: if not force: raise self._status_notify(context, sources_total, i + 1) return [] else: try: for i, arg in enumerate(sources): try: fs.move_to_trash(arg) except: if not force: raise undo_targets.append(arg) self._status_notify(context, sources_total, i + 1) self._note_modified_paths(context, sources) finally: context.push_undo(lambda: fs.undo_trashed(undo_targets)) return []
def completions(self, text, cwd): expanded = path_expanduser(text) fullpath = FilePath(expanded, cwd) try: isdir = stat.S_ISDIR(os.stat(fullpath).st_mode) except OSError as e: isdir = False fs = Filesystem.getInstance() if isdir and fullpath.endswith('/'): for fpath in iterd_sorted(fullpath, fpath=True): yield _mkfile_completion(text, fpath) return (src_dpath, src_prefix) = os.path.split(fullpath) try: for fpath in iterd_sorted(src_dpath, fpath=True): fname = unix_basename(fpath) if fname.startswith(src_prefix): try: yield _mkfile_completion(text, fpath) except OSError as e: pass except OSError as e: pass
def open(context, args): _("""Open a file using default program.""") fs = Filesystem.getInstance() for arg in args: fs.launch_open_file(FilePath(arg, context.cwd), context.cwd)
def _get_state_path(name): dirname = Filesystem.getInstance().make_conf_subdir('state') return os.path.join(dirname, name)
def __init__(self, *args, **kwargs): super(TabCompletionView, self).__init__(*args, **kwargs) self.__fs = Filesystem.getInstance() colidx = self.get_view().insert_column_with_data_func(0, '', gtk.CellRendererPixbuf(), self.__render_icon)
def get_hosts(self): if self.__monitor is None: self.__monitor = Filesystem.getInstance().get_monitor(self.__path, self.__on_hostchange) if self.__hostcache is None: self.__on_hostchange() return self.__hostcache
def __init__(self, *args, **kwargs): super(TabCompletionView, self).__init__(*args, **kwargs) self.__fs = Filesystem.getInstance() colidx = self.get_view().insert_column_with_data_func( 0, '', gtk.CellRendererPixbuf(), self.__render_icon)