import tarfile
import time
import os
import getpass
import paramiko
import arrow
curtime = time.strftime("%d-%b-%Y-%H", time.gmtime())

sshgetdrn = paramiko.SSHClient()

sshgetdrn.set_missing_host_key_policy(paramiko.AutoAddPolicy())

usrg = getpass.getuser()

sshgetdrn.connect('128.199.60.12', username='wcmckee')

sup = sshgetdrn.exec_command('uptime')

ouput = sshgetdrn.invoke_shell()

ouput.recv(1000)

ouput.send('uptime')

ouput.send('chdir /getsdrawn')

opftp = sshgetdrn.open_sftp()

for i in opftp.listdir('/home/wcmckee/getsdrawndotcom/'):
    print i

utc = arrow.utcnow()

"""
Explanation: TarPipe
This script creates a .tar.gz of certain folders and allows for easy search of the files backed up. 
Currently focus on on motion but getsdrawn would also help. 
TODO
ssh and tarpipe into redditgetsdrawn when it hits midnight on server time (GMT).
End of explanation
"""


print utc

utc.weekday()

utc.date()

utc.datetime

backdir = ('/home/' + usrg + '/backup-motion/')


if os.path.isdir(backdir) == True:
    print 'its true'
else:
    print 'its false'
    os.mkdir(backdir)

tar = tarfile.open(backdir + curtime + ".tar.gz", "w:gz")
tar.add("/home/wcmckee/mot/", arcname="TarName")
tar.close()
#os.rmdir('/home/shared/cam')

"""
Explanation: I want datetime printed as year-month-day-hour-min.
Currently shows on getsdrawn as : Updated Tue, 03 Feb 2015 19:00:12 +0000.
Folder format:
End of explanation
"""


