def __init__ (self, _gettext): global _ _ = _gettext # Figure out our installation paths self.DATADIR = os.path.join (os.path.dirname (os.path.abspath ( sys.argv [0])), "share") if not os.path.exists (self.DATADIR): self.DATADIR = os.path.join (os.path.normpath (sys.prefix), "share/tinyavi") if not os.path.exists (self.DATADIR): self.DATADIR = os.path.join (os.path.normpath (os.path.join ( os.path.dirname (os.path.abspath (sys.argv [0])), "..")), "share/tinyavi") if not os.path.exists (self.DATADIR): raise SystemExit, _("FATAL: Could not find data directory") self.BINDIR = os.path.dirname (os.path.abspath (sys.argv [0])) self.configfile = gobject.filename_from_utf8 (os.path.expanduser("~/.config")) if not os.access (self.configfile, os.F_OK): os.makedirs (self.configfile, 0700) self.configfile = os.path.join (self.configfile, "tinyavi-gui.conf") # Load the widgets from the Glade file try: self.glade = gtk.glade.XML(self.DATADIR + "/gui.glade") except RuntimeError, msg: raise SystemExit, msg
def get_text_items(self, text): if not text.strip(): return if '\n' in text: return ## check for absolute path with arguments firstwords = text.split() ## files are handled elsewhere if firstwords[0].startswith("/") and len(firstwords) == 1: return ## absolute paths come out here since ## os.path.join with two abspaths returns the latter firstword = firstwords[0] # bash aliases/functions: should supercede real commands (you might # have, say, alias ls='ls --color=auto') if (__kupfer_settings__["aliases"] and firstword in self._aliases) or \ (__kupfer_settings__["functions"] and firstword in self._fns): cmds = self._bash_cmds + u" ".join(firstwords) yield BashCommand('bash -i -c ' + quote(cmds), text) # iterate over $PATH directories PATH = os.environ.get("PATH", os.defpath) for execdir in PATH.split(os.pathsep): exepath = os.path.join(execdir, firstword) # use filesystem encoding here exepath = gobject.filename_from_utf8(exepath) if os.access(exepath, os.R_OK | os.X_OK) and os.path.isfile(exepath): yield Command(exepath, text) break
def get_text_items(self, text): if not text.strip(): return if '\n' in text: return ## check for absolute path with arguments firstwords = text.split() ## files are handled elsewhere if firstwords[0].startswith("/") and len(firstwords) == 1: return ## absolute paths come out here since ## os.path.join with two abspaths returns the latter firstword = firstwords[0] # bash aliases/functions: should supercede real commands (you might # have, say, alias ls='ls --color=auto') if (__kupfer_settings__["aliases"] and firstword in self._aliases) or \ (__kupfer_settings__["functions"] and firstword in self._fns): cmds = self._bash_cmds + u" ".join(firstwords) yield BashCommand('bash -i -c '+ quote(cmds), text) # iterate over $PATH directories PATH = os.environ.get("PATH", os.defpath) for execdir in PATH.split(os.pathsep): exepath = os.path.join(execdir, firstword) # use filesystem encoding here exepath = gobject.filename_from_utf8(exepath) if os.access(exepath, os.R_OK|os.X_OK) and os.path.isfile(exepath): yield Command(exepath, text) break
def get_text_items(self, text): # Find directories or files prefix = os.path.expanduser(u"~/") ufilepath = text if os.path.isabs(text) else os.path.join(prefix, text) # use filesystem encoding here filepath = gobject.filename_from_utf8(os.path.normpath(ufilepath)) if os.access(filepath, os.R_OK): yield FileLeaf(filepath)
def get_full_path(self): text = self.__gentry.get_entry().get_text() if not text: return None sys_text = gobject.filename_from_utf8(text) filename = _expand_filename(sys_text, self._get_default()) if not filename: return None return filename
def get_process_args(self, filename): """Get the process args. Return the process arguments (the app_path, argv[0], will be prepended in async_process_file and should not be included here). """ if config.data.os == 'win32': args = [ '-i', filename.encode('utf8', sys.getfilesystemencoding()), '-o', self.tempdir.encode('utf8', sys.getfilesystemencoding()), '-s', str(self.sensitivity) ] else: args = [ '-i', gobject.filename_from_utf8(filename.encode('utf8')), '-o', gobject.filename_from_utf8(self.tempdir.encode('utf8')), '-s', str(self.sensitivity) ] return args
def single_image_in_dir(dirname): # Returns None or a filename if there is exactly one image # in the dir. try: dirname = gobject.filename_from_utf8(dirname) except: pass if not os.path.exists(dirname): return None imgfiles = [f for f in os.listdir(dirname) if is_imgfile(f)] if len(imgfiles) != 1: return None return os.path.join(dirname, imgfiles[0])
def __build_filename(self): text = self.__gentry.get_entry().get_text() if not text: return self.__default_path + os.sep locale_text = gobject.filename_from_utf8(text) if not locale_text: return self.__default_path + os.sep filename = _expand_filename(locale_text, self.__default_path) if not filename: return self.__default_path + os.sep if not filename.endswith(os.sep) and (self.__directory_entry or os.path.isdir(filename)): filename += os.sep return filename
def get_text_items(self, text): if not text.strip(): return if len(text.splitlines()) > 1: return firstword = text.split()[0] if firstword.startswith("/"): return # iterate over $PATH directories PATH = os.environ.get("PATH") or os.defpath for execdir in PATH.split(os.pathsep): exepath = os.path.join(execdir, firstword) # use filesystem encoding here exepath = gobject.filename_from_utf8(exepath) if os.access(exepath, os.R_OK|os.X_OK) and os.path.isfile(exepath): yield Command(exepath, text) break
def get_text_items(self, text): if not text.strip(): return if '\n' in text: return ## check for absolute path with arguments firstwords = text.split() ## files are handled elsewhere if firstwords[0].startswith("/") and len(firstwords) == 1: return ## absolute paths come out here since ## os.path.join with two abspaths returns the latter firstword = firstwords[0] # iterate over $PATH directories PATH = os.environ.get("PATH", os.defpath) for execdir in PATH.split(os.pathsep): exepath = os.path.join(execdir, firstword) # use filesystem encoding here exepath = gobject.filename_from_utf8(exepath) if os.access(exepath, os.R_OK|os.X_OK) and os.path.isfile(exepath): yield Command(exepath, text) break
# Text interface # (i) live_query_id, (s) service, (s) search_text, # (i) offset, (i) max_hits # Returns array of strings for results try: file_hits = searchobj.Text(1, "Files", self.query, 0, self.max_items) except dbus.DBusException, exc: pretty.print_error(__name__, exc) return for filestr in file_hits: # A bit of encoding carousel # dbus strings are subclasses of unicode # but FileLeaf expects a filesystem encoded object bytes = filestr.decode("UTF-8", "replace") filename = gobject.filename_from_utf8(bytes) yield ConstructFileLeaf(filename) def get_description(self): return _('Results for "%s"') % self.query def get_icon_name(self): return "tracker" @classmethod def decorates_type(cls): return FileLeaf @classmethod def decorate_item(cls, leaf): # FIXME: Very simplified .savedSearch parsing, so far we only support # the query, without additional filtering. The simplest form of # .savedSearch file is saved by nautilus as following:
def file_from_utf8(filename): import gobject try: return gobject.filename_from_utf8(filename) except: return filename
# (i) live_query_id, (s) service, (s) search_text, # (i) offset, (i) max_hits # Returns array of strings for results try: file_hits = searchobj.Text(1, "Files", self.query, 0, self.max_items) except dbus.DBusException, exc: pretty.print_error(__name__, exc) return for filestr in file_hits: # A bit of encoding carousel # dbus strings are subclasses of unicode # but FileLeaf expects a filesystem encoded object bytes = filestr.decode("UTF-8", "replace") filename = gobject.filename_from_utf8(bytes) yield ConstructFileLeaf(filename) def get_description(self): return _('Results for "%s"') % self.query def get_icon_name(self): return "tracker" @classmethod def decorates_type(cls): return FileLeaf @classmethod def decorate_item(cls, leaf): # FIXME: Very simplified .savedSearch parsing, so far we only support
def file_from_utf8(filename): try: return gobject.filename_from_utf8(filename) except: return filename