Exemplo n.º 1
0
class Scanner:
    def __init__(self, path):
        self.path = path
        self.queue = Queue.PriorityQueue()
        self.watcher = Watcher(path, self.queue)
        self.walker = Walker(path, self.queue, Settings.is_rescan_forced())
        self.reader = Reader(self.queue)
        self.validator = Validator(self.queue)

    def start(self):
        self.validator.start()
        self.watcher.start()
        self.walker.start()
        self.reader.start()

    def stop(self):
        self.watcher.stop()
        self.reader.stop()

        self.validator.join()
        self.walker.join()
        self.watcher.join()
        self.reader.join()
Exemplo n.º 2
0
def main(file_path=None, all_sync=False):
    inifile = cp.SafeConfigParser()
    inifile.read(os.getcwd() + "/confing.ini")

    """ load config file """
    host = inifile.get("receiver", "host")
    port = inifile.get("receiver", "port")
    user = inifile.get("receiver", "user")
    passwd = inifile.get("receiver", "passwd")
    header_path = inifile.get("file", "header_path")

    transfer = Transfer("ftp")
    transfer.inst.connect(host, port, user, passwd)

    if all_sync:
        syncdir = inifile.get("all_sync", "syncdir")
        walker = Walker(syncdir)
        w = walker.start()
        while True:
            try:
                file_path = w.next()
                remote_path = file_path.replace(header_path, "")
                dirname = os.path.dirname(remote_path)
                filename = os.path.basename(remote_path)
                send(transfer.inst, dirname, filename, file_path)
            except StopIteration:
                return

    if file_path:
        remote_path = file_path.replace(header_path, "")
        if remote_path[0] != "/":
            remote_path = "/" + remote_path
        dirname = os.path.dirname(remote_path)
        filename = os.path.basename(remote_path)

        """ Connection with remote server """
        send(transfer.inst, dirname, filename, file_path)