USB Syncing

From XPUB & Lens-Based wiki
Revision as of 18:39, 13 January 2014 by Michael Murtaugh (talk | contribs) (Created page with "<source lang="python"> import os, time initial = set(os.listdir("/media")) while True: media = set(os.listdir("/media")) new = media.difference(initial) if (len(...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
import os, time

initial = set(os.listdir("/media"))

while True:
    media = set(os.listdir("/media"))
    new = media.difference(initial)
    if (len(new) == 2):
        sticks = list(new)
        print "TIME TO SYNC"
        os.system("mplayer -loop 0 sticksync/sync.ogg &")

        # rsync 0 => 1
        cmd = "rsync -rv /media/{0}/ /media/{1}/ ".format(sticks[0], sticks[1])
        print cmd
        os.system(cmd)

        # rsync 1 => 0
        cmd = "rsync -rv /media/{1}/ /media/{0}/ ".format(sticks[0], sticks[1])
        print cmd
        os.system(cmd)
        os.system("killall mplayer")

        while True:
            print "waiting for less than two sticks"
            media = set(os.listdir("/media"))
            new = media.difference(initial)
            if (len(new) < 2):
                break
            time.sleep(1)

        # os.system(cmd)
    else:
        print "nothing to do"

    time.sleep(1)

https://archive.org/details/EqueTheartoflisteningSync

Auto login on pi: http://stackoverflow.com/questions/17830333/start-raspberry-pi-without-login