Comment/code cleanup, fix failing on multiple files in destination directory. Proper CLI args.
This commit is contained in:
parent
741c2effca
commit
a396e1457a
|
@ -1,4 +1,4 @@
|
||||||
# Sermon Upload v2.0 Alpha
|
# Sermon Upload v2.1 Alpha
|
||||||
|
|
||||||
import subprocess
|
import subprocess
|
||||||
from subprocess import call # We can do BASH in Python if needed.
|
from subprocess import call # We can do BASH in Python if needed.
|
||||||
|
@ -18,8 +18,7 @@ parser.add_argument("ssh")
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
def upload(scrdir, dstdir, key, ssh): # Input has to end in /
|
def upload(scrdir, dstdir, key, ssh): # Input has to end in /
|
||||||
|
# time.sleep(10) # Wait 10 seconds to make sure the machine is booted if we're doing auto. NOTE: Change to only run when auto is specified.
|
||||||
#time.sleep(10) # Wait 10 seconds.
|
|
||||||
os.chdir(scrdir) # Go to sermon directory.
|
os.chdir(scrdir) # Go to sermon directory.
|
||||||
list = sorted(glob.glob('*.mp3')) # Sort files alphabetically.
|
list = sorted(glob.glob('*.mp3')) # Sort files alphabetically.
|
||||||
mostrecent = list[-1] # Find most recent sermon
|
mostrecent = list[-1] # Find most recent sermon
|
||||||
|
@ -30,52 +29,43 @@ def upload(scrdir, dstdir, key, ssh): # Input has to end in /
|
||||||
|
|
||||||
copyfile(sermonsrc, sermondst) # Copy the sermon
|
copyfile(sermonsrc, sermondst) # Copy the sermon
|
||||||
|
|
||||||
# bash = subprocess.check_output('./sermon-upload.sh')
|
|
||||||
# print(bash)
|
|
||||||
os.chdir(dstdir) # Go to the directory where the sermon has been copied to
|
os.chdir(dstdir) # Go to the directory where the sermon has been copied to
|
||||||
os.system("export sermondst")
|
|
||||||
os.environ['sermondst'] = str(sermondst)
|
# Export some variables to BASH
|
||||||
# os.system(sermondst=sermondst)
|
|
||||||
#print(os.system("echo $sermondst"))
|
# os.popen("export sermondst")
|
||||||
os.system("export key")
|
os.environ['sermondst'] = sermondst
|
||||||
|
# os.popen("export key")
|
||||||
os.environ['key'] = key
|
os.environ['key'] = key
|
||||||
# os.system(key=key)
|
# os.popen("export ssh")
|
||||||
os.system("export ssh")
|
|
||||||
os.environ['ssh'] = ssh
|
os.environ['ssh'] = ssh
|
||||||
# os.system(ssh=ssh)
|
os.popen('rsync --update --progress -e "ssh -i $key" $mostrecent $ssh:$sermondst') # Upload the sermon.
|
||||||
os.system('rsync --update --progress -e "ssh -i $key" *.mp3 $ssh:$sermondst') # Upload the sermon.
|
# os.popen("export dstdir")
|
||||||
os.system("export dstdir")
|
|
||||||
os.environ['dstdir'] = dstdir
|
os.environ['dstdir'] = dstdir
|
||||||
# os.system(dstdir=dstdir)
|
# os.popen("export recentsermon") # Export the list to Python
|
||||||
# os.system("findsermon='ls $dstdir'")
|
recentsermon = os.popen('ssh -i $key $ssh ls $sermondst').read() # Get most recent sermon from destination server.
|
||||||
# os.system("export findsermon")
|
|
||||||
# os.environ['findsermon'] = 'ls $dstdir'
|
# recentsermon = recentsermon[-1:]
|
||||||
os.system("export recentsermon") # Export the list to Python
|
recentsermon = recentsermon.rstrip() # Strip whitespace at the end of the string.
|
||||||
# subprocess.call("ssh -i $key $ssh ls $dstdir")
|
# recentsermon = recentsermon.split(',')
|
||||||
recentsermon = os.popen('ssh -i $key $ssh ls $dstdir').read()
|
# print(recentsermon[-1])
|
||||||
# print(re.sub(' +', ' ', recentsermon))
|
# recentsermon = recentsermon[-1]
|
||||||
recentsermon = "".join(recentsermon.split()) # Strip whitespace.
|
# recentsermon = "".join(recentsermon.split()) # Strip whitespace.
|
||||||
# recentsermon = re.sub (r'([^(\s+)])', '', recentsermon)
|
|
||||||
# print(recentsermon)
|
|
||||||
# print(ser)
|
|
||||||
# os.system(sermons=$("ssh -i $key $ssh ls $dstdir"))
|
|
||||||
# os.environ["recentsermon"] # Set it to a variable
|
|
||||||
# comparesermon = ""
|
|
||||||
# for c in recentsermon:
|
|
||||||
# comparesermon = comparesermon + recentsermon[c] # Try to grab most recent sermon.
|
|
||||||
# print(recentsermon) # Print most recent sermon.
|
|
||||||
#print(recentsermon)
|
|
||||||
#print(mostrecent)
|
#print(mostrecent)
|
||||||
|
#print(recentsermon)
|
||||||
|
|
||||||
if str(mostrecent) == str(recentsermon): # If the most recent sermon uploaded matches the most recent sermon locally, we're good.
|
if recentsermon == sermondst:
|
||||||
|
|
||||||
notify2.init('Sermon Script')
|
# if str(mostrecent) == str(recentsermon): # If the most recent sermon uploaded matches the most recent sermon locally, we're good.
|
||||||
|
|
||||||
|
notify2.init('Sermon Script') # Notify user of success.
|
||||||
n = notify2.Notification("Sermon Uploaded",
|
n = notify2.Notification("Sermon Uploaded",
|
||||||
mostrecent
|
mostrecent
|
||||||
)
|
)
|
||||||
n.show()
|
n.show()
|
||||||
|
|
||||||
else: # Otherwise, something went wrong.
|
else: # Otherwise, something went wrong, say it failed.
|
||||||
|
|
||||||
notify2.init('Sermon Script')
|
notify2.init('Sermon Script')
|
||||||
n = notify2.Notification("Sermon Upload Failed",
|
n = notify2.Notification("Sermon Upload Failed",
|
||||||
|
@ -83,5 +73,5 @@ def upload(scrdir, dstdir, key, ssh): # Input has to end in /
|
||||||
)
|
)
|
||||||
n.show()
|
n.show()
|
||||||
|
|
||||||
|
upload(args.scrdir, args.dstdir, args.key, args.ssh)
|
||||||
#upload("/mnt/52265C99265C8041/Users/Berean-Sound/sermons", "/home/josh/sermons/2018", "/home/berean/sermons/.tempssh/temp", "sermons@bereanbibleutah.org")
|
#upload("/mnt/52265C99265C8041/Users/Berean-Sound/sermons", "/home/josh/sermons/2018", "/home/berean/sermons/.tempssh/temp", "sermons@bereanbibleutah.org")
|
||||||
#upload("/home/josh/Downloads/Downloads/", "/home/josh/Downloads/Downloads2/", "/home/josh/.ssh/id_rsa", "josh@127.0.0.1")
|
|
||||||
|
|
Loading…
Reference in New Issue