Exemplo n.º 1
0
    def push_all(self):
        log.debug("push_all started with override = %s" % self.override)

        local_dir = os.path.join(sublime.packages_path(), "User")
        remote_dir = self.settings.get("sync_folder")

        local_data = self.find_files(local_dir)
        remote_data = self.find_files(remote_dir)

        # Get data of last sync
        last_data = tools.load_last_data()
        last_local_data = last_data.get("last_local_data", {})
        last_remote_data = last_data.get("last_remote_data", {})

        deleted_local_data = [
            key for key in last_local_data if key not in local_data
        ]
        deleted_remote_data = [
            key for key in last_remote_data if key not in remote_data
        ]

        log.debug("local_data: %s" % local_data)
        log.debug("remote_data: %s" % remote_data)
        log.debug("deleted_local_data: %s" % deleted_local_data)
        log.debug("deleted_remote_data: %s" % deleted_remote_data)

        diff = [{
            "type": "d",
            "key": key
        } for key in last_local_data if key not in local_data]
        for key, value in local_data.items():
            if key in deleted_remote_data:
                pass
            elif key not in remote_data:
                diff += [dict({"type": "c", "key": key}, **value)]
            elif int(value["version"]) > int(
                    remote_data[key]["version"]) or self.override:
                diff += [dict({"type": "m", "key": key}, **value)]

        for item in diff:
            self.push(item)

        # Set data for next last sync
        tools.save_last_data(last_local_data=self.find_files(local_dir),
                             last_remote_data=self.find_files(remote_dir))
Exemplo n.º 2
0
    def pull_package_control(self, last_data, previous_installed_packages,
                             installed_packages):
        # Save items to remove
        to_install = [
            item for item in installed_packages
            if item not in previous_installed_packages
        ]
        to_remove = [
            item for item in previous_installed_packages
            if item not in installed_packages
        ]

        log.debug("install: %s", to_install)
        log.debug("remove: %s", to_remove)

        # Check for old remove_packages
        remove_packages = last_data.get("remove_packages", [])
        remove_packages += [
            item for item in to_remove
            if item != "Package Control" and item not in remove_packages
        ]

        log.debug("remove_packages %s", remove_packages)

        if remove_packages:
            removed_packages = self.remove_packages(remove_packages)
        else:
            removed_packages = []

        # Check if new packages are available and run package cleanup to install missing packages
        if to_install:
            sublime.set_timeout(self.install_packages, 1000)

        tools.save_last_data(remove_packages=[
            item for item in remove_packages if item not in removed_packages
        ])
    def push_all(self):
        log.debug("push_all started with override = %s" % self.override)

        local_dir = os.path.join(sublime.packages_path(), "User")
        remote_dir = self.settings.get("sync_folder")

        local_data = self.find_files(local_dir)
        remote_data = self.find_files(remote_dir)

        # Get data of last sync
        last_data = tools.load_last_data()
        last_local_data = last_data.get("last_local_data", {})
        last_remote_data = last_data.get("last_remote_data", {})

        deleted_local_data = [key for key in last_local_data if key not in local_data]
        deleted_remote_data = [key for key in last_remote_data if key not in remote_data]

        log.debug("local_data: %s" % local_data)
        log.debug("remote_data: %s" % remote_data)
        log.debug("deleted_local_data: %s" % deleted_local_data)
        log.debug("deleted_remote_data: %s" % deleted_remote_data)

        diff = [{"type": "d", "key": key} for key in last_local_data if key not in local_data]
        for key, value in local_data.items():
            if key in deleted_remote_data:
                pass
            elif key not in remote_data:
                diff += [dict({"type": "c", "key": key}, **value)]
            elif int(value["version"]) > int(remote_data[key]["version"]) or self.override:
                diff += [dict({"type": "m", "key": key}, **value)]

        for item in diff:
            self.push(item)

        # Set data for next last sync
        tools.save_last_data(last_local_data=self.find_files(local_dir), last_remote_data=self.find_files(remote_dir))
    def pull_package_control(self, last_data, previous_installed_packages, installed_packages):
        # Save items to remove
        to_install = [item for item in installed_packages if item not in previous_installed_packages]
        to_remove = [item for item in previous_installed_packages if item not in installed_packages]

        log.debug("install: %s", to_install)
        log.debug("remove: %s", to_remove)

        # Check for old remove_packages
        remove_packages = last_data.get("remove_packages", [])
        remove_packages += [item for item in to_remove if item != "Package Control" and item not in remove_packages]

        log.debug("remove_packages %s", remove_packages)

        if remove_packages:
            removed_packages = self.remove_packages(remove_packages)
        else:
            removed_packages = []

        # Check if new packages are available and run package cleanup to install missing packages
        if to_install:
            sublime.set_timeout(self.install_packages, 1000)

        tools.save_last_data(remove_packages=[item for item in remove_packages if item not in removed_packages])
Exemplo n.º 5
0
    def push(self, item):
        log.debug("push started for %s" % item)

        local_dir = os.path.join(sublime.packages_path(), "User")
        remote_dir = self.settings.get("sync_folder")

        # Get data of last sync
        last_data = tools.load_last_data()
        last_local_data = last_data.get("last_local_data", {})
        last_remote_data = last_data.get("last_remote_data", {})

        # Skip if file was just copied
        try:
            if item["type"] == "c" or item["type"] == "m":
                if last_remote_data[item["key"]]["version"] == item["version"]:
                    log.debug("Already pushed")
                    return
        except:
            pass

        # Make target file path and dir
        target = os.path.join(remote_dir, item["key"])
        target_dir = os.path.dirname(target)

        if item["type"] == "c":

            if not os.path.isdir(target_dir):
                os.makedirs(target_dir)

            shutil.copy2(item["path"], target)
            log.info("Created %s" % target)
            if not log.isEnabledFor(logger.logging.INFO):
                print("Package Syncing: Created %s" % target)
            #
            last_local_data[item["key"]] = {
                "path": item["path"],
                "dir": item["dir"],
                "version": item["version"]
            }
            last_remote_data[item["key"]] = {
                "path": target,
                "dir": item["dir"],
                "version": item["version"]
            }

        elif item["type"] == "d":
            if os.path.isfile(target):
                os.remove(target)
                log.info("Deleted %s" % target)
                if not log.isEnabledFor(logger.logging.INFO):
                    print("Package Syncing: Deleted %s" % target)

            try:
                del last_local_data[item["key"]]
                del last_remote_data[item["key"]]
            except:
                pass

            # Check if dir is empty and remove it if
            if os.path.isdir(target_dir) and not os.listdir(target_dir):
                os.rmdir(target_dir)

        elif item["type"] == "m":
            if not os.path.isdir(target_dir):
                os.mkdir(target_dir)
            shutil.copy2(item["path"], target)
            log.info("Updated %s" % target)
            if not log.isEnabledFor(logger.logging.INFO):
                print("Package Syncing: Updated %s" % target)
            #
            last_local_data[item["key"]] = {
                "path": item["path"],
                "dir": item["dir"],
                "version": item["version"]
            }
            last_remote_data[item["key"]] = {
                "path": target,
                "dir": item["dir"],
                "version": item["version"]
            }

        # Set data for next last sync
        tools.save_last_data(last_local_data=last_local_data,
                             last_remote_data=last_remote_data)
Exemplo n.º 6
0
    def pull(self, item):
        log.debug("pull started for %s" % item)

        local_dir = os.path.join(sublime.packages_path(), "User")
        remote_dir = self.settings.get("sync_folder")

        # Get data of last sync
        last_data = tools.load_last_data()
        last_local_data = last_data.get("last_local_data", {})
        last_remote_data = last_data.get("last_remote_data", {})

        # Make target file path and directory
        target = os.path.join(local_dir, item["key"])
        target_dir = os.path.dirname(target)

        # Skip if file was just pushed
        try:
            if item["type"] == "c" or item["type"] == "m":

                # Check for an updated Package Control setting file and backup old file
                if item["key"] == "Package Control.sublime-settings":
                    previous_installed_packages = tools.load_installed_packages(
                        target)
                    installed_packages = tools.load_installed_packages(
                        item["path"])

                # Check if the watcher detects a file again
                if last_local_data[item["key"]]["version"] == item["version"]:
                    log.debug("Already pulled")
                    return
        except:
            pass

        # If a file was created
        if item["type"] == "c":

            if not os.path.isdir(target_dir):
                os.makedirs(target_dir)

            shutil.copy2(item["path"], target)
            log.info("Created %s" % target)
            if not log.isEnabledFor(logger.logging.INFO):
                print("Package Syncing: Created %s" % target)
            #
            last_local_data[item["key"]] = {
                "path": target,
                "dir": item["dir"],
                "version": item["version"]
            }
            last_remote_data[item["key"]] = {
                "path": item["path"],
                "dir": item["dir"],
                "version": item["version"]
            }

        # If a file was delated
        elif item["type"] == "d":
            if os.path.isfile(target):
                os.remove(target)
                log.info("Deleted %s" % target)
                if not log.isEnabledFor(logger.logging.INFO):
                    print("Package Syncing: Deleted %s" % target)

            try:
                del last_local_data[item["key"]]
                del last_remote_data[item["key"]]
            except:
                pass

            # Check if directory is empty and remove it if, just cosmetic issue
            if os.path.isdir(target_dir) and not os.listdir(target_dir):
                os.rmdir(target_dir)

        # If a file was modified
        elif item["type"] == "m":

            if not os.path.isdir(target_dir):
                os.mkdir(target_dir)
            shutil.copy2(item["path"], target)
            log.info("Updated %s" % target)
            if not log.isEnabledFor(logger.logging.INFO):
                print("Package Syncing: Updated %s" % target)
            #
            last_local_data[item["key"]] = {
                "path": target,
                "dir": item["dir"],
                "version": item["version"]
            }
            last_remote_data[item["key"]] = {
                "path": item["path"],
                "dir": item["dir"],
                "version": item["version"]
            }

        # Set data for next last sync
        tools.save_last_data(last_local_data=last_local_data,
                             last_remote_data=last_remote_data)

        if item["type"] != "d" and item[
                "key"] == "Package Control.sublime-settings":
            # Handle Package Control
            self.pull_package_control(last_data, previous_installed_packages,
                                      installed_packages)
    def push(self, item):
        log.debug("push started for %s" % item)

        local_dir = os.path.join(sublime.packages_path(), "User")
        remote_dir = self.settings.get("sync_folder")

        # Get data of last sync
        last_data = tools.load_last_data()
        last_local_data = last_data.get("last_local_data", {})
        last_remote_data = last_data.get("last_remote_data", {})

        # Skip if file was just copied
        try:
            if item["type"] == "c" or item["type"] == "m":
                if last_remote_data[item["key"]]["version"] == item["version"]:
                    log.debug("Already pushed")
                    return
        except:
            pass

        # Make target file path and dir
        target = os.path.join(remote_dir, item["key"])
        target_dir = os.path.dirname(target)

        if item["type"] == "c":

            if not os.path.isdir(target_dir):
                os.makedirs(target_dir)

            shutil.copy2(item["path"], target)
            log.info("Created %s" % target)
            if not log.isEnabledFor(logger.logging.INFO):
                print("Package Syncing: Created %s" % target)
            #
            last_local_data[item["key"]] = {"path": item["path"], "dir": item["dir"], "version": item["version"]}
            last_remote_data[item["key"]] = {"path": target, "dir": item["dir"], "version": item["version"]}

        elif item["type"] == "d":
            if os.path.isfile(target):
                os.remove(target)
                log.info("Deleted %s" % target)
                if not log.isEnabledFor(logger.logging.INFO):
                    print("Package Syncing: Deleted %s" % target)

            try:
                del last_local_data[item["key"]]
                del last_remote_data[item["key"]]
            except:
                pass

            # Check if dir is empty and remove it if
            if os.path.isdir(target_dir) and not os.listdir(target_dir):
                os.rmdir(target_dir)

        elif item["type"] == "m":
            if not os.path.isdir(target_dir):
                os.mkdir(target_dir)
            shutil.copy2(item["path"], target)
            log.info("Updated %s" % target)
            if not log.isEnabledFor(logger.logging.INFO):
                print("Package Syncing: Updated %s" % target)
            #
            last_local_data[item["key"]] = {"path": item["path"], "dir": item["dir"], "version": item["version"]}
            last_remote_data[item["key"]] = {"path": target, "dir": item["dir"], "version": item["version"]}

        # Set data for next last sync
        tools.save_last_data(last_local_data=last_local_data, last_remote_data=last_remote_data)
    def pull(self, item):
        log.debug("pull started for %s" % item)

        local_dir = os.path.join(sublime.packages_path(), "User")
        remote_dir = self.settings.get("sync_folder")

        # Get data of last sync
        last_data = tools.load_last_data()
        last_local_data = last_data.get("last_local_data", {})
        last_remote_data = last_data.get("last_remote_data", {})

        # Make target file path and directory
        target = os.path.join(local_dir, item["key"])
        target_dir = os.path.dirname(target)

        # Skip if file was just pushed
        try:
            if item["type"] == "c" or item["type"] == "m":

                # Check for an updated Package Control setting file and backup old file
                if item["key"] == "Package Control.sublime-settings":
                    previous_installed_packages = tools.load_installed_packages(target)
                    installed_packages = tools.load_installed_packages(item["path"])

                # Check if the watcher detects a file again
                if last_local_data[item["key"]]["version"] == item["version"]:
                    log.debug("Already pulled")
                    return
        except:
            pass

        # If a file was created
        if item["type"] == "c":

            if not os.path.isdir(target_dir):
                os.makedirs(target_dir)

            shutil.copy2(item["path"], target)
            log.info("Created %s" % target)
            if not log.isEnabledFor(logger.logging.INFO):
                print("Package Syncing: Created %s" % target)
            #
            last_local_data[item["key"]] = {"path": target, "dir": item["dir"], "version": item["version"]}
            last_remote_data[item["key"]] = {"path": item["path"], "dir": item["dir"], "version": item["version"]}

        # If a file was delated
        elif item["type"] == "d":
            if os.path.isfile(target):
                os.remove(target)
                log.info("Deleted %s" % target)
                if not log.isEnabledFor(logger.logging.INFO):
                    print("Package Syncing: Deleted %s" % target)

            try:
                del last_local_data[item["key"]]
                del last_remote_data[item["key"]]
            except:
                pass

            # Check if directory is empty and remove it if, just cosmetic issue
            if os.path.isdir(target_dir) and not os.listdir(target_dir):
                os.rmdir(target_dir)

        # If a file was modified
        elif item["type"] == "m":

            if not os.path.isdir(target_dir):
                os.mkdir(target_dir)
            shutil.copy2(item["path"], target)
            log.info("Updated %s" % target)
            if not log.isEnabledFor(logger.logging.INFO):
                print("Package Syncing: Updated %s" % target)
            #
            last_local_data[item["key"]] = {"path": target, "dir": item["dir"], "version": item["version"]}
            last_remote_data[item["key"]] = {"path": item["path"], "dir": item["dir"], "version": item["version"]}

        # Set data for next last sync
        tools.save_last_data(last_local_data=last_local_data, last_remote_data=last_remote_data)

        if item["type"] != "d" and item["key"] == "Package Control.sublime-settings":
            # Handle Package Control
            self.pull_package_control(last_data, previous_installed_packages, installed_packages)