def get_cache_folder(self, collect_type): cache_folder = "%s/.cinnamon/spices.cache/%s/" % (HOME_PATH, collect_type) if not os.path.exists(cache_folder): SystemTools.rec_mkdir(cache_folder) return cache_folder
def _uninstall_single(self, uuid, edited_date, collect_type): error = None install_folder = self.cache.get_install_folder(collect_type) self.EmitStatus("status-removing", _("Uninstalling %s...") % uuid) try: if collect_type != "theme": shutil.rmtree(os.path.join(install_folder, uuid)) # Uninstall spice localization files, if any if (os.path.exists(LOCALE_PATH)): i19_folders = os.listdir(LOCALE_PATH) for i19_folder in i19_folders: if os.path.isfile(os.path.join(LOCALE_PATH, i19_folder, "LC_MESSAGES", "%s.mo" % uuid)): os.remove(os.path.join(LOCALE_PATH, i19_folder, "LC_MESSAGES", "%s.mo" % uuid)) # Clean-up this locale folder SystemTools.removeEmptyFolders(os.path.join(LOCALE_PATH, i19_folder)) # Uninstall settings file, if any if (os.path.exists(os.path.join(SETTINGS_PATH, uuid))): shutil.rmtree(os.path.join(SETTINGS_PATH, uuid)) else: shutil.rmtree(os.path.join(install_folder, uuid)) except Exception: e = sys.exc_info()[1] error = _("Problem uninstalling %s. %s. You may need to manually remove it.") % (uuid, str(e)) self.EmitLogError(error)
def _download_file(self, url, path=None, reporthook=None, user_params=None): if self.abort_download > ABORT_NONE: raise Exception(_("Download aborted.")) fd, filename = tempfile.mkstemp() f = os.fdopen(fd, "wb") self._download_file_temp(url, f, filename, self.pending_downloads, reporthook, user_params) self.pending_downloads -= 1 if path and os.path.isfile(filename): shutil.copyfile(filename, path) os.remove(filename) filename = path if os.path.isfile(filename): SystemTools.set_propietary_id(filename, EFECTIVE_IDS[0], EFECTIVE_IDS[1]) SystemTools.set_mode(filename, EFECTIVE_MODE) return filename
def _save_log(self, image): print("Saving periodic log tar ...") # Save image save_path_name = self.periodic_save_dir + strftime("%Y%m%d_%H%M%S") cv2.imwrite(save_path_name + ".png", image) # Save json camera_settings = CameraTools.get_camera_settings(self.camera, silent=True) system_info = SystemTools.get_system_info(self.video, self) json_dict = {'Camera Settings': camera_settings, 'System Info': system_info} with open(save_path_name + '.json', 'w') as fp: json.dump(json_dict, fp, sort_keys=True, indent=4, cls=ExtendedJsonEncoder) # Tar with tarfile.open(save_path_name + '.tar', mode='w') as tar: for ext in [".png", ".json"]: tar.add(save_path_name + ext, arcname=(save_path_name + ext).split("/")[-1]) os.remove(save_path_name + ext) # Remove of too old log tars existing_logs = sorted(os.listdir(self.periodic_save_dir)) for file in existing_logs[:-50]: os.remove(self.periodic_save_dir + file)
try: import threading, Queue try: import urllib2 except: import urllib.request as urllib2 except Exception: e = sys.exc_info()[1] print(str(e)) #sys.exit(1) ABORT_NONE = 0 ABORT_ERROR = 1 ABORT_USER = 2 EFECTIVE_USER = SystemTools.get_user() EFECTIVE_IDS = [SystemTools.get_user_id(EFECTIVE_USER), SystemTools.get_group_id(EFECTIVE_USER)] EFECTIVE_MODE = SystemTools.get_standar_mode() HOME_PATH = SystemTools.get_home() class ThreadPool(): def __init__(self, max_process=1): self.max_process = max_process self.work_count = 0 def get_max_process(self): return self.max_process def execute_task_async(self, task, works, on_finished=None): #Wont bocking the main thread. threading.Thread(target = self._execute_task_pool,
def _install_single(self, uuid, name, file_path, edited_date, compressor, collect_type): error_title = uuid schema_filename = "" try: folder_path = tempfile.mkdtemp() compressor.set_collection(collect_type) compressor.extract_file(file_path, folder_path) if collect_type == "theme": # Check dir name - it may or may not be the same as the theme name from our spices data # Regardless, this will end up being the installed theme name, whether it matched or not data_path = os.path.join(folder_path, name) if not os.path.exists(data_path): title = os.listdir(folder_path)[0] # We assume only a single folder, the theme name data_path = os.path.join(folder_path, title) # Test for correct folder structure - look for cinnamon.css file = open(os.path.join(data_path, "cinnamon", "cinnamon.css"), "r") file.close() md = {} md["last-edited"] = edited_date md["uuid"] = uuid metadata_file = os.path.join(data_path, "cinnamon", "metadata.json") final_path = os.path.join(self.cache.get_install_folder(collect_type), name) else: error_title = uuid members = compressor.get_members() for file in members: file_locate = os.path.join(folder_path, file.filename) SystemTools.set_propietary_id(file_locate, EFECTIVE_IDS[0], EFECTIVE_IDS[1]) SystemTools.set_mode(file_locate, EFECTIVE_MODE) if file.filename[:3] == "po/": parts = os.path.splitext(file.filename) if parts[1] == ".po": this_locale_dir = os.path.join(LOCALE_PATH, parts[0][3:], "LC_MESSAGES") #self.progresslabel.set_text(_("Installing translations for %s...") % title) SystemTools.rec_mkdir(this_locale_dir, EFECTIVE_MODE, EFECTIVE_IDS) #print("/usr/bin/msgfmt -c %s -o %s" % (os.path.join(dest, file.filename), os.path.join(this_locale_dir, "%s.mo" % uuid))) mo_file = os.path.join(this_locale_dir, "%s.mo" % uuid) subprocess.call(["msgfmt", "-c", file_locate, "-o", mo_file]) SystemTools.set_propietary_id(mo_file, EFECTIVE_IDS[0], EFECTIVE_IDS[1]) SystemTools.set_mode(mo_file, EFECTIVE_MODE) #self.progresslabel.set_text(_("Installing %s...") % (title)) elif "gschema.xml" in file.filename: schema_filename = file.filename # Test for correct folder structure file = open(os.path.join(folder_path, "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 metadata_file = os.path.join(folder_path, "metadata.json") data_path = folder_path final_path = os.path.join(self.cache.get_install_folder(collect_type), uuid) raw_meta = json.dumps(md, indent=4) file = open(metadata_file, "w+") file.write(raw_meta) file.close() SystemTools.set_propietary_id(metadata_file, EFECTIVE_IDS[0], EFECTIVE_IDS[1]) SystemTools.set_mode(metadata_file, EFECTIVE_MODE) self.EmitStatus("status-cleaning-up", _("Cleaning up...")) self.EmitIcon("cinnamon-installer-cleanup") if os.path.exists(final_path): shutil.rmtree(final_path) shutil.copytree(data_path, final_path) shutil.rmtree(folder_path) os.remove(file_path) except Exception: e = sys.exc_info()[1] schema_filename = "" print("Error: " + str(e)) try: shutil.rmtree(folder_path) os.remove(file_path) except: pass if not self.abort_download: error = _("An error occurred during installation or updating of %s. %s. You may wish to report this incident to the developer.\nIf this was an update, the previous installation is unchanged") % (uuid, str(e)) self.EmitLogError(error) return schema_filename
sys.path.append(SETT_PATH) try: from XletInstallerModules import * from SettingsInstallerWidgets import * import InstallerProviders, SystemTools try: import json except ImportError: import simplejson as json except Exception: e = sys.exc_info()[1] print(str(e)) sys.exit(1) HOME_PATH = SystemTools.get_home() Gtk.IconTheme.get_default().append_search_path(os.path.join(DIR_PATH, "gui/img")) #Gtk.IconTheme.get_default().append_search_path("/usr/share/icons/hicolor/scalable/categories") class Module: def __init__(self, content_box): self.keywords = _("installer") self.name = "installer" self.fileName = "cs_installer" self.comment = _("Manage Cinnamon extensions and packages") self.category = "prefs" self.icon = "cinnamon-installer" self.sidePage = SidePage(_("Cinnamon Installer"), self.icon, self.keywords, content_box, module=self) #self.managerBuilder = Gtk.Builder() self.modules = {}
# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 # USA from __future__ import print_function from ExtensionInstallerCore import ExtensionSidePage from gi.repository import GObject from gi.repository.Gtk import SizeGroup, SizeGroupMode from SettingsInstallerWidgets import * import SystemTools ICON_SIZE = 48 HOME_PATH = SystemTools.get_home() #os.path.expanduser("~") def sortArr(listSA): #change to support python3 try: listSA.sort(lambda a, b: cmp(a[0].lower(), b[0].lower())) except: sorted(listSA, key=getKey) def sortVal(listS): try: listS.sort(lambda a, b: cmp(a.lower(), b.lower())) except: sorted(listS)