I wrote a small no-input python program to sync recent iTunes podcasts to a BlackBerry; it works great from a terminal but I would like to share it with my old man and whoever. The only output is dialogue as files copy. Is there a way to make a desktop or dock shortcut to something that runs in a shell? No suggestion is too obvious, I am just back to the Mac after ages away. Script posted below, any help very much appreciated.
PHP:
#!/usr/bin/python
import os, getpass, shutil
def getOSSpecificFilepath():
if os.path.exists('/boot/grub'):
return '/home/'+getpass.getuser()+'/podcasts/current/'
elif os.path.exists('/Users'):
return '/Users/'+getpass.getuser()+'/Music/iTunes/iTunes Music/Podcasts/'
elif os.path.exists(r'C:\\'):
return 'C:\\Users\\'+getpass.getuser()+'\\music\\itunes\\itunes music\\podcasts\\'
else:
print 'problem getting os specific filepath'
def getDevicepath():
if os.path.exists('/media/BB'):
return '/media/BB/BlackBerry/music/podcasts/'
elif os.name is 'posix':
return '/Volumes/BB/BlackBerry/music/Podcasts/'
elif os.name is 'nt':
return r'E:\\BlackBerry\\music\\Podcasts\\'
else:
print 'problem getting os device filepath'
def checkDevicepath():
if not os.path.exists(getDevicepath()):
os.mkdir(getDevicepath())
def allFiles(filepath, depth, flist=[]):
fpath=os.walk(filepath)
fpath=[item for item in fpath]
while depth < len(fpath):
for item in fpath[depth][-1]:
flist.append(fpath[depth][0]+os.sep+item)
depth+=1
return flist
def getFilelist():
a = getOSSpecificFilepath()
b = allFiles(a, 1)
return b
def getDevicelist():
a = getDevicepath()
b = os.walk(a)
c = [item for item in b]
return c[0][-1]
def getMtimeList(filelist):
tmplist = []
for item in filelist:
tmplist.append(os.stat(item).st_mtime)
return tmplist
def getMtimeDict(filelist):
tmpdict = {}
for item in filelist:
tmpdict[os.stat(item).st_mtime] = item
return tmpdict
def getUpdatedList(filelist, mtimelist, mtimedict):
tmplist = []
a = sorted(mtimelist)
for item in a:
tmplist.append(mtimedict[item])
return tmplist
def defaultCast():
a = getFilelist()
b = getMtimeList(a)
c = getMtimeDict(a)
d = getUpdatedList(a, b, c)
return d
def thoseThatFit(fulllist=defaultCast()):
counter = -1
tmplist = []
tmpnum = 0
targetsize = 1000000000
while tmpnum < targetsize:
tmplist.append(fulllist[counter])
tmpnum += os.stat(fulllist[counter]).st_size
if abs(counter) < len(fulllist):
counter -= 1
else:
return tmplist
break
return tmplist
def cpFunction():
dp = getDevicepath()
a = thoseThatFit()
b = getDevicelist()
c = [item.split(os.sep) for item in a]
c = [item[-1] for item in c]
counter=0
for item in b:
if item not in c:
try:
os.remove(dp+item)
print 'removed', item
except:
continue
while counter <= (len(a)-1):
if c[counter] in b:
counter+=1
elif 'm4v' in a[counter]:
counter+=1
else:
print 'adding', a[counter], '...'
shutil.copy2(a[counter], dp)
counter += 1
checkDevicepath()
cpFunction()