Ejemplo n.º 1
0
    def list():
        """Get list all files to be synced when system is offline"""

        src = get_source_local()
        dest = get_source_server()
        cmd = "rsync -nvai --exclude='.*' {0} {1}".format(src, dest)

        historylist = os.popen(cmd).readlines()
        filelist = []

        for f in historylist:
            try:
                # TODO: Dev dependencies
                # path = f.split("SHRINK/")[1].replace("\n", "")
                # path = "Users/karthik/SHRINK/" + path

                # Rsync returns relative file paths with ownership info
                # appending to it, that occupies 10 characters
                path = f.replace(f[:10], '').replace("\n", "")
                path = "Users/karthik/SHRINK/" + path

                if not is_hidden(path) and os.path.isfile("/" + path):
                    filelist.append(path)
            except:
                print "Unable to process {0}".format(f)
                # print ""

        return filelist
Ejemplo n.º 2
0
def rsync(event):
    """Rsyncs locally created files to server"""
    src = get_source_local()
    dest = get_source_server()
    subprocess.call(['rsync', '-avzr', '--exclude', '.*', src, dest])

    if event.event_type == "created" and not event.is_directory:
        print "Sending..."
        post_file_creation(event.src_path)
Ejemplo n.º 3
0
def rsync(event):
    """Rsyncs locally created files to server"""
    src = get_source_local()
    dest = get_source_server()
    subprocess.call(['rsync', '-avzr', '--exclude', '.*', src, dest])

    if event.event_type == "created" and not event.is_directory:
        print "Sending..."
        post_file_creation(event.src_path)
Ejemplo n.º 4
0
 def download():
     """
         Pull down everything in server to local
         IMP: Will delete anything stored previously
     """
     # Sync everything in server to local
     src = get_source_server()
     dest = get_source_local()
     subprocess.call(
         ['rsync', '-avzr', '--exclude', '.*', '--delete-after', src, dest])
Ejemplo n.º 5
0
    def push():
        """Pushes new files created to server"""
        filelist = History.list()
        src = get_source_local()
        dest = get_source_server()
        subprocess.call(['rsync', '-avzr', '--exclude', '.*', src, dest])

        for filepath in filelist:
            # TODO: Dev dependencies
            print "Sending: "+filepath
            synclady.pigeon.post_file_creation("/" + filepath)
Ejemplo n.º 6
0
def clean_path(path):
    """
        Converts to local path to server path
        Ex,
            localpath => '/Users/username/SHRINK/'
            serverpath => '/shrinkdata/username/'

            path => '/Users/username/SHRINK/A'
            newpath => '/shrinkdata/username/A'
    """
    local_path = get_source_local()
    server_path = get_source_server_path()
    return path.replace(local_path, server_path, 1)
Ejemplo n.º 7
0
def clean_path(path):
    """
        Converts to local path to server path
        Ex,
            localpath => '/Users/username/SHRINK/'
            serverpath => '/shrinkdata/username/'

            path => '/Users/username/SHRINK/A'
            newpath => '/shrinkdata/username/A'
    """
    local_path = get_source_local()
    server_path = get_source_server_path()
    return path.replace(local_path, server_path, 1)
Ejemplo n.º 8
0
    def start(self):
        """Starts Watchdog file listener"""
        self.observer = Observer()
        path = get_source_local()
        self.observer.schedule(self, path=path, recursive=True)
        self.observer.start()
        print "* Running Synclady at {0} (Press CTRL+C to quit)".format(path)

        try:
            while True:
                time.sleep(1)
        except KeyboardInterrupt:
            self.observer.stop()
        self.observer.join()
Ejemplo n.º 9
0
    def resync():
        """
            Syncs local and server. This pushes locally created files when offline
            to server. After, brings down files and directory structure in server
            to local.
            IMP: Does not remember files/folders deleted locally when offline.
        """
        # Sync everything in local to server without deleting
        # This will bring everything that's been created when offline to server
        # Will not sync anything that's been deleted
        History.push()

        # Sync everything in server to local
        # This will bring everything that's been created when offline to local
        # Will delete file/folders after syncing
        src = get_source_server()
        dest = get_source_local()
        subprocess.call(['rsync', '-avzr', '--delete-after', '--exclude', '.*', src, dest])