コード例 #1
0
ファイル: editor.py プロジェクト: sandeep-datta/hotwire
 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)
コード例 #2
0
 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)
コード例 #3
0
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
コード例 #4
0
ファイル: walk.py プロジェクト: sandeep-datta/hotwire
 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
コード例 #5
0
ファイル: command.py プロジェクト: sandeep-datta/hotwire
 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)
コード例 #6
0
ファイル: ls.py プロジェクト: sandeep-datta/hotwire
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
コード例 #7
0
 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)
コード例 #8
0
ファイル: sshutil.py プロジェクト: sandeep-datta/hotwire
 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
コード例 #9
0
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
コード例 #10
0
ファイル: completion.py プロジェクト: sandeep-datta/hotwire
 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)
コード例 #11
0
ファイル: command.py プロジェクト: zsx/hotwire
 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)
コード例 #12
0
ファイル: pluginsystem.py プロジェクト: sandeep-datta/hotwire
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)
コード例 #13
0
ファイル: editor.py プロジェクト: zaxebo1/hotwire-shell
 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
コード例 #14
0
ファイル: editor.py プロジェクト: EmilyDirsh/hotwire-shell
 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
コード例 #15
0
ファイル: __init__.py プロジェクト: sandeep-datta/hotwire
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
コード例 #16
0
 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)
コード例 #17
0
ファイル: file.py プロジェクト: zsx/hotwire
 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)
コード例 #18
0
ファイル: completion.py プロジェクト: zsx/hotwire
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)
コード例 #19
0
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)
コード例 #20
0
ファイル: completion.py プロジェクト: sandeep-datta/hotwire
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)     
コード例 #21
0
ファイル: sechash.py プロジェクト: EmilyDirsh/hotwire-shell
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()
コード例 #22
0
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()
コード例 #23
0
ファイル: rm.py プロジェクト: EmilyDirsh/hotwire-shell
 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 []
コード例 #24
0
 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 []
コード例 #25
0
ファイル: completion.py プロジェクト: sandeep-datta/hotwire
 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
コード例 #26
0
ファイル: open.py プロジェクト: EmilyDirsh/hotwire-shell
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)
コード例 #27
0
def _get_state_path(name):
    dirname = Filesystem.getInstance().make_conf_subdir('state')
    return os.path.join(dirname, name)
コード例 #28
0
ファイル: completion.py プロジェクト: sandeep-datta/hotwire
 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)
コード例 #29
0
ファイル: sshutil.py プロジェクト: EmilyDirsh/hotwire-shell
 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
コード例 #30
0
ファイル: completion.py プロジェクト: zaxebo1/hotwire-shell
 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)
コード例 #31
0
ファイル: state.py プロジェクト: EmilyDirsh/hotwire-shell
def _get_state_path(name):
    dirname = Filesystem.getInstance().make_conf_subdir('state')
    return os.path.join(dirname, name)
コード例 #32
0
ファイル: open.py プロジェクト: sandeep-datta/hotwire
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)