Example #1
0
    def get_cache_folder(self):
        cache_folder = "%s/.cinnamon/spices.cache/%s/" % (home,
                                                          self.collection_type)

        if not os.path.exists(cache_folder):
            rec_mkdir(cache_folder)
        return cache_folder
Example #2
0
    def install(self, uuid):
        # print "Start downloading and installation"
        title = self.index_cache[uuid]["name"]

        self.download_url = URL_SPICES_HOME + self.index_cache[uuid]["file"]
        self.current_uuid = uuid

        self.progress_button_activate.set_sensitive(False)
        self.progress_button_close.set_sensitive(False)
        self.progress_window.show()
        self.progress_window.set_title(_("Progress"))

        self.progresslabel.set_text(_("Installing %s...") % title)
        self.progressbar.set_fraction(0)

        executable_files = ["settings.py"]

        fd, filename = tempfile.mkstemp()
        f = os.fdopen(fd, "wb")
        try:
            self.download(f, filename)
            dest = os.path.join(self.install_folder, uuid)
            zip = zipfile.ZipFile(filename)
            zip.extractall(dest, self.get_members(zip))
            for file in self.get_members(zip):
                if file.filename in executable_files:
                    os.chmod(os.path.join(dest, file.filename), 0o755)
                elif file.filename[:3] == "po/":
                    parts = os.path.splitext(file.filename)
                    if parts[1] == ".po":
                        this_locale_dir = os.path.join(locale_inst, parts[0][3:], "LC_MESSAGES")
                        self.progresslabel.set_text(_("Installing translations for %s...") % title)
                        rec_mkdir(this_locale_dir)
                        # print "/usr/bin/msgfmt -c %s -o %s" % (os.path.join(dest, file.filename), os.path.join(this_locale_dir, '%s.mo' % uuid))
                        subprocess.call(
                            [
                                "msgfmt",
                                "-c",
                                os.path.join(dest, file.filename),
                                "-o",
                                os.path.join(this_locale_dir, "%s.mo" % uuid),
                            ]
                        )
                        self.progresslabel.set_text(_("Installing %s...") % title)

        except:
            return False

        self.progress_button_close.set_sensitive(True)
        self.progress_button_activate.set_sensitive(True)
        self.progress_button_abort.set_sensitive(False)
        self.progress_window.show()
Example #3
0
    def install(self, uuid):
        #print "Start downloading and installation"
        title = self.index_cache[uuid]['name']

        self.download_url = URL_SPICES_HOME + self.index_cache[uuid]['file'];
        self.current_uuid = uuid
        
        self.progress_button_activate.set_sensitive(False)
        self.progress_button_close.set_sensitive(False)
        self.progress_window.show()        

        self.progresslabel.set_text(_("Installing %s...") % title)
        self.progressbar.set_fraction(0)
        
        executable_files = ['settings.py']
        
        fd, filename = tempfile.mkstemp()
        f = os.fdopen(fd, 'wb')
        try:
            self.download(f, filename)
            dest = os.path.join(self.install_folder, uuid)
            zip = zipfile.ZipFile(filename)
            zip.extractall(dest, self.get_members(zip))
            for file in self.get_members(zip):
                if file.filename in executable_files:
                    os.chmod(os.path.join(dest, file.filename), 0o755)
                elif file.filename[:3] == 'po/':
                    parts = os.path.splitext(file.filename)
                    if parts[1] == '.po':
                       this_locale_dir = os.path.join(locale_inst, parts[0][3:], 'LC_MESSAGES')
                       self.progresslabel.set_text(_("Installing translations for %s...") % title)
                       rec_mkdir(this_locale_dir)
                       #print "/usr/bin/msgfmt -c %s -o %s" % (os.path.join(dest, file.filename), os.path.join(this_locale_dir, '%s.mo' % uuid))
                       subprocess.call(["msgfmt", "-c", os.path.join(dest, file.filename), "-o", os.path.join(this_locale_dir, '%s.mo' % uuid)])
                       self.progresslabel.set_text(_("Installing %s...") % title)

        except:
            return False

        self.progress_button_close.set_sensitive(True)
        self.progress_button_activate.set_sensitive(True)
        self.progress_button_abort.set_sensitive(False)
        self.progress_window.show()
Example #4
0
    def _load_cache(self):
        filename = os.path.join(self.cache_folder, 'index.json')
        if not os.path.exists(self.cache_folder):
            rec_mkdir(self.cache_folder)

        if not os.path.exists(filename):
            self.has_cache = False
            return
        else:
            self.has_cache = True

        self.updates_available = []
        f = open(filename, 'r')
        try:
            self.index_cache = json.load(f)
        except ValueError, detail:
            try:
                os.remove(filename)
            except:
                pass
            self.errorMessage(_("Something went wrong with the spices download.  Please try refreshing the list again."), str(detail))
Example #5
0
    def install(self, uuid, is_update, is_active):
        #print "Start downloading and installation"
        title = self.index_cache[uuid]['name']

        download_url = URL_SPICES_HOME + self.index_cache[uuid]['file'];
        self.current_uuid = uuid

        ui_thread_do(self.ui_installing_xlet, title)

        edited_date = self.index_cache[uuid]['last_edited']

        if not self.themes:
            fd, filename = tempfile.mkstemp()
            dirname = tempfile.mkdtemp()
            f = os.fdopen(fd, 'wb')
            try:
                self.download(f, filename, download_url)
                dest = os.path.join(self.install_folder, uuid)
                schema_filename = ""
                zip = zipfile.ZipFile(filename)
                zip.extractall(dirname, self.get_members(zip))
                for file in self.get_members(zip):
                    if not file.filename.endswith('/') and ((file.external_attr >> 16L) & 0o755) == 0o755:
                        os.chmod(os.path.join(dirname, file.filename), 0o755)
                    elif file.filename[:3] == 'po/':
                        parts = os.path.splitext(file.filename)
                        if parts[1] == '.po':
                           this_locale_dir = os.path.join(locale_inst, parts[0][3:], 'LC_MESSAGES')
                           ui_thread_do(self.progresslabel.set_text, _("Installing translations for %s...") % title)
                           rec_mkdir(this_locale_dir)
                           #print "/usr/bin/msgfmt -c %s -o %s" % (os.path.join(dest, file.filename), os.path.join(this_locale_dir, '%s.mo' % uuid))
                           subprocess.call(["msgfmt", "-c", os.path.join(dirname, file.filename), "-o", os.path.join(this_locale_dir, '%s.mo' % uuid)])
                           ui_thread_do(self.progresslabel.set_text, _("Installing %s...") % title)
                    elif "gschema.xml" in file.filename:
                        sentence = _("Please enter your password to install the required settings schema for %s") % (uuid)
                        if os.path.exists("/usr/bin/gksu") and os.path.exists("/usr/lib/cinnamon-settings/bin/installSchema.py"):
                            launcher = "gksu  --message \"<b>%s</b>\"" % sentence
                            tool = "/usr/lib/cinnamon-settings/bin/installSchema.py %s" % (os.path.join(dirname, file.filename))
                            command = "%s %s" % (launcher, tool)
                            os.system(command)
                            schema_filename = file.filename
                        else:
                            self.errorMessage(_("Could not install the settings schema for %s.  You will have to perform this step yourself.") % (uuid))
                file = open(os.path.join(dirname, "metadata.json"), 'r')
                raw_meta = file.read()
                file.close()
                md = json.loads(raw_meta)
                md["last-edited"] = edited_date
                if schema_filename != "":
                    md["schema-file"] = schema_filename
                raw_meta = json.dumps(md, indent=4)
                file = open(os.path.join(dirname, "metadata.json"), 'w+')
                file.write(raw_meta)
                file.close()
                if os.path.exists(dest):
                    shutil.rmtree(dest)
                shutil.copytree(dirname, dest)
                shutil.rmtree(dirname)
                os.remove(filename)

            except Exception, detail:
                ui_thread_do(self.progress_window.hide)
                try:
                    shutil.rmtree(dirname)
                    os.remove(filename)
                except:
                    pass
                if not self.abort_download:
                    self.errorMessage(_("An error occurred during installation or updating.  You may wish to report this incident to the developer of %s.\n\nIf this was an update, the previous installation is unchanged") % (uuid), str(detail))
                return False
Example #6
0
    def get_cache_folder(self):
        cache_folder = "%s/.cinnamon/spices.cache/%s/" % (home, self.collection_type)

        if not os.path.exists(cache_folder):
            rec_mkdir(cache_folder)
        return cache_folder
Example #7
0
    def _install(self, job):
        try:
            uuid = job['uuid']

            download_url = URL_SPICES_HOME + self.index_cache[uuid]['file'];
            self.current_uuid = uuid

            fd, ziptempfile = tempfile.mkstemp()
            f = os.fdopen(fd, 'wb')
            self._download(f, ziptempfile, download_url)
            zip = zipfile.ZipFile(ziptempfile)

            tempfolder = tempfile.mkdtemp()
            zip.extractall(tempfolder)

            uuidfolder = os.path.join(tempfolder, uuid)
            contents = os.listdir(uuidfolder)
            # do we need to check file permissions?
            #         os.chmod(os.path.join(dirname, file.filename), 0o755)

            # check integrity of the download

            if not self.themes:
                # Install spice localization files, if any
                if 'po' in contents:
                    po_dir = os.path.join(uuidfolder, 'po')
                    for file in os.listdir(po_dir):
                        if file.endswith('.po'):
                            lang = file.split(".")[0]
                            locale_dir = os.path.join(locale_inst, lang, 'LC_MESSAGES')
                            rec_mkdir(locale_dir)
                            subprocess.call(['msgfmt', '-c', os.path.join(po_dir, file), '-o', os.path.join(locale_dir, '%s.mo' % uuid)])

                # Install spice schema file, if any
                schema = [filename for filename in contents if 'gschema.xml' in filename]
                for filename in schema:
                    if os.path.exists('/usr/bin/gksu'):
                        message = _("Please enter your password to install the required settings schema for ") + uuid
                        path = os.path.join(uuidfolder, filename)
                        os.system('gksu  --message "<b>%s</b>" cinnamon-schema-install %s' % (message, path))
                    else:
                        self.errorMessage(_("Could not install the settings schema for %s.  You will have to perform this step yourself.") % (uuid))

            meta_path = os.path.join(uuidfolder, 'metadata.json')
            if self.themes and not os.path.exists(meta_path):
                md = {}
            else:
                file = open(meta_path, 'r')
                raw_meta = file.read()
                file.close()
                md = json.loads(raw_meta)

            if not self.themes and len(schema) > 0:
                md['schema-file'] = ','.join(schema)
            md['last-edited'] = self.index_cache[uuid]['last_edited']

            raw_meta = json.dumps(md, indent=4)
            file = open(meta_path, 'w+')
            file.write(raw_meta)
            file.close()

            dest = os.path.join(self.install_folder, uuid)
            if os.path.exists(dest):
                shutil.rmtree(dest)
            shutil.copytree(uuidfolder, dest)

        except Exception, detail:
            if not self.abort_download:
                self.errorMessage(_("An error occurred during the installation of %s. Please report this incident to its developer.") % uuid, str(detail))
            return False