OnJava8-Examples/tools/backup.bat

54 lines
1.5 KiB
Batchfile
Raw Normal View History

2015-05-13 16:14:46 -07:00
@setlocal enabledelayedexpansion && py -3 -x "%~f0" %* & exit /b !ERRORLEVEL!
#start python code here
import zipfile
import datetime
import os, sys, shutil
from glob import glob
2015-05-16 11:37:29 -07:00
import pathlib
2015-05-13 16:14:46 -07:00
from pathlib import Path
2015-05-16 11:37:29 -07:00
import pprint
2015-05-16 16:31:08 -07:00
import msvcrt
2015-05-13 16:14:46 -07:00
2015-05-16 11:37:29 -07:00
root = Path('.').resolve().parent.parent
boxdir = root / r"Box Sync\TIJ4-ebook-Backups"
gdrive = root / "Google Drive" / "TIJ4RefreshedBackups"
idrive = root / "IDrive-Sync" / "TIJ4-ebook-Backups"
print(boxdir)
print(gdrive)
print(idrive)
2015-05-13 16:14:46 -07:00
2015-05-16 11:37:29 -07:00
def cp(src, dest, display=True):
if type(src) is pathlib.WindowsPath:
name = src.name
else:
name = src
if display:
print("copying", name)
print("to:", dest)
shutil.copy(str(src), str(dest))
2015-05-13 16:14:46 -07:00
now = datetime.datetime.now().strftime("%Y-%m-%d_%H-%M")
zip_file_name = 'TIJDirectorsCut-' + now + '.zip'
2015-05-16 11:37:29 -07:00
dest = boxdir / zip_file_name
print(dest)
tozip = ["Notes.txt", "backup.bat", "go.bat"] + glob("*.py") + glob("*.docx") + glob("*.docm")
2015-05-13 16:14:46 -07:00
2015-05-16 11:37:29 -07:00
with zipfile.ZipFile(str(dest), 'w') as myzip:
for f in tozip:
2015-05-13 16:14:46 -07:00
myzip.write(f)
2015-05-16 11:37:29 -07:00
cp(dest, gdrive)
cp(dest, idrive)
2015-05-13 16:14:46 -07:00
2015-05-16 11:37:29 -07:00
shortcut = Path(r"C:\Python34\Scripts")
tools = ["Examples.py", "Validate.py", "backup.bat", "go.bat", "StripLastBlankLine.py",
shortcut / "v.bat", shortcut / "e.bat"]
print("copying tools to Github")
for tool in tools:
cp(tool, root / "Documents" / "GitHub" / "TIJ-Directors-Cut" / "tools", False)
2015-05-13 16:14:46 -07:00
# Touch this file to indicate most recent update time:
os.utime("backup.bat", None)
2015-05-16 16:31:08 -07:00
msvcrt.getch()