def create_temp_backup(): psync_settings = tools.get_psync_settings() try: if os.path.exists(tools.temp_backup_folder): shutil.rmtree(tools.temp_backup_folder, True) shutil.copytree(tools.user_settings_folder, tools.temp_backup_folder) for root, dirs, files in os.walk(tools.temp_backup_folder): for dir in dirs: if dir in psync_settings["ignore_dirs"]: shutil.rmtree(os.path.join(root, dir), True) for file in files: absolute_path = os.path.join(root, file) relative_path = os.path.relpath(absolute_path, tools.temp_backup_folder) include_matches = [ fnmatch.fnmatch(relative_path, p) for p in psync_settings["include_files"] ] ignore_matches = [ fnmatch.fnmatch(relative_path, p) for p in psync_settings["ignore_files"] ] if any(ignore_matches) or not any(include_matches): os.remove(absolute_path) except Exception as e: tools.log("PackageSync: Error while creating temp backup.", force=True) tools.log("PackageSync: Error message: %s" % str(e), force=True)
def create_temp_backup(): psync_settings = tools.get_psync_settings() try: if os.path.exists(tools.temp_backup_folder): shutil.rmtree(tools.temp_backup_folder, True) shutil.copytree(tools.user_settings_folder, tools.temp_backup_folder) for root, dirs, files in os.walk(tools.temp_backup_folder): for dir in dirs: if dir in psync_settings["ignore_dirs"]: shutil.rmtree(os.path.join(root, dir), True) for file in files: absolute_path = os.path.join(root, file) relative_path = os.path.relpath( absolute_path, tools.temp_backup_folder) include_matches = [ fnmatch.fnmatch(relative_path, p) for p in psync_settings["include_files"]] ignore_matches = [ fnmatch.fnmatch(relative_path, p) for p in psync_settings["ignore_files"]] if any(ignore_matches) or not any(include_matches): os.remove(absolute_path) except Exception as e: tools.log("PackageSync: Error while creating temp backup.", force=True) tools.log("PackageSync: Error message: %s" % str(e), force=True)
def run(self): psync_settings = tools.get_psync_settings() if psync_settings["prompt_for_location"] == False: zip_backup_path = psync_settings["zip_backup_path"] backup_path = None try: if zip_backup_path == "": backup_path = tools.default_zip_backup_path elif os.path.isfile(zip_backup_path): backup_path = zip_backup_path else: sublime.error_message( "Invalid path provided in user-settings. Please correct & then retry." ) backup_path = None except Exception as e: tools.log("PackageSync: Error while fetching backup path.", force=True) tools.log("PackageSync: Error message: %s" % str(e), force=True) self.restore_zip(backup_path) else: offline.prompt_parameters = { "mode": "restore", "type": "file", "window_context": self.window, "initial_text": tools.default_zip_backup_path, "operation_to_perform": self.restore_zip, "on_change": None, "on_cancel": tools.packagesync_cancelled } offline.prompt_for_location()
def get_sync_folder_on_done(path): if not os.path.isdir(path): os.makedirs(path) if os.path.isdir(path): if os.listdir(path): if sublime.ok_cancel_dialog( "Backup already exists @ %s \nReplace it?" % path, "Continue"): override = True else: self.window.show_input_panel( "Online Sync Folder", path, get_sync_folder_on_done, None, tools.packagesync_cancelled) return else: override = False # Adjust settings settings.set("online_sync_enabled", True) settings.set("online_sync_folder", path) # Reset last-run file for Package Control last_run_file = os.path.join(sublime.packages_path(), "User", "Package Control.last-run") if os.path.isfile(last_run_file): os.remove(last_run_file) # Reset last-run file for PackageSync last_run_file = os.path.join(sublime.packages_path(), "User", "PackageSync.last-run") if os.path.isfile(last_run_file): os.remove(last_run_file) sublime.save_settings("PackageSync.sublime-settings") sublime.status_message( "online_sync_folder has been set to \n %s" % path) # Restart watcher tools.pause_watcher(local=False) tools.stop_watcher(local=False) tools.start_watcher(tools.get_psync_settings(), local=False) # Run pkg_sync sublime.set_timeout( lambda: sublime.run_command("psync_online_sync", { "mode": ["pull", "push"], "override": override }), 1000) else: sublime.error_message("Invalid Path \n %s" % path) # Add an on_change listener sublime.set_timeout( lambda: settings.add_on_change("package_sync", tools. restart_watcher), 500)
def __init__(self, mode=["pull", "push"], override=False, item=None): psync_settings = tools.get_psync_settings() self.psync_settings = psync_settings self.mode = mode self.item = item self.override = override threading.Thread.__init__(self)
def run(self): s = sublime.load_settings("PackageSync.sublime-settings") s.set("online_sync_enabled", True) sublime.save_settings("PackageSync.sublime-settings") # Start watcher tools.start_watcher(tools.get_psync_settings()) # Run online package syncing module sublime.run_command("psync_online_sync", {"mode": ["pull", "push"]})
def restore_from_temp(): try: if tools.get_psync_settings()["preserve_packages"] == False: # Delete all existing user settings & restore from temp backup shutil.rmtree(tools.user_settings_folder, True) shutil.copytree(tools.temp_restore_folder, tools.user_settings_folder) else: for src_root, dirs, files in os.walk(tools.temp_restore_folder): dst_root = src_root.replace(tools.temp_restore_folder, tools.user_settings_folder) if not os.path.exists(dst_root): os.mkdir(dst_root) for file in files: src_file = os.path.join(src_root, file) dst_file = os.path.join(dst_root, file) if file == "Package Control.sublime-settings": new_installed_packages = [] with open(src_file, "r") as f: new_installed_packages = json.load( f)["installed_packages"] package_control_settings = sublime.load_settings( "Package Control.sublime-settings") current_installed_packages = package_control_settings.get( "installed_packages") for package_name in new_installed_packages: if package_name not in current_installed_packages: current_installed_packages.append(package_name) package_control_settings.set( "installed_packages", current_installed_packages) sublime.save_settings( "Package Control.sublime-settings") else: if os.path.exists(dst_file): os.remove(dst_file) shutil.move(src_file, dst_root) except Exception as e: tools.log("PackageSync: Error while restoring from backup.", force=True) tools.log("PackageSync: Error message: %s" % str(e), force=True)
def plugin_loaded(): tools.init_paths() s = sublime.load_settings("PackageSync.sublime-settings") s.clear_on_change("package_sync") s.add_on_change("package_sync", tools.restart_watcher) sublime.save_settings("PackageSync.sublime-settings") # Start watcher sublime.set_timeout( lambda: tools.start_watcher(tools.get_psync_settings()), 100) # Run online package syncing sublime.set_timeout( lambda: sublime.run_command("psync_online_sync", {"mode": ["pull", "push"]}), 1000)
def restore_from_temp(): try: if tools.get_psync_settings()["preserve_packages"] == False: # Delete all existing user settings & restore from temp backup shutil.rmtree(tools.user_settings_folder, True) shutil.copytree( tools.temp_restore_folder, tools.user_settings_folder) else: for src_root, dirs, files in os.walk(tools.temp_restore_folder): dst_root = src_root.replace( tools.temp_restore_folder, tools.user_settings_folder) if not os.path.exists(dst_root): os.mkdir(dst_root) for file in files: src_file = os.path.join(src_root, file) dst_file = os.path.join(dst_root, file) if file == "Package Control.sublime-settings": new_installed_packages = [] with open(src_file, "r") as f: new_installed_packages = json.load( f)["installed_packages"] package_control_settings = sublime.load_settings( "Package Control.sublime-settings") current_installed_packages = package_control_settings.get( "installed_packages") for package_name in new_installed_packages: if package_name not in current_installed_packages: current_installed_packages.append(package_name) package_control_settings.set( "installed_packages", current_installed_packages) sublime.save_settings( "Package Control.sublime-settings") else: if os.path.exists(dst_file): os.remove(dst_file) shutil.move(src_file, dst_root) except Exception as e: tools.log("PackageSync: Error while restoring from backup.", force=True) tools.log("PackageSync: Error message: %s" % str(e), force=True)
def run(self): psync_settings = tools.get_psync_settings() if psync_settings["prompt_for_location"] == False: list_backup_path = psync_settings["list_backup_path"] backup_path = None try: if list_backup_path == "": backup_path = tools.default_list_backup_path elif os.path.exists(list_backup_path): if sublime.ok_cancel_dialog( "Backup already exists @ %s \nReplace it?" % list_backup_path) == True: os.remove(list_backup_path) backup_path = list_backup_path else: backup_path = None elif os.path.isabs(os.path.dirname(list_backup_path)): backup_path = list_backup_path else: sublime.error_message( "Invalid path provided in user-settings. Please correct & then retry." ) backup_path = None except Exception as e: tools.log("PackageSync: Error while fetching backup path.", force=True) tools.log("PackageSync: Error message: %s" % str(e), force=True) self.backup_pkg_list(backup_path) else: offline.prompt_parameters = { "mode": "backup", "type": "file", "window_context": self.window, "initial_text": tools.default_list_backup_path, "operation_to_perform": self.backup_pkg_list, "on_change": None, "on_cancel": tools.packagesync_cancelled } offline.prompt_for_location()
def is_enabled(self): s = tools.get_psync_settings() return s.get("online_sync_enabled", False) and s.get( "online_sync_folder", False) and os.path.isdir( s.get("online_sync_folder"))
def is_enabled(self): s = tools.get_psync_settings() return s.get("online_sync_enabled", False) and s.get("online_sync_folder", False) != False
def is_enabled(self): s = tools.get_psync_settings() return not s.get("online_sync_enabled", False)