combox

split and encrypted files between online file storage providers
git clone git://git.ricketyspace.net/combox.git
Log | Files | Refs

commit 2bb73ab1dba409e1fc76c7459e1dd0f0dad2792d
parent f319bd834dda521e18a05e15b8318fffeb097a5c
Author: Siddharth Ravikumar <sravik@bgsu.edu>
Date:   Wed, 14 Jan 2015 21:53:06 -0500

combox/events.py: contains the ComboxEventHandler which monitors and does the combox thing.

Diffstat:
combox/events.py | 78++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 78 insertions(+), 0 deletions(-)

diff --git a/combox/events.py b/combox/events.py @@ -0,0 +1,78 @@ +# Copyright (C) 2014 Combox author(s). See AUTHORS. +# +# This file is part of Combox. +# +# Combox is free software: you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Combox is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Combox (see COPYING). If not, see +# <http://www.gnu.org/licenses/>. + +import os +import logging + +from os import path + +from watchdog.events import FileSystemEventHandler + +from combox.crypto import split_and_encrypt +from combox.file import mk_nodedir, relative_path + +class ComboxEventHandler(FileSystemEventHandler): + """Monitors Combox directory for changes and does its crypto thing. + + """ + + def __init__(self, config): + """ + config: a dictinary which contains combox configuration. + """ + self.config = config + + logging.basicConfig(level=logging.INFO, + format='%(asctime)s - %(message)s', + datefmt='%Y-%m-%d %H:%M:%S') + + + def on_moved(self, event): + super(ComboxEventHandler, self).on_moved(event) + + type_ = 'directory' if event.is_directory else 'file' + logging.info("Moved %s: from %s to %s", type_, event.src_path, + event.dest_path) + + + def on_created(self, event): + super(ComboxEventHandler, self).on_created(event) + + if event.is_directory: + # creates a corresponding directory at the node dirs. + mk_nodedir(event.src_path, self.config) + else: + # file was created + split_and_encrypt(event.src_path, self.config) + # TODO: code for storing file info in YAML. + + type_ = 'directory' if event.is_directory else 'file' + logging.info("Created %s: %s", type_, event.src_path) + + + def on_deleted(self, event): + super(ComboxEventHandler, self).on_deleted(event) + + type_ = 'directory' if event.is_directory else 'file' + logging.info("Deleted %s: %s", type_, event.src_path) + + def on_modified(self, event): + super(ComboxEventHandler, self).on_modified(event) + + type_ = 'directory' if event.is_directory else 'file' + logging.info("Modified %s: %s", type_, event.src_path)