Exemplo n.º 1
0
    def start_watching(self):
        """Starts folder watching.

        Loads folders to watch from settings.
        """
        settings = Settings()
        webprint_dir = str(settings.getWebprintFolder())
        for (name, location) in settings.getInstalledPrinters():
            path = os.path.join(webprint_dir, str(location))
            self.observer.schedule(self.event_handler, path)
Exemplo n.º 2
0
    def build_webprint_dir(self):
        """Create print folders in the 'webprint' directory.

        Delete files and folders not listed in settings.
        Creates the webprint directory if it does not exist.
        Folder watching is temporarily stopped during this operation.
        """
        self.stop_watching()
        settings = Settings()
        webprint_dir = settings.getWebprintFolder()
        if not os.path.exists(webprint_dir):
            os.makedirs(webprint_dir)
        folders = [location for (name, location) in
                    settings.getInstalledPrinters()]
        ls = os.listdir(webprint_dir)
        for folder in folders:
            if folder not in ls:
                os.mkdir(os.path.join(webprint_dir, folder))
            else:
                ls.remove(folder)
        for item in ls:
            shutil.rmtree(os.path.join(webprint_dir, item))
        self.start_watching()