def remove_palette(self, palette_name): filepath = os.path.join(self.app.appdata.app_palette_dir, config.palette_files[palette_name]) if fsutils.isfile(filepath): fsutils.remove(filepath) del self.palettes[palette_name] del config.palette_files[palette_name]
def make_backup(doc_file, export=False): if not export and not config.make_backup: return if export and not config.make_export_backup: return if fsutils.exists(doc_file): if fsutils.exists(doc_file + '~'): fsutils.remove(doc_file + '~') fsutils.rename(doc_file, doc_file + '~')
def remove_profile(self): index = self.viewer.get_active() name = self.pf_list[index] filename = self.profiles[name] dst_dir = self.app.appdata.app_color_profile_dir dst = os.path.join(dst_dir, filename) if fsutils.isfile(dst): fsutils.remove(dst) self.profiles.pop(name) self.apply_changes() self.viewer.set_active(index - 1)
def load_palettes(self): paldir = self.app.appdata.app_palette_dir loader = get_loader_by_id(uc2const.SKP) for item in config.palette_files.keys(): filepath = os.path.join(paldir, config.palette_files[item]) try: self.palettes[item] = loader(self.app.appdata, filepath, False, False, True) except Exception: if fsutils.isfile(filepath): fsutils.remove(filepath) del config.palette_files[item]
def check_server(cfgdir): cfg_dir = os.path.join(cfgdir, '.config', 'sk1-wx') lock = os.path.join(cfg_dir, 'lock') if config.app_server and fsutils.exists(lock): socket = os.path.join(cfg_dir, 'socket') with fsutils.uopen(socket, 'wb') as fp: for item in sys.argv[1:]: fp.write('%s\n' % item) time.sleep(2) if fsutils.exists(socket): fsutils.remove(socket) else: sys.exit(0)
def on_timer(self, *_args): if fsutils.exists(self.socket): self.mw.raise_window() with fsutils.uopen(self.socket, 'rb') as fp: lines = fp.readlines() fsutils.remove(self.socket) [ self.app.open(item.strip('\n')) for item in lines if fsutils.exists(item.strip('\n')) ] if not fsutils.exists(self.lock): with fsutils.uopen(self.lock, 'wb') as fp: fp.write('\n')
def change_config(options): config = uc2.config if len(options) < 2: echo('Please provide configuration values to change.') return for key, value in options.items(): if key in BOOL_ATTRS: config.__dict__[key] = bool(value) elif key == 'log_level': if value in LEVELS: config.log_level = value elif key in INTENT_ATTRS: if isinstance(value, int) and value in INTENTS: config.__dict__[key] = value elif value in INTENTS: config.__dict__[key] = INTENTS[value] elif key in PROFILES and isinstance(value, str): if not value: config.__dict__[key] = '' continue cs = uc2const.COLORSPACES[PROFILES.index(key)] path = fsutils.normalize_path(value) if not fsutils.exists(path): echo('ERROR: file "%s" is not found!' % path) continue profile_name = cms.get_profile_name(path) if not profile_name: echo('ERROR: file "%s" is not valid color profile!' % path) continue profile_dir = config.app.appdata.app_color_profile_dir dest_path = os.path.join(profile_dir, '%s.icc' % cs) if fsutils.exists(dest_path): fsutils.remove(dest_path) fsutils.copy(path, dest_path) profile_dict = PROFILE_DICTS[PROFILES.index(key)] config.__dict__[profile_dict] = {profile_name: dest_path} config.__dict__[key] = profile_name
def destroy(self): if fsutils.exists(self.lock): fsutils.remove(self.lock) if self.timer.is_running(): self.timer.stop()