Skip to content

Instantly share code, notes, and snippets.

@dgrant
Created May 2, 2015 05:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dgrant/4dc1f38f86c12368fae1 to your computer and use it in GitHub Desktop.
Save dgrant/4dc1f38f86c12368fae1 to your computer and use it in GitHub Desktop.
Synchronize music with a USB mp3 player
#!/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