Exemplo n.º 1
0
 def shutdown(self, signum, frame):
     self.streamer.terminate()
     self.scanner.terminate()
     config = GlobalConfig()
     config['last_shutdown_time'] = int(time.time())
     config.save()
     sys.exit(0)
Exemplo n.º 2
0
def save_directories():
    config = GlobalConfig()
    collection_paths = []
    if 'collection' in config and 'paths' in config['collection']:
        collection_paths = config['collection']['paths']

    paths = set()
    def parse_paths(root, base=''):
        """
        If class is jstree-undetermined
        some directory below it is checked so
        we have to crawl this level.

        If it is jstree-unchecked, don't bother

        If it is jstree-checked, we handle it, but
        we don't need to crawl lower.
        """

        if not 'class' in root['attr']:
            return

        if root['data'] == 'Computer' and base is '':
            if sys.platform == 'win32':
	        root['data'] = ''
	    else:
                root['data'] = '/'

        abspath = os.path.join(base, root['data'])

        if 'class' in root['attr'] and 'jstree-checked' in root['attr']['class']:
            paths.add(abspath)
            return
        elif 'class' in root['attr'] and 'jstree-undetermined' in root['attr']['class']:
            for cp in collection_paths:
                if cp.startswith(abspath):
                    paths.add(cp)

        if abspath in collection_paths and 'jstree-unchecked' in root['attr']['class']:
            collection_paths.remove(abspath)
            paths.remove(abspath)

        crawl = 'jstree-undetermined' in root['attr']['class']
        if crawl and 'children' in root:
            for child in root['children']:
                parse_paths(child, os.path.join(base, root['data']))

    listing = json.loads(request.data)
    parse_paths(listing[0])

    if not 'collection' in config:
        config['collection'] = {'paths': []}
    config['collection']['paths'] = list(paths)
    config['collection']['paths_saved_at'] = int(time.time())
    config.save()

    return jsonify(success=True)
Exemplo n.º 3
0
def change_password():
    try:
        input = sha256(request.form['password']).hexdigest()
        config = GlobalConfig()
        config['password'] = input
        config.save()
        flash("Password changed successfully.")
    except Exception:
        flash("Error changing password!", "error")
    return redirect(url_for('index'))
Exemplo n.º 4
0
    def quit(self, signum, frame):
        signal.signal(signal.SIGINT, signal.SIG_DFL)
        signal.signal(signal.SIGTERM, signal.SIG_DFL)
        # stop watching file before we make any changes
        self.observer.unschedule_all()
        self.observer.stop()
        # close all update threads
        # save current time
        config = GlobalConfig()
        try:
            config['collection']
        except KeyError:
            config['collection'] = {}
        now = int(time.time())
        config['collection']['last_scan'] = now
        config.save()

        self.scanner_pool.close()
        self.scanner_pool.terminate()

        self.observer.join()
        self.scanner_pool.join()
        sys.exit(0)