Example #1
0
 def __init__(self, dir, show_hidden=False):
     # Use glib filename reading to make display name out of filenames
     # this function returns a `unicode` object
     name = GLib.filename_display_basename(dir)
     super(DirectorySource, self).__init__(name)
     self.directory = dir
     self.show_hidden = show_hidden
Example #2
0
    def test_filenames(self):
        self.assertEqual(GLib.filename_display_name('foo'), 'foo')
        self.assertEqual(GLib.filename_display_basename('bar/foo'), 'foo')

        def glibfsencode(f):
            # the annotations of filename_from_utf8() was changed in
            # https://bugzilla.gnome.org/show_bug.cgi?id=756128
            if isinstance(f, bytes):
                return f
            if os.name == "nt":
                if PY3:
                    return f.encode("utf-8", "surrogatepass")
                else:
                    return f.encode("utf-8")
            else:
                assert PY3
                return os.fsencode(f)

        # this is locale dependent, so we cannot completely verify the result
        res = GLib.filename_from_utf8(u'aäb')
        res = glibfsencode(res)
        self.assertTrue(isinstance(res, bytes))
        self.assertGreaterEqual(len(res), 3)

        # with explicit length argument
        res = GLib.filename_from_utf8(u'aäb', 1)
        res = glibfsencode(res)
        self.assertEqual(res, b'a')
Example #3
0
 def __init__(self, dirlist, depth=0):
     """
     @dirlist: Directories as byte strings
     """
     name = GLib.filename_display_basename(dirlist[0])
     if len(dirlist) > 1:
         name = _("%s et. al.") % name
     super(FileSource, self).__init__(name)
     self.dirlist = dirlist
     self.depth = depth
Example #4
0
def parse_kfcom_file(filepath):
    """Extract the serialized command inside @filepath

    The file must be executable (comparable to a shell script)
    >>> parse_kfcom_file(__file__)  # doctest: +ELLIPSIS
    Traceback (most recent call last):
        ...
    ExecutionError: ... (not executable)

    Return commands triple
    """
    fobj = open(filepath, "rb")
    if not os.access(filepath, os.X_OK):
        raise ExecutionError(
            _('No permission to run "%s" (not executable)') %
            GLib.filename_display_basename(filepath))

    # strip shebang away
    data = fobj.read()
    if data.startswith(b"#!") and b"\n" in data:
        shebang, data = data.split(b"\n", 1)

    try:
        id_ = conspickle.BasicUnpickler.loads(data)
        command_object = puid.resolve_unique_id(id_)
    except pickle.UnpicklingError as err:
        raise ExecutionError("Could not parse: %s" % str(err))
    except Exception:
        raise ExecutionError('"%s" is not a saved command' %
                             os.path.basename(filepath))
    if command_object is None:
        raise ExecutionError(
            _('Command in "%s" is not available') %
            GLib.filename_display_basename(filepath))

    try:
        return tuple(command_object.object)
    except (AttributeError, TypeError):
        raise ExecutionError('"%s" is not a saved command' %
                             os.path.basename(filepath))
    finally:
        GLib.idle_add(update_icon, command_object, filepath)
Example #5
0
    def test_filenames(self):
        self.assertEqual(GLib.filename_display_name('foo'), 'foo')
        self.assertEqual(GLib.filename_display_basename('bar/foo'), 'foo')

        # this is locale dependent, so we cannot completely verify the result
        res = GLib.filename_from_utf8(_unicode('aäb'))
        self.assertTrue(isinstance(res, bytes))
        self.assertGreaterEqual(len(res), 3)

        # with explicit length argument
        self.assertEqual(GLib.filename_from_utf8(_unicode('aäb'), 1), b'a')
Example #6
0
    def test_filenames(self):
        self.assertEqual(GLib.filename_display_name('foo'), 'foo')
        self.assertEqual(GLib.filename_display_basename('bar/foo'), 'foo')

        # this is locale dependent, so we cannot completely verify the result
        res = GLib.filename_from_utf8(_unicode('aäb'))
        self.assertTrue(isinstance(res, bytes))
        self.assertGreaterEqual(len(res), 3)

        # with explicit length argument
        self.assertEqual(GLib.filename_from_utf8(_unicode('aäb'), 1), b'a')
Example #7
0
def parse_kfcom_file(filepath):
    """Extract the serialized command inside @filepath

    The file must be executable (comparable to a shell script)
    >>> parse_kfcom_file(__file__)  # doctest: +ELLIPSIS
    Traceback (most recent call last):
        ...
    ExecutionError: ... (not executable)

    Return commands triple
    """
    fobj = open(filepath, "rb")
    if not os.access(filepath, os.X_OK):
        raise ExecutionError(_('No permission to run "%s" (not executable)') %
                GLib.filename_display_basename(filepath))

    # strip shebang away
    data = fobj.read()
    if data.startswith(b"#!") and b"\n" in data:
        shebang, data = data.split(b"\n", 1)

    try:
        id_ = conspickle.BasicUnpickler.loads(data)
        command_object = puid.resolve_unique_id(id_)
    except pickle.UnpicklingError as err:
        raise ExecutionError("Could not parse: %s" % str(err))
    except Exception:
        raise ExecutionError('"%s" is not a saved command' %
                os.path.basename(filepath))
    if command_object is None:
        raise ExecutionError(_('Command in "%s" is not available') %
                GLib.filename_display_basename(filepath))

    try:
        return tuple(command_object.object)
    except (AttributeError, TypeError):
        raise ExecutionError('"%s" is not a saved command' %
                os.path.basename(filepath))
    finally:
        GLib.idle_add(update_icon, command_object, filepath)
Example #8
0
    def get_basename_display(self):
        """
            Return the track basename for display purposes (invalid characters
            are replaced).

            :rtype: unicode
        """
        gfile = Gio.File.new_for_uri(self.get_loc_for_io())
        path = gfile.get_path()
        if path:  # Local
            path = GLib.filename_display_basename(path)
        else:  # Non-local
            path = GLib.filename_display_name(gfile.get_basename())
        return path.decode('utf-8')
Example #9
0
    def get_basename_display(self):
        """
            Return the track basename for display purposes (invalid characters
            are replaced).

            :rtype: unicode
        """
        gfile = Gio.File.new_for_uri(self.get_loc_for_io())
        path = gfile.get_path()
        if path:  # Local
            path = GLib.filename_display_basename(path)
        else:  # Non-local
            path = GLib.filename_display_name(gfile.get_basename())
        return path.decode('utf-8')
Example #10
0
    def __init__(self, obj, name=None, alias=None):
        """Construct a FileLeaf

        The display name of the file is normally derived from the full path,
        and @name should normally be left unspecified.

        @obj: byte string (file system encoding)
        @name: unicode name or None for using basename
        """
        if obj is None:
            raise InvalidDataError("File path for %s may not be None" % name)
        # Use glib filename reading to make display name out of filenames
        # this function returns a `unicode` object
        if not name:
            unicode_path = tounicode(obj)
            name = GLib.filename_display_basename(unicode_path)
        super(FileLeaf, self).__init__(obj, name)
        if alias:
            self.kupfer_add_alias(alias)
Example #11
0
    def __init__(self, obj, name=None, alias=None):
        """Construct a FileLeaf

        The display name of the file is normally derived from the full path,
        and @name should normally be left unspecified.

        @obj: byte string (file system encoding)
        @name: unicode name or None for using basename
        """
        if obj is None:
            raise InvalidDataError("File path for %s may not be None" % name)
        # Use glib filename reading to make display name out of filenames
        # this function returns a `unicode` object
        if not name:
            unicode_path = tounicode(obj)
            name = GLib.filename_display_basename(unicode_path)
        super(FileLeaf, self).__init__(obj, name)
        if alias:
            self.kupfer_add_alias(alias)
Example #12
0
    def new_folder_chooser (self, menuitem, window):
        dialog = Gtk.FileChooserDialog ("New project",
                                        None,
                                        Gtk.FileChooserAction.CREATE_FOLDER,
                                        (Gtk.STOCK_CANCEL,
                                        Gtk.ResponseType.CANCEL,
                                        Gtk.STOCK_SAVE, Gtk.ResponseType.OK))

        dialog.set_do_overwrite_confirmation (True)

        response = dialog.run ()

        if response == Gtk.ResponseType.OK:
            self.listStore.clear ()
            self.projectDir = dialog.get_filename ()
            projectName = GLib.filename_display_basename (self.projectDir)
            self.projectConfig = dutProject.dutProject (self.projectDir+"/"+projectName+".dut", projectName)

            self.projectLabel.set_text ("Project: "+projectName)
            self.enable_buttons ()

        dialog.destroy()
Example #13
0
    def test_filenames(self):
        self.assertEqual(GLib.filename_display_name('foo'), 'foo')
        self.assertEqual(GLib.filename_display_basename('bar/foo'), 'foo')

        def glibfsencode(f):
            # the annotations of filename_from_utf8() was changed in
            # https://bugzilla.gnome.org/show_bug.cgi?id=756128
            if isinstance(f, bytes):
                return f
            if os.name == "nt":
                return f.encode("utf-8", "surrogatepass")
            else:
                return os.fsencode(f)

        # this is locale dependent, so we cannot completely verify the result
        res = GLib.filename_from_utf8(u'aäb')
        res = glibfsencode(res)
        self.assertTrue(isinstance(res, bytes))
        self.assertGreaterEqual(len(res), 3)

        # with explicit length argument
        res = GLib.filename_from_utf8(u'aäb', 1)
        res = glibfsencode(res)
        self.assertEqual(res, b'a')
Example #14
0
 def _get_package_name(self):
     return GLib.filename_display_basename(self.get_id())
Example #15
0
 def _get_package_name(self):
     return GLib.filename_display_basename(self.get_id())
Example #16
0
 def __init__(self, path):
     basename = GLib.filename_display_basename(path)
     nameroot, ext = os.path.splitext(basename)
     FileLeaf.__init__(self, path, _("%s template") % nameroot)