Created
May 2, 2015 05:10
-
-
Save dgrant/4dc1f38f86c12368fae1 to your computer and use it in GitHub Desktop.
Synchronize music with a USB mp3 player
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
""" | |
Synchronize music with a portable device | |
""" | |
import os | |
import subprocess | |
from easygui import msgbox, choicebox, codebox, ynbox, diropenbox | |
def sync_music(): | |
"""Synchronize music with a portable device""" | |
device_filter = ['YP', 'usb', 'music'] | |
command = ['rsync', '-v', '-r'] | |
#get devices | |
df_output = subprocess.Popen(['/bin/df', '-h', '-l'], | |
stdout=subprocess.PIPE).communicate()[0] | |
lines = df_output.split('\n')[1:-1] | |
lines = [x.split() for x in lines] | |
devices = [] | |
for line in lines: | |
for device in device_filter: | |
if device in line[5]: | |
devices.append(line) | |
break | |
choices = [x[5]+" "+x[1] for x in devices] | |
choice = choicebox("Which device do you want to sync with?", | |
"Choose your device", | |
choices) | |
device_name = choice.split()[0] | |
msgbox("using "+choice) | |
delete = ynbox("delete files on device if not in local directory?", | |
"Delete files?") | |
if delete: | |
command += ['--delete'] | |
# Get source dir | |
src_dir = diropenbox(msg="Choose source dir", | |
title="Choose src dir", | |
default="~") | |
print src_dir | |
src_dir += os.path.sep | |
print src_dir | |
# Run rsync | |
command += [src_dir, device_name+'/Music'] | |
print 'running ' + ' '.join(command) | |
output = subprocess.Popen(command, | |
stdout=subprocess.PIPE, shell=True).communicate()[0] | |
codebox('Here is the log output', 'Summary', output) | |
def main(): | |
"""Main script""" | |
sync_music() | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment