Beispiel #1
0
    def add_album(self, album_name, artist_ids, filepath, popularity, mtime):
        """
            Add album to db
            @param album name as string
            @param album artist ids as [int]
            @param path to an album track as string
            @param year as int
            @param popularity as int
            @param mtime as int
            @return (album id as int, new as bool)
            @commit needed
        """
        path = GLib.path_get_dirname(filepath)
        new = False
        if artist_ids:
            album_id = Lp().albums.get_non_compilation_id(
                album_name, artist_ids)
        else:
            album_id = Lp().albums.get_compilation_id(album_name)
        if album_id is None:
            new = True
            album_id = Lp().albums.add(album_name, artist_ids, path,
                                       popularity, mtime)
        # Now we have our album id, check if path doesn't change
        if Lp().albums.get_path(album_id) != path:
            Lp().albums.set_path(album_id, path)

        return (album_id, new)
Beispiel #2
0
Datei: ffs.py Projekt: jku/ffs
    def stop_sharing(self):
        if self.archive_state != ArchiveState.NA:
            try:
                os.remove(self.shared_file)
                os.rmdir(GLib.path_get_dirname(self.shared_file))
            except:
                logging.warning("Failed to remove temporary archive")

        self.shared_file = None
        self.change_callback()
 def get_subject_origin(self, uri):
     scheme = GLib.uri_parse_scheme(uri)
     if scheme == 'file':
         return GLib.path_get_dirname(uri)
     elif scheme in ('http', 'https'):
         scheme, domain = uri.split('://', 1)
         return '%s://%s' % (scheme, domain.split('/', 1)[0])
     else:
         return GLib.filename_to_uri(
             self.get_path(force_directory=True), None)
def main():
    ext_path = GLib.path_get_dirname(os.path.realpath(__file__))

    md_file = Gio.file_new_for_path(GLib.build_filenamev([ ext_path, MD_NAME ]))
    [ values, _, err_str ] = read_json_file(md_file)

    # look for an existing locale directory
    locale_dirs = [ GLib.build_filenamev([ ext_path, LOCALE_SUBDIR ]) ]
    if err_str != None:
        print(err_str)
    else:
        if values['system-locale-dir'] != None:
            locale_dirs += [ values['system-locale-dir'] ]

    if values['gettext-domain'] != None:
        for i in range(len(locale_dirs)):
            directory = Gio.file_new_for_path(locale_dirs[i])

            if (directory.query_file_type(Gio.FileQueryInfoFlags.NONE, None) ==
                    Gio.FileType.DIRECTORY):
                gettext.textdomain(values['gettext-domain'])
                gettext.bindtextdomain(values['gettext-domain'],
                    directory.get_path())
                break

    parser = OptionParser(g(ERR_USAGE),
        description = "",
        option_list = [
            make_option('--file', '-f',
                type = 'filename',
                action = 'store',
                dest = 'filename',
                help=g(ERR_FILE_HELP)
            )
        ])
    try:
        parser.parse_args()
    except Exception as e:
        sys.stderr.write("%s\n" % g(ERR_WRONG_ARGS))
        return

    if parser.values.filename == None:
        filename = GLib.build_filenamev(DEFAULT_OPTION_FILE_PARTS)
        sys.stderr.write(g(WARN_DEF_OPT_FILE) % filename)
    else:
        filename = parser.values.filename

    configurator = Configurator(filename)
    configurator.run(None)
    def __apply_cb(self):
        cfgdir = Gio.file_new_for_path(GLib.path_get_dirname(
                self.file.get_path()))

        if cfgdir.query_exists(None):
            if (cfgdir.query_file_type(Gio.FileQueryInfoFlags.NONE, None) !=
                    Gio.FileType.DIRECTORY):
                self.__show_error(g(ERR_TITLE), g(ERR_BASE_NOT_DIR))
                return
        else:
            try:
                cfgdir.make_directory_with_parents(None)
            except GObject.GError as e:
                self.__show_error(g(ERR_TITLE), g(ERR_CANT_MKDIR))
                return

        # collect new data from the status of the widgets. in this way we
        # can also ditch eventual unnecessary data previously read
        self.options = {}
        self.options['use-default-profile'] = self.def_profile.get_active()
        self.options['split-profile-view'] = self.split_view.get_active()
        self.options['show-icons'] = self.show_icons.get_active()
        self.options['hide-entries-not-in-xdg-dir'
                ] = self.hide_non_xdg.get_active()
        self.options['icon-size'] = int(
                round(self.icon_size_spin.get_value()))
        self.options['profiles'] = []
        def collect_profiles(model, path, i, rows=None):
            indices = path.get_indices()
            index = indices[0]
            # we need to add a new empty dict to the list
            self.options['profiles'].append({})
            self.options['profiles'][index][
                    'name'] = model.get_value(i, COLUMN['name'])
            self.options['profiles'][index][
                    'directory'] = model.get_value(i, COLUMN['dir'])
            return False
        args = []
        self.profile_store.foreach(collect_profiles, args)

        write_error = None
        try:
            encoded = str.encode(json.dumps(self.options))
            GLib.file_set_contents(self.file.get_path(), encoded)
        except GObject.GError as write_error:
            text = (g(ERR_FILE_WRITE) % (self.file.get_path(), write_error))
            self.__show_error(g(ERR_TITLE), text)
            return
        self.__set_changed(False)
Beispiel #6
0
    def open_file_chooser(self, menuitem, window):
        dialog = Gtk.FileChooserDialog(
            _("Open Project"), window, Gtk.FileChooserAction.OPEN,
            (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_OPEN,
             Gtk.ResponseType.OK))
        fileFilter = Gtk.FileFilter()
        fileFilter.set_name(_("Insight recorder projects"))
        #old project file extension
        fileFilter.add_pattern("*.dut")
        fileFilter.add_pattern("*.isr")

        response = dialog.run()

        if (response == Gtk.ResponseType.OK):
            projectFile = dialog.get_filename()
            self.projectDir = GLib.path_get_dirname(projectFile)
            self.listStore.clear()
            self.projectConfig = isrProject.isrProject(projectFile, None)
            self.projectConfig.populate(self, m)

        dialog.destroy()
    def open_file_chooser (self, menuitem, window):
        dialog = Gtk.FileChooserDialog ("Open File",
                                        None,
                                        Gtk.FileChooserAction.OPEN,
                                        (Gtk.STOCK_CANCEL,
                                        Gtk.ResponseType.CANCEL,
                                        Gtk.STOCK_OPEN, Gtk.ResponseType.OK))
        fileFilter = Gtk.FileFilter ()
        fileFilter.set_name ("Dawati User testing project")
        fileFilter.add_pattern ("*.dut")
        dialog.add_filter (fileFilter)

        response = dialog.run ()

        if response == Gtk.ResponseType.OK:
            projectFile = dialog.get_filename ()
            self.projectDir = GLib.path_get_dirname (projectFile)
            self.listStore.clear ()
            self.projectConfig = dutProject.dutProject (projectFile, None)
            self.projectConfig.populate (self, m)

        dialog.destroy()
    def open_file_chooser (self, menuitem, window):
        dialog = Gtk.FileChooserDialog (_("Open Project"),
                                        window,
                                        Gtk.FileChooserAction.OPEN,
                                        (Gtk.STOCK_CANCEL,
                                        Gtk.ResponseType.CANCEL,
                                        Gtk.STOCK_OPEN, Gtk.ResponseType.OK))
        fileFilter = Gtk.FileFilter ()
        fileFilter.set_name (_("Insight recorder projects"))
        #old project file extension
        fileFilter.add_pattern ("*.dut")
        fileFilter.add_pattern ("*.isr")

        response = dialog.run ()

        if (response == Gtk.ResponseType.OK):
            projectFile = dialog.get_filename ()
            self.projectDir = GLib.path_get_dirname (projectFile)
            self.listStore.clear ()
            self.projectConfig = isrProject.isrProject (projectFile, None)
            self.projectConfig.populate (self, m)

        dialog.destroy()
Beispiel #9
0
def log(title, uri, opened):
    subject = Subject.new_for_values(
        uri=uri,
        interpretation=Interpretation.PLAIN_TEXT_DOCUMENT,
        manifestation=Manifestation.FILE_DATA_OBJECT,
        origin=GLib.path_get_dirname(uri),
        mimetype='text/plain',
        text=title)
    event = Event.new_for_values(
        timestamp=time.time()*1000,
        manifestation=Manifestation.USER_ACTIVITY,
        actor='application://sublime-text-2.desktop',
        subjects=[subject])
    if opened:
        event.interpretation = Interpretation.ACCESS_EVENT
    else:
        event.interpretation = Interpretation.LEAVE_EVENT
 
    def on_id_received(event_ids):
        print 'Logged %s (%d) with event id %d.' % (title, opened, event_ids[0])
    
    print 'Logging event %s - %s' % (title, uri)
    zeitgeist.insert_events([event], on_id_received)