Ejemplo n.º 1
0
    def setup_test_directory(self, sessions=[], profinit=True, prefsinit=True):
        profile1_prefs = DEFAULT_PREFERENCES_1_DATA
        profile2_prefs = DEFAULT_PREFERENCES_2_DATA
        # Create a temporary directory for testing
        TMPDIR = GLib.dir_make_tmp("fc_logger_chromium_XXXXXX")
        # Create profile directories
        self.assertEqual(
            0,
            GLib.mkdir_with_parents(
                os.path.join(TMPDIR, "Profile 1"),
                0o755))
        self.assertEqual(
            0,
            GLib.mkdir_with_parents(
                os.path.join(TMPDIR, "Profile 2"),
                0o755))
        # Create local state file
        local_state_data = DEFAULT_LOCAL_STATE_DATA
        local_state_data["profile"]["last_active_profiles"] = sessions
        with open(os.path.join(TMPDIR, "Local State"), 'w') as fd:
                fd.write(json.dumps(local_state_data, sort_keys=True))
        with open(os.path.join(TMPDIR, "Profile 1/Preferences"), 'w') as fd:
                fd.write(json.dumps(profile1_prefs, sort_keys=True))
        with open(os.path.join(TMPDIR, "Profile 2/Preferences"), 'w') as fd:
                fd.write(json.dumps(profile2_prefs, sort_keys=True))
        # Bookmarks data
        with open(os.path.join(TMPDIR, "Profile 1/Bookmarks"), 'w') as fd:
                fd.write(json.dumps(DEFAULT_BOOKMARKS_DATA, sort_keys=True))
        with open(os.path.join(TMPDIR, "Profile 2/Bookmarks"), 'w') as fd:
                fd.write(json.dumps(DEFAULT_BOOKMARKS_DATA, sort_keys=True))

        return TMPDIR
Ejemplo n.º 2
0
    def __init__(self):
        GObject.GObject.__init__(self)
        self.playlist_path = GLib.build_filenamev([GLib.get_user_data_dir(),
                                                  "gnome-music", "playlists"])
        if not (GLib.file_test(self.playlist_path, GLib.FileTest.IS_DIR)):
            GLib.mkdir_with_parents(self.playlist_path, int("0755", 8))

        Grl.init(None)
        self.options = Grl.OperationOptions()
        self.options.set_resolution_flags(Grl.ResolutionFlags.FAST_ONLY |
                                          Grl.ResolutionFlags.IDLE_RELAY)

        self.full_options = Grl.OperationOptions()
        self.full_options.set_resolution_flags(Grl.ResolutionFlags.FULL |
                                               Grl.ResolutionFlags.IDLE_RELAY)

        self.sources = {}
        self.blacklist = ['grl-filesystem', 'grl-bookmarks', 'grl-metadata-store', 'grl-podcasts']
        self.tracker = None
        self.changed_media_ids = []
        self.pending_event_id = 0
        self.changes_pending = {'Albums': False, 'Artists': False, 'Songs': False}
        self.pending_changed_medias = []

        self.registry = Grl.Registry.get_default()

        self.sparqltracker = TrackerWrapper().tracker
Ejemplo n.º 3
0
 def __init__(self):
     """
         Create database tables or manage update if needed
         @param suffix as str
     """
     self.thread_lock = Lock()
     new_version = len(self.__UPGRADES)
     self.__DB_PATH = "%s/settings2.db" % EOLIE_DATA_PATH
     if not GLib.file_test(self.__DB_PATH, GLib.FileTest.IS_REGULAR):
         try:
             if not GLib.file_test(EOLIE_DATA_PATH, GLib.FileTest.IS_DIR):
                 GLib.mkdir_with_parents(EOLIE_DATA_PATH, 0o0750)
             # Create db schema
             with SqlCursor(self) as sql:
                 sql.execute(self.__create_settings)
                 sql.execute("PRAGMA user_version=%s" % new_version)
         except Exception as e:
             Logger.error("DatabaseSettings::__init__(): %s", e)
     # DB upgrade, TODO Make it generic between class
     version = 0
     with SqlCursor(self) as sql:
         result = sql.execute("PRAGMA user_version")
         v = result.fetchone()
         if v is not None:
             version = v[0]
         if version < new_version:
             for i in range(version + 1, new_version + 1):
                 try:
                     sql.execute(self.__UPGRADES[i])
                 except:
                     Logger.error("Settings DB upgrade %s failed", i)
             sql.execute("PRAGMA user_version=%s" % new_version)
Ejemplo n.º 4
0
    def __init__(self):
        GObject.GObject.__init__(self)
        self.playlist_path = GLib.build_filenamev([GLib.get_user_data_dir(),
                                                  "gnome-music", "playlists"])
        if not (GLib.file_test(self.playlist_path, GLib.FileTest.IS_DIR)):
            GLib.mkdir_with_parents(self.playlist_path, int("0755", 8))
        self.options = Grl.OperationOptions()
        self.options.set_resolution_flags(Grl.ResolutionFlags.FAST_ONLY |
                                          Grl.ResolutionFlags.IDLE_RELAY)

        self.full_options = Grl.OperationOptions()
        self.full_options.set_resolution_flags(Grl.ResolutionFlags.FULL |
                                               Grl.ResolutionFlags.IDLE_RELAY)

        self.sources = {}
        self.blacklist = ['grl-filesystem', 'grl-bookmarks', 'grl-metadata-store', 'grl-podcasts']
        self.tracker = None
        self.changed_media_ids = []
        self.pending_event_id = 0
        self.changes_pending = {'Albums': False, 'Artists': False, 'Songs': False}
        self.pending_changed_medias = []

        self.registry = Grl.Registry.get_default()

        self.sparqltracker = TrackerWrapper().tracker
Ejemplo n.º 5
0
    def __init__(self):
        GObject.GObject.__init__(self)
        self.playlist_path = GLib.build_filenamev([GLib.get_user_data_dir(),
                                                  "gnome-music", "playlists"])
        if not (GLib.file_test(self.playlist_path, GLib.FileTest.IS_DIR)):
            GLib.mkdir_with_parents(self.playlist_path, int("0755", 8))
        self.options = Grl.OperationOptions()
        self.options.set_flags(Grl.ResolutionFlags.FAST_ONLY |
                               Grl.ResolutionFlags.IDLE_RELAY)

        self.full_options = Grl.OperationOptions()
        self.full_options.set_flags(Grl.ResolutionFlags.FULL |
                                    Grl.ResolutionFlags.IDLE_RELAY)

        self.sources = {}
        self.tracker = None
        self.changed_media_ids = []
        self.pending_event_id = 0

        self.registry = Grl.Registry.get_default()
        self.registry.connect('source_added', self._on_source_added)
        self.registry.connect('source_removed', self._on_source_removed)

        try:
            self.registry.load_all_plugins()
        except GLib.GError:
            logger.error('Failed to load plugins.')
        if self.tracker is not None:
            logger.debug("tracker found")
Ejemplo n.º 6
0
    def do_dummy_install(self):
        podir = os.path.join(XLET_DIR, "files", XLET_UUID, "po")
        done_one = False
        dummy_locale_path = os.path.join("../../", "tmp", "locales", XLET_UUID)

        for root, subFolders, files in os.walk(podir, topdown=False):
            for file in files:
                parts = os.path.splitext(file)
                if parts[1] == ".po":
                    self.lang_list.append(parts[0])
                    this_locale_dir = os.path.join(dummy_locale_path, parts[0],
                                                   "LC_MESSAGES")
                    GLib.mkdir_with_parents(this_locale_dir, 0o755)
                    subprocess.call([
                        "msgfmt", "-c",
                        os.path.join(root, file), "-o",
                        os.path.join(this_locale_dir, "%s.mo" % XLET_UUID)
                    ])
                    done_one = True

        if done_one:
            print("Dummy install complete")

            if len(self.lang_list) > 0:
                translations.store(XLET_UUID, dummy_locale_path,
                                   self.lang_list)

            # Append english to lang_list AFTER storing the translations.
            self.lang_list.append("en")
            self.create_html_document()
        else:
            print("Dummy install failed")
            quit()
Ejemplo n.º 7
0
    def on_button2_clicked(self, widget, data=None):
        #get the title for the note
        title = self.ui.entry1.get_text()
        if title.find(" ") != -1:
            dialog = Gtk.MessageDialog(self, 0, Gtk.MessageType.WARNING,
            Gtk.ButtonsType.OK_CANCEL, "Warning on Title")
            dialog.format_secondary_text("Do not place spaces in title")
            response = dialog.run()
            if response == Gtk.ResponseType.OK:
                print "WARN dialog closed by clicking OK button"
            elif response == Gtk.ResponseType.CANCEL:
                print "WARN dialog closed by clicking CANCEL button"

            dialog.destroy()

            return

        #get the string
        buff = self.ui.textview1.get_buffer()
        start_iter = buff.get_start_iter()
        end_iter = buff.get_end_iter()
        text = buff.get_text(start_iter, end_iter, True)

        #create the filename
        data_dir = "pastebin/pastebinnotsync"
        filename = os.path.join(data_dir, title)
        filename=filename+".txt"

        #write the data
        GLib.mkdir_with_parents(data_dir, 0o700)
        GLib.file_set_contents(filename, text)
        print "save"            
    def on_checkbutton_sound_toggled(self, widget, data=None):
        if self.check.get_active():
            # write the string True to file
            content = True
            s = str(content)

            # create file the filename
            title = "config"
            data_dir = GLib.get_user_data_dir()
            pomidor_dir = os.path.join(data_dir, "pomidor")
            filename = os.path.join(pomidor_dir, title)
            
            # write the data
            GLib.mkdir_with_parents(pomidor_dir, 0o700)
            GLib.file_set_contents(filename, s)
        else:
            # write the string False to file
            content = False
            s = str(content)

            # create file the filename
            title = "config"
            data_dir = GLib.get_user_data_dir()
            pomidor_dir = os.path.join(data_dir, "pomidor")
            filename = os.path.join(pomidor_dir, title)
            
            # write the data
            GLib.mkdir_with_parents(pomidor_dir, 0o700)
            GLib.file_set_contents(filename, s)
Ejemplo n.º 9
0
    def setup_test_directory(self, sessions=[], profinit=True, prefsinit=True):
        profile1_prefs = DEFAULT_PREFERENCES_1_DATA
        profile2_prefs = DEFAULT_PREFERENCES_2_DATA
        # Create a temporary directory for testing
        TMPDIR = GLib.dir_make_tmp("fc_logger_chromium_XXXXXX")
        # Create profile directories
        self.assertEqual(
            0, GLib.mkdir_with_parents(os.path.join(TMPDIR, "Profile 1"),
                                       0o755))
        self.assertEqual(
            0, GLib.mkdir_with_parents(os.path.join(TMPDIR, "Profile 2"),
                                       0o755))
        # Create local state file
        local_state_data = DEFAULT_LOCAL_STATE_DATA
        local_state_data["profile"]["last_active_profiles"] = sessions
        with open(os.path.join(TMPDIR, "Local State"), 'w') as fd:
            fd.write(json.dumps(local_state_data, sort_keys=True))
        with open(os.path.join(TMPDIR, "Profile 1/Preferences"), 'w') as fd:
            fd.write(json.dumps(profile1_prefs, sort_keys=True))
        with open(os.path.join(TMPDIR, "Profile 2/Preferences"), 'w') as fd:
            fd.write(json.dumps(profile2_prefs, sort_keys=True))
        # Bookmarks data
        with open(os.path.join(TMPDIR, "Profile 1/Bookmarks"), 'w') as fd:
            fd.write(json.dumps(DEFAULT_BOOKMARKS_DATA, sort_keys=True))
        with open(os.path.join(TMPDIR, "Profile 2/Bookmarks"), 'w') as fd:
            fd.write(json.dumps(DEFAULT_BOOKMARKS_DATA, sort_keys=True))

        return TMPDIR
Ejemplo n.º 10
0
Archivo: art.py Proyecto: bagage/eolie
 def __create_cache(self):
     """
         Create cache dir
     """
     if not GLib.file_test(EOLIE_CACHE_PATH, GLib.FileTest.IS_DIR):
         try:
             GLib.mkdir_with_parents(EOLIE_CACHE_PATH, 0o0750)
         except Exception as e:
             Logger.error("Art::__create_cache(): %s", e)
Ejemplo n.º 11
0
    def __init__(self, connmgr, homedir=GLib.get_home_dir()):
        logging.debug("Constructing GSettingsLogger")

        self._testing_loop = None

        self.homedir = homedir
        self.connmgr = connmgr
        self.path_to_known_schema = {}
        self.relocatable_schemas = []
        self.past_keys_for_path = {}
        self.found_schemas_for_path = {}
        self.dconf_subscription_id = 0

        self.schema_source = Gio.SettingsSchemaSource.get_default()

        # Create file for LibreOffice dconf writes
        dconfwrite = Gio.File.new_for_path(
            os.path.join(self.homedir, self.LIBREOFFICE_DCONF_PATH))

        if not dconfwrite.query_exists(None):
            GLib.mkdir_with_parents(dconfwrite.get_parent().get_path(), 483)
            try:
                dconfwrite.create(Gio.FileCreateFlags.NONE, None)
            except Exception as e:
                logging.error(
                    "Could not create file %s: %s" % (
                        dconfwrite.get_path(), e))

        # Populate a table of paths to schema ids.  We can do this up
        # front for fixed-path schemas.  For relocatable schemas we have to
        # wait for a change to occur and then try to derive the schema from
        # the path and key(s) in the change notification.
        logging.debug("Caching known schemas")
        for schema_name in Gio.Settings.list_schemas():
        #for schema_name in self.schema_source.list_schemas(True):
            schema = self.schema_source.lookup(schema_name, True)
            path = schema.get_path()
            logging.debug("Adding schema %s: %s" % (path, schema_name))
            self.path_to_known_schema[path] = schema_name

        self.relocatable_schemas = Gio.Settings.list_relocatable_schemas()

        Gio.bus_watch_name(
            Gio.BusType.SESSION,
            self.BUS_NAME,
            Gio.BusNameWatcherFlags.NONE,
            self._bus_name_appeared_cb,
            self._bus_name_disappeared_cb)
    def __init__(self, connmgr, homedir=GLib.get_home_dir()):
        logging.debug("Constructing GSettingsLogger")

        self._testing_loop = None

        self.homedir = homedir
        self.connmgr = connmgr
        self.path_to_known_schema = {}
        self.relocatable_schemas = []
        self.past_keys_for_path = {}
        self.found_schemas_for_path = {}
        self.dconf_subscription_id = 0

        self.schema_source = Gio.SettingsSchemaSource.get_default()

        # Create file for LibreOffice dconf writes
        dconfwrite = Gio.File.new_for_path(
            os.path.join(self.homedir, self.LIBREOFFICE_DCONF_PATH))

        if not dconfwrite.query_exists(None):
            GLib.mkdir_with_parents(dconfwrite.get_parent().get_path(), 483)
            try:
                dconfwrite.create(Gio.FileCreateFlags.NONE, None)
            except Exception as e:
                logging.error(
                    "Could not create file %s: %s" % (
                        dconfwrite.get_path(), e))

        # Populate a table of paths to schema ids.  We can do this up
        # front for fixed-path schemas.  For relocatable schemas we have to
        # wait for a change to occur and then try to derive the schema from
        # the path and key(s) in the change notification.
        logging.debug("Caching known schemas")
        for schema_name in Gio.Settings.list_schemas():
        #for schema_name in self.schema_source.list_schemas(True):
            schema = self.schema_source.lookup(schema_name, True)
            path = schema.get_path()
            logging.debug("Adding schema %s: %s" % (path, schema_name))
            self.path_to_known_schema[path] = schema_name

        self.relocatable_schemas = Gio.Settings.list_relocatable_schemas()

        Gio.bus_watch_name(
            Gio.BusType.SESSION,
            self.BUS_NAME,
            Gio.BusNameWatcherFlags.NONE,
            self._bus_name_appeared_cb,
            self._bus_name_disappeared_cb)
Ejemplo n.º 13
0
    def add_clicked(self, sender):
        """
        Add or remove the bulb to the main list.
        """

        permissions = 0o664

        if self.added:
            for light in self.config_list:
                if light["mac"] == self.light.get_mac_addr():
                    self.config_list.remove(light)
                    self.added = False
        else:
            self.config_list.append({
                "ip": self.light.get_ip_addr(),
                "mac": self.light.get_mac_addr(),
                "label": self.light.get_label()
            })
            self.added = True

        if GLib.mkdir_with_parents(self.dest_file.get_parent().get_path(),
                                   permissions) == 0:
            (success, tag) = self.dest_file.replace_contents(
                str.encode(json.dumps(self.config_list)), None, False,
                Gio.FileCreateFlags.REPLACE_DESTINATION, None)

            if success:
                self.update_icon()
            else:
                print("Unable to save config file")
        else:
            print("Unable to create required directory/ies for config file")
Ejemplo n.º 14
0
    def new_folder_chooser (self, menuitem, window):
        dialog = self.newProjectDialogUI.get_object ("dialog-window")
        response = dialog.run ()

        if (response == Gtk.ResponseType.OK):
            filechooser = self.newProjectDialogUI.get_object ("filechooser-button")
            projectNameEntry = self.newProjectDialogUI.get_object ("project-name")
            self.listStore.clear ()
            projectName = projectNameEntry.get_text ()
            self.projectDir = filechooser.get_filename ()+"/"+projectName
            GLib.mkdir_with_parents (self.projectDir, 0755)
            self.projectConfig = isrProject.isrProject (self.projectDir+"/"+projectName+".isr", projectName)

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

        dialog.hide ()
Ejemplo n.º 15
0
    def __init__(self):
        super().__init__()

        self.playlist_path = GLib.build_filenamev(
            [GLib.get_user_data_dir(), "gnome-music", "playlists"])
        if not (GLib.file_test(self.playlist_path, GLib.FileTest.IS_DIR)):
            GLib.mkdir_with_parents(self.playlist_path, int("0755", 8))

        Grl.init(None)
        self.options = Grl.OperationOptions()
        self.options.set_resolution_flags(Grl.ResolutionFlags.FAST_ONLY
                                          | Grl.ResolutionFlags.IDLE_RELAY)

        self.full_options = Grl.OperationOptions()
        self.full_options.set_resolution_flags(
            Grl.ResolutionFlags.FULL | Grl.ResolutionFlags.IDLE_RELAY)

        self.props.sources = {}

        self.blacklist = [
            'grl-filesystem', 'grl-bookmarks', 'grl-metadata-store',
            'grl-podcasts', 'grl-spotify-cover'
        ]
        self.tracker = None
        self.changed_media_ids = []
        self.pending_event_id = 0
        self.changes_pending = {
            'Albums': False,
            'Artists': False,
            'Songs': False
        }
        self.pending_changed_medias = []

        self._thumbnail_sources = []
        self._thumbnail_sources_timeout = None

        self.registry = Grl.Registry.get_default()

        self._tracker_wrapper = TrackerWrapper()
        self.tracker_sparql = self._tracker_wrapper.props.tracker
        self._tracker_wrapper.bind_property(
            "tracker-available", self, "tracker-available",
            GObject.BindingFlags.BIDIRECTIONAL
            | GObject.BindingFlags.SYNC_CREATE)

        self._find_sources()
Ejemplo n.º 16
0
 def __init__(self):
     """
         Create database tables or manage update if needed
     """
     self.__cancellable = Gio.Cancellable.new()
     self.__task_helper = TaskHelper()
     # Lazy loading if not empty
     if not GLib.file_test(self.DB_PATH, GLib.FileTest.IS_REGULAR):
         try:
             if not GLib.file_test(EOLIE_DATA_PATH, GLib.FileTest.IS_DIR):
                 GLib.mkdir_with_parents(EOLIE_DATA_PATH, 0o0750)
             # Create db schema
             with SqlCursor(self) as sql:
                 sql.execute(self.__create_phishing)
                 sql.commit()
         except Exception as e:
             print("DatabasePhishing::__init__(): %s" % e)
Ejemplo n.º 17
0
 def __init__(self, suffix):
     """
         Create database tables or manage update if needed
         @param suffix as str
     """
     self.__DB_PATH = "%s/exceptions2_%s.db" % (EOLIE_DATA_PATH, suffix)
     self.__cancellable = Gio.Cancellable.new()
     if not GLib.file_test(self.__DB_PATH, GLib.FileTest.IS_REGULAR):
         try:
             if not GLib.file_test(EOLIE_DATA_PATH, GLib.FileTest.IS_DIR):
                 GLib.mkdir_with_parents(EOLIE_DATA_PATH, 0o0750)
             # Create db schema
             with SqlCursor(self) as sql:
                 sql.execute(self.__create_exceptions)
                 sql.commit()
         except Exception as e:
             print("DatabaseExceptions::__init__(): %s" % e)
Ejemplo n.º 18
0
 def do_install(self):
     podir = os.path.join(os.getcwd(), "po")
     done_one = False
     for root, subFolders, files in os.walk(podir, topdown=False):
         for file in files:
             parts = os.path.splitext(file)
             if parts[1] == '.po':
                 this_locale_dir = os.path.join(locale_inst, parts[0], 'LC_MESSAGES')
                 GLib.mkdir_with_parents(this_locale_dir, 0755)
                 print "/usr/bin/msgfmt -c %s -o %s" % (os.path.join(root, file), os.path.join(this_locale_dir, '%s.mo' % self.get_uuid()))
                 #subprocess.call(["msgfmt", "-c", os.path.join(root, file), "-o", os.path.join(this_locale_dir, '%s.mo' % self.get_uuid())])
                 done_one = True
     if done_one:
         print "Install complete for domain: %s" % self.get_uuid()
     else:
         print "Nothing installed"
     quit()
Ejemplo n.º 19
0
    def on_mnu_save_activate(self, widget, date=None):
        print "saveing"
        
        ## get the title for the note
        #title = self.ui.entry1.get_text()
        
        ##get the string
        #buff = self.ui.textview1.get_buffer()
        #start_iter = buff.get_start_iter()
        #end_iter = buff.get_end_iter()
        #text = buff.get_text(start_iter, end_iter, True)
        
        ##create the filename
        #data_dir = GLib.get_user_data_dir()
        #jotty_dir = os.path.join(data_dir, "jotty")
        #filename = os.path.join(jotty_dir, title)

        ##write the data
        #GLib.mkdir_with_parents(jotty_dir, 0o700)
        #GLib.file_set_contents(filename, text)
        
        #get the title from the user
        saver = SaveDialog()
        result = saver.run()
        title = saver.title_text()

        saver.destroy()
        if result != Gtk.ResponseType.OK:
            return

        #get the string
        buff = self.ui.textview1.get_buffer()
        start_iter = buff.get_start_iter()
        end_iter = buff.get_end_iter()
        text = buff.get_text(start_iter, end_iter, True)

        #create the filename
        data_dir = GLib.get_user_data_dir()
        jotty_dir = os.path.join(data_dir, "jotty")
        print title
        filename = os.path.join(jotty_dir, title)

        #write the data
        GLib.mkdir_with_parents(jotty_dir, 0o700)
        GLib.file_set_contents(filename, text)
Ejemplo n.º 20
0
    def __init__(self):
        super().__init__()

        self.playlist_path = GLib.build_filenamev([GLib.get_user_data_dir(),
                                                  "gnome-music", "playlists"])
        if not (GLib.file_test(self.playlist_path, GLib.FileTest.IS_DIR)):
            GLib.mkdir_with_parents(self.playlist_path, int("0755", 8))

        Grl.init(None)
        self.options = Grl.OperationOptions()
        self.options.set_resolution_flags(Grl.ResolutionFlags.FAST_ONLY |
                                          Grl.ResolutionFlags.IDLE_RELAY)

        self.full_options = Grl.OperationOptions()
        self.full_options.set_resolution_flags(Grl.ResolutionFlags.FULL |
                                               Grl.ResolutionFlags.IDLE_RELAY)

        self.props.sources = {}

        self.blacklist = [
            'grl-filesystem',
            'grl-bookmarks',
            'grl-metadata-store',
            'grl-podcasts',
            'grl-spotify-cover'
        ]
        self.tracker = None
        self.changed_media_ids = []
        self.pending_event_id = 0
        self.changes_pending = {'Albums': False, 'Artists': False, 'Songs': False}
        self.pending_changed_medias = []

        self._thumbnail_sources = []
        self._thumbnail_sources_timeout = None

        self.registry = Grl.Registry.get_default()

        self._tracker_wrapper = TrackerWrapper()
        self.tracker_sparql = self._tracker_wrapper.props.tracker
        self._tracker_wrapper.bind_property(
            "tracker-available", self, "tracker-available",
            GObject.BindingFlags.BIDIRECTIONAL |
            GObject.BindingFlags.SYNC_CREATE)

        self._find_sources()
Ejemplo n.º 21
0
    def on_mnu_save_activate(self, widget, date=None):
        print "saveing"

        ## get the title for the note
        #title = self.ui.entry1.get_text()

        ##get the string
        #buff = self.ui.textview1.get_buffer()
        #start_iter = buff.get_start_iter()
        #end_iter = buff.get_end_iter()
        #text = buff.get_text(start_iter, end_iter, True)

        ##create the filename
        #data_dir = GLib.get_user_data_dir()
        #jotty_dir = os.path.join(data_dir, "jotty")
        #filename = os.path.join(jotty_dir, title)

        ##write the data
        #GLib.mkdir_with_parents(jotty_dir, 0o700)
        #GLib.file_set_contents(filename, text)

        #get the title from the user
        saver = SaveDialog()
        result = saver.run()
        title = saver.title_text()

        saver.destroy()
        if result != Gtk.ResponseType.OK:
            return

        #get the string
        buff = self.ui.textview1.get_buffer()
        start_iter = buff.get_start_iter()
        end_iter = buff.get_end_iter()
        text = buff.get_text(start_iter, end_iter, True)

        #create the filename
        data_dir = GLib.get_user_data_dir()
        jotty_dir = os.path.join(data_dir, "jotty")
        print title
        filename = os.path.join(jotty_dir, title)

        #write the data
        GLib.mkdir_with_parents(jotty_dir, 0o700)
        GLib.file_set_contents(filename, text)
Ejemplo n.º 22
0
 def __init__(self):
     """
         Create database tables or manage update if needed
     """
     self.thread_lock = Lock()
     if not GLib.file_test(self.DB_PATH, GLib.FileTest.IS_REGULAR):
         try:
             if not GLib.file_test(EOLIE_DATA_PATH, GLib.FileTest.IS_DIR):
                 GLib.mkdir_with_parents(EOLIE_DATA_PATH, 0o0750)
             # Create db schema
             with SqlCursor(self) as sql:
                 sql.execute(self.__create_bookmarks)
                 sql.execute(self.__create_tags)
                 sql.execute(self.__create_bookmarks_tags)
                 sql.execute(self.__create_parents)
                 sql.commit()
         except Exception as e:
             print("DatabaseBookmarks::__init__(): %s" % e)
Ejemplo n.º 23
0
 def install(self):
     done_one = False
     for file in os.listdir("po"):
         parts = os.path.splitext(file)
         if parts[1] == ".po":
             this_locale_dir = os.path.join(locale_inst, parts[0],
                                            "LC_MESSAGES")
             GLib.mkdir_with_parents(this_locale_dir, 0o755)
             arguments = ("--check", os.path.join("po",
                                                  file), "--output-file",
                          os.path.join(this_locale_dir,
                                       "%s.mo" % self.md["uuid"]))
             self.call("msgfmt", arguments=arguments)
             done_one = True
     if done_one:
         print("Install complete for domain %s" % self.md["uuid"])
     else:
         print("Nothing installed")
Ejemplo n.º 24
0
    def on_mnu_save_activate(self, widget, data=None):
        #get the title for the note
        title = self.ui.entry1.get_text()

        #get the string
        buff = self.ui.textview1.get_buffer()
        start_iter = buff.get_start_iter()
        end_iter = buff.get_end_iter()
        text = buff.get_text(start_iter, end_iter, True)

        #create the filename
        data_dir = GLib.get_user_data_dir()
        jotty_dir = os.path.join(data_dir, "jotty")
        filename = os.path.join(jotty_dir, title)

        #write the data
        GLib.mkdir_with_parents(jotty_dir, 0o700)
        GLib.file_set_contents(filename, text)
Ejemplo n.º 25
0
    def create_changelogs(self):
        """create_changelogs

        Generate the CHANGE_LOG.md files for all xlets.
        """
        print(Ansi.YELLOW_BOLD("Generating change logs..."))

        logs_storage = os.path.join(self.root_path, "tmp", "changelogs")
        changelog_sanitizer_path = os.path.join(self.root_path, "tools",
                                                "changelog_handler", "changelog_sanitizer.py")

        GLib.mkdir_with_parents(logs_storage, 0o755)

        for xlet in self.xlets_meta.list:
            print(Ansi.GREEN_BOLD("Generating change log for %s..." % xlet["name"]))

            xlet_root_folder = get_parent_dir(xlet["meta-path"], 2)
            tmp_log_path = os.path.join(logs_storage, xlet["uuid"] + ".md")

            # Generate change log from current repository paths.
            relative_xlet_path1 = "./" + xlet["type"] + "s/" + xlet["uuid"]
            cmd1 = git_log_cmd.format(relative_xlet_path=relative_xlet_path1,
                                      append_or_override=">",
                                      tmp_log_path=tmp_log_path)
            self.exec_command(cmd=cmd1,
                              working_directory=self.root_path)

            # Generate change log from old repository paths (before repository rearrangement).
            # Then append them to the previously generated change log.
            relative_xlet_path2 = "./" + xlet["type"].capitalize() + "s/" + xlet["uuid"]
            cmd2 = git_log_cmd.format(relative_xlet_path=relative_xlet_path2,
                                      append_or_override=">>",
                                      tmp_log_path=tmp_log_path)
            self.exec_command(cmd=cmd2,
                              working_directory=self.root_path)

            # Sanitize and clean up formatting of the change logs and
            # copy them to their final destinations.
            cmd3 = '%s "%s" "%s" "%s/CHANGE_LOG.md"' % (changelog_sanitizer_path,
                                                        xlet["name"],
                                                        tmp_log_path,
                                                        xlet_root_folder)
            self.exec_command(cmd=cmd3,
                              working_directory=xlet_root_folder)
 def install(self):
     done_one = False
     for file in os.listdir("po"):
         parts = os.path.splitext(file)
         if parts[1] == '.po':
             this_locale_dir = os.path.join(locale_inst, parts[0], 'LC_MESSAGES')
             GLib.mkdir_with_parents(this_locale_dir, 0755)
             arguments = (
                 "--check",
                 os.path.join("po", file),
                 "--output-file",
                 os.path.join(this_locale_dir, "%s.mo" % self.md["uuid"])
             )
             self.call("msgfmt", arguments = arguments)
             done_one = True
     if done_one:
         print "Install complete for domain %s" % self.md["uuid"]
     else:
         print "Nothing installed"
Ejemplo n.º 27
0
    def finish_initializing(self, builder): # pylint: disable=E1002
        """Set up the main window"""
        super(PomidorWindow, self).finish_initializing(builder)

        self.AboutDialog = AboutPomidorDialog
        self.SettingsDialog = SettingsDialog

        # Code for other initialization actions should be added here.
        self.initialize_quicklist()

        self.timeout_id = None
        self.time = 0
        self.minimizeonclicked = 1
        self.say = Salert()

        self.pbutton = self.builder.get_object("pbutton")
        self.sbutton = self.builder.get_object("sbutton")
        self.lbutton = self.builder.get_object("lbutton")
        self.timelabel = self.builder.get_object("timelabel")

        # Optionally play sound
        userpath = GLib.get_user_data_dir()
        fullpath = userpath + "/pomidor/config" # plus app path

        # run only once when window initialized
        if  os.path.exists(fullpath):
            pass
        else:
            print "No file. Create file now."
            #  set True by deafault is sound notification enabled
            content = True
            s = str(content)

            # create the filename
            title = "config"
            data_dir = GLib.get_user_data_dir()
            pomidor_dir = os.path.join(data_dir, "pomidor")
            filename = os.path.join(pomidor_dir, title)

            # write the data
            GLib.mkdir_with_parents(pomidor_dir, 0o700)
            GLib.file_set_contents(filename, s)
Ejemplo n.º 28
0
 def __init__(self):
     """
         Create database tables or manage update if needed
     """
     upgrade = DatabaseUpgrade(Type.HISTORY)
     self.thread_lock = Lock()
     if not GLib.file_test(self.DB_PATH, GLib.FileTest.IS_REGULAR):
         try:
             if not GLib.file_test(EOLIE_DATA_PATH, GLib.FileTest.IS_DIR):
                 GLib.mkdir_with_parents(EOLIE_DATA_PATH, 0o0750)
             # Create db schema
             with SqlCursor(self) as sql:
                 sql.execute(self.__create_history)
                 sql.execute(self.__create_history_atime)
                 sql.execute(self.__create_history_orderby_idx)
                 sql.execute(self.__create_history_where_idx)
                 sql.execute("PRAGMA user_version=%s" % upgrade.version)
         except Exception as e:
             Logger.error("DatabaseHistory::__init__(): %s", e)
     else:
         upgrade.upgrade(self)
Ejemplo n.º 29
0
    def __init__(self):
        GObject.GObject.__init__(self)
        self.playlist_path = GLib.build_filenamev([GLib.get_user_data_dir(),
                                                  "gnome-music", "playlists"])
        if not (GLib.file_test(self.playlist_path, GLib.FileTest.IS_DIR)):
            GLib.mkdir_with_parents(self.playlist_path, int("0755", 8))
        self.options = Grl.OperationOptions()
        self.options.set_flags(Grl.ResolutionFlags.FULL |
                               Grl.ResolutionFlags.IDLE_RELAY)

        self.sources = {}
        self.tracker = None

        self.registry = Grl.Registry.get_default()
        self.registry.connect('source_added', self._on_source_added)
        self.registry.connect('source_removed', self._on_source_removed)

        try:
            self.registry.load_all_plugins()
        except GLib.GError:
            print('Failed to load plugins.')
Ejemplo n.º 30
0
 def do_install(self):
     podir = os.path.join(XLET_DIR, "po")
     done_one = False
     for root, subFolders, files in os.walk(podir, topdown=False):
         for file in files:
             parts = os.path.splitext(file)
             if parts[1] == ".po":
                 this_locale_dir = os.path.join(LOCALE_INST, parts[0],
                                                "LC_MESSAGES")
                 GLib.mkdir_with_parents(this_locale_dir, 0o755)
                 subprocess.run([
                     "msgfmt", "-c",
                     os.path.join(root, file), "-o",
                     os.path.join(this_locale_dir, "%s.mo" % XLET_UUID)
                 ])
                 done_one = True
     if done_one:
         print("Install complete for domain: %s" % XLET_UUID)
     else:
         print("Nothing installed")
     quit()
Ejemplo n.º 31
0
 def __init__(self):
     """
         Create database tables or manage update if needed
     """
     upgrade = DatabaseUpgrade(Type.BOOKMARK)
     self.thread_lock = Lock()
     if not GLib.file_test(self.DB_PATH, GLib.FileTest.IS_REGULAR):
         try:
             if not GLib.file_test(EOLIE_DATA_PATH, GLib.FileTest.IS_DIR):
                 GLib.mkdir_with_parents(EOLIE_DATA_PATH, 0o0750)
             # Create db schema
             with SqlCursor(self) as sql:
                 sql.execute(self.__create_bookmarks)
                 sql.execute(self.__create_tags)
                 sql.execute(self.__create_bookmarks_tags)
                 sql.execute(self.__create_parents)
                 sql.execute("PRAGMA user_version=%s" % upgrade.version)
         except Exception as e:
             Logger.error("DatabaseBookmarks::__init__(): %s", e)
     else:
         upgrade.upgrade(self)
Ejemplo n.º 32
0
 def create_db(self):
     """
         Create databse
     """
     if not GLib.file_test(EOLIE_DATA_PATH, GLib.FileTest.IS_DIR):
         GLib.mkdir_with_parents(EOLIE_DATA_PATH, 0o0750)
     # If DB schema changed, remove it
     if GLib.file_test(self.__DB_PATH, GLib.FileTest.IS_REGULAR):
         with SqlCursor(self) as sql:
             result = sql.execute("PRAGMA user_version")
             v = result.fetchone()
             if v is None or v[0] != self.__SCHEMA_VERSION:
                 f = Gio.File.new_for_path(self.__DB_PATH)
                 f.delete()
     if not GLib.file_test(self.__DB_PATH, GLib.FileTest.IS_REGULAR):
         try:
             # Create db schema
             with SqlCursor(self) as sql:
                 sql.execute(self.__create_adblock)
                 sql.execute(self.__create_adblock_re)
                 sql.execute(self.__create_adblock_re_domain)
                 sql.execute(self.__create_adblock_re_domain_ex)
                 sql.execute(self.__create_adblock_css)
                 sql.execute(self.__create_adblock_cache)
                 sql.execute(self.__create_adblock_idx)
                 sql.execute(self.__create_adblock_re_idx)
                 sql.execute(self.__create_adblock_re_domain_idx)
                 sql.execute(self.__create_adblock_re_domain_regex_idx)
                 sql.execute(self.__create_adblock_re_domain_ex_idx)
                 sql.execute(self.__create_adblock_re_domain_regex_ex_idx)
                 sql.execute(self.__create_adblock_css_black_idx)
                 sql.execute(self.__create_adblock_css_white_idx)
                 sql.execute(self.__create_adblock_cache_idx)
                 sql.execute("PRAGMA user_version=%s" %
                             self.__SCHEMA_VERSION)
         except Exception as e:
             Logger.error("DatabaseAdblock::__init__(): %s", e)
Ejemplo n.º 33
0
    def setup_test_directory(self, profinit=True, prefsinit=True):
        # Create a temporary directory for testing
        TMPDIR = GLib.dir_make_tmp("fc_logger_firefox_XXXXXX")
        logging.debug("Testing data at dir %s" % TMPDIR)
        # Create profiles file
        if profinit:
            self.file_set_contents(os.path.join(TMPDIR, "profiles.ini"),
                                   PROFILES_FILE_CONTENT)
        # Create profile directory
        self.assertEqual(
            0,
            GLib.mkdir_with_parents(os.path.join(TMPDIR, "robuvvg2.default"),
                                    0o755))

        # Initialize preferences file
        if prefsinit:
            self.file_set_contents(
                os.path.join(TMPDIR, "robuvvg2.default", "prefs.js"),
                RAW_PREFS_DATA)

        return TMPDIR
Ejemplo n.º 34
0
    def setup_test_directory(self, profinit=True, prefsinit=True):
        # Create a temporary directory for testing
        TMPDIR = GLib.dir_make_tmp("fc_logger_firefox_XXXXXX")
        logging.debug("Testing data at dir %s" % TMPDIR)
        # Create profiles file
        if profinit:
            self.file_set_contents(
                os.path.join(TMPDIR, "profiles.ini"),
                PROFILES_FILE_CONTENT)
        # Create profile directory
        self.assertEqual(
            0,
            GLib.mkdir_with_parents(
                os.path.join(TMPDIR, "robuvvg2.default"),
                0o755))

        # Initialize preferences file
        if prefsinit:
            self.file_set_contents(
                os.path.join(TMPDIR, "robuvvg2.default", "prefs.js"),
                RAW_PREFS_DATA)

        return TMPDIR
Ejemplo n.º 35
0
 def _cache_subtitles_dir():
     bpath = GLib.get_user_cache_dir()
     ret = os.path.join(bpath, 'totem', 'subtitles')
     GLib.mkdir_with_parents(ret, 0o777)
     return ret
Ejemplo n.º 36
0
    group.add_argument("-d",
                       "--dev",
                       help="Creates the help file into its final destination.",
                       action="store_true",
                       dest="dev",
                       default=False)

    options = parser.parse_args()

    if not (options.production or options.dev):
        parser.print_help()
        quit()

    help_file_path = None
    creation_type = None

    if options.production:
        creation_type = "production"
        help_file_path = os.path.join(XLET_DIR, "files", XLET_UUID, "HELP.html")
    elif options.dev:
        creation_type = "dev"
        repo_tmp_folder = os.path.join(repo_folder, "tmp", "help_files")
        GLib.mkdir_with_parents(repo_tmp_folder, 0o755)
        help_file_path = os.path.join(repo_tmp_folder, XLET_UUID + "-HELP.html")

    if help_file_path is not None:
        m = Main()
        m.creation_type = creation_type
        m.help_file_path = help_file_path
        m.do_dummy_install()
Ejemplo n.º 37
0
 def create_cache(self):
     if not os.path.isdir(CACHE_PATH):
         GLib.mkdir_with_parents(CACHE_PATH, 0o0755)
Ejemplo n.º 38
0
    def __init(self):
        """
            Init main application
        """
        self.settings = Settings.new()

        # Init extensions
        GLib.setenv("PYTHONPATH", self.__extension_dir, True)

        # Create favicon path
        if not GLib.file_test(self.__FAVICONS_PATH, GLib.FileTest.IS_DIR):
            GLib.mkdir_with_parents(self.__FAVICONS_PATH, 0o0750)

        # Add a global DBus helper
        self.helper = DBusHelper()
        # First init sync worker
        from eolie.mozilla_sync import SyncWorker
        if SyncWorker.check_modules():
            self.sync_worker = SyncWorker()
            # Run a first sync in 10 seconds, speed up app start
            GLib.timeout_add_seconds(10, self.sync_worker.sync, False)
            # Then run a sync every hour
            GLib.timeout_add_seconds(3600, self.sync_worker.sync, True)
        else:
            self.sync_worker = None
        if self.prefers_app_menu():
            menu = self.get_app_menu()
            self.set_app_menu(menu)
        cssProviderFile = Gio.File.new_for_uri(
            'resource:///org/gnome/Eolie/application.css')
        cssProvider = Gtk.CssProvider()
        cssProvider.load_from_file(cssProviderFile)
        screen = Gdk.Screen.get_default()
        styleContext = Gtk.StyleContext()
        styleContext.add_provider_for_screen(screen, cssProvider,
                                             Gtk.STYLE_PROVIDER_PRIORITY_USER)
        self.history = DatabaseHistory()
        self.bookmarks = DatabaseBookmarks()
        # We store cursors for main thread
        SqlCursor.add(self.history)
        SqlCursor.add(self.bookmarks)
        self.websettings = DatabaseSettings()
        self.adblock = DatabaseAdblock()
        self.adblock.update()
        self.phishing = DatabasePhishing()
        self.adblock_exceptions = DatabaseExceptions("adblock")
        # Do not remove this!
        self.update_default_style_sheet()
        self.popup_exceptions = DatabaseExceptions("popups")
        self.image_exceptions = DatabaseExceptions("images")
        if self.settings.get_user_value("jsblock") is not None:
            self.js_exceptions = DatabaseExceptions("js")
        else:
            self.js_exceptions = None
        self.phishing.update()
        self.art = Art()
        self.search = Search()
        self.download_manager = DownloadManager()
        self.pages_menu = PagesMenu()

        # Check MOZ_PLUGIN_PATH
        if self.settings.get_value('enable-plugins') and\
                not GLib.getenv("MOZ_PLUGIN_PATH"):
            print("You need to set MOZ_PLUGIN_PATH to use plugins")

        # https://wiki.ubuntu.com/Unity/LauncherAPI
        self.__unity = None
        if is_unity():
            try:
                gi.require_version('Unity', '7.0')
                from gi.repository import Unity
                self.__unity = Unity.LauncherEntry.get_for_desktop_id(
                    "org.gnome.Eolie.desktop")
            except:
                pass

        # Init profiles
        self.set_profiles()

        shortcut_action = Gio.SimpleAction.new('shortcut',
                                               GLib.VariantType.new('s'))
        shortcut_action.connect('activate', self.__on_shortcut_action)
        self.add_action(shortcut_action)
        self.set_accels_for_action("win.shortcut::expose", ["<Alt>e"])
        self.set_accels_for_action("win.exceptions::site", ["<Control>e"])
        self.set_accels_for_action("win.shortcut::show_left_panel", ["F9"])
        self.set_accels_for_action("win.shortcut::uri",
                                   ["<Control>l", "<Control>b"])
        self.set_accels_for_action("win.shortcut::new_page", ["<Control>t"])
        self.set_accels_for_action("win.shortcut::last_page",
                                   ["<Control><Shift>t"])
        self.set_accels_for_action("app.shortcut::new_window", ["<Control>n"])
        self.set_accels_for_action("win.shortcut::private",
                                   ["<Control><Shift>p"])
        self.set_accels_for_action("win.shortcut::close_page", ["<Control>w"])
        self.set_accels_for_action("win.shortcut::quit", ["<Control>q"])
        self.set_accels_for_action("win.shortcut::save", ["<Control><Shift>s"])
        self.set_accels_for_action("win.shortcut::filter", ["<Control>i"])
        self.set_accels_for_action("win.shortcut::reload",
                                   ["<Control>r", "F5"])
        self.set_accels_for_action("win.shortcut::home", ["<Control>Home"])
        self.set_accels_for_action("win.shortcut::find", ["<Control>f"])
        self.set_accels_for_action("win.shortcut::print", ["<Control>p"])
        self.set_accels_for_action("win.shortcut::source",
                                   ["<Control><Shift>c"])
        self.set_accels_for_action("win.shortcut::history", ["<Control>h"])
        self.set_accels_for_action("win.shortcut::search", ["<Control>k"])
        self.set_accels_for_action("win.shortcut::fullscreen", ["F11"])
        self.set_accels_for_action("app.settings", ["<Control>s"])
        self.set_accels_for_action("win.shortcut::backward",
                                   ["<Alt>Left", "XF86Back"])
        self.set_accels_for_action("win.shortcut::forward",
                                   ["<Alt>Right", "XF86Forward"])
        self.set_accels_for_action("win.shortcut::next",
                                   ["<Control>Tab", "<Control>Page_Down"])
        self.set_accels_for_action("win.shortcut::previous",
                                   ["<Control><Shift>Tab", "<Control>Page_Up"])
        self.set_accels_for_action("win.shortcut::next_site",
                                   ["<Control>twosuperior"])
        self.set_accels_for_action("win.shortcut::previous_site",
                                   ["<Control><Shift>twosuperior"])
        self.set_accels_for_action(
            "win.shortcut::zoom_in",
            ["<Control>KP_Add", "<Control>plus", "<Control>equal"])
        self.set_accels_for_action("win.shortcut::zoom_out",
                                   ["<Control>KP_Subtract", "<Control>minus"])
        self.set_accels_for_action("win.shortcut::zoom_default",
                                   ["<Control>KP_0", "<Control>0"])
Ejemplo n.º 39
0
 def create_new_dir (self, timeStamp):
     recordingDir = self.projectDir
     recordingDir += "/"+timeStamp+"/"
     GLib.mkdir_with_parents (recordingDir, 0755)
     return recordingDir
Ejemplo n.º 40
0
 def create_cache(self):
     if not os.path.isdir(CACHE_PATH):
         GLib.mkdir_with_parents(CACHE_PATH, 0o0755)
Ejemplo n.º 41
0
 def get_config_file(self):
     path = GLib.build_pathv(
         '/', (GLib.get_user_config_dir(), 'ga-dashlet', None))
     GLib.mkdir_with_parents(path, 0o700)
     return GLib.build_filenamev((path, 'settings.ini'))