This repository has been archived by the owner on Jan 25, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathbackup.py
64 lines (52 loc) · 1.63 KB
/
backup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
"""
Google backup
Usage:
backup.py gmail [--verbose] (all | <user>...)
backup.py calendar [--verbose] (all | <user>...)
backup.py drive [--verbose] (all | <user>...)
backup.py full [--verbose] (all | <user>...)
backup.py -h | --help
Options:
-h --help Show this screen.
--verbose More verbose output.
"""
import sys
from docopt import docopt
from .calendarbackup import CalendarBackup
from .drivebackup import DriveBackup
from .get_users import get_users
from .gmailbackup import GmailBackup
from .settings import DOMAIN
SERVICES = ["gmail", "calendar", "drive"]
def main():
""" Main method: parses command line arguments, fetch full list of users
and execute backups """
run_services = []
arguments = docopt(__doc__, version='Google Backup 0.1')
if arguments["full"]:
run_services.extend(SERVICES)
else:
for service in SERVICES:
if arguments[service]:
run_services.append(service)
if len(run_services) == 0 or len(arguments["<user>"]) == 0:
print(__doc__)
return 1
users = arguments["<user>"]
if "all" in arguments["<user>"]:
users = get_users(DOMAIN)
for service in run_services:
for user in users:
backup = None
if service == 'gmail':
backup = GmailBackup(user)
elif service == 'drive':
backup = DriveBackup(user)
elif service == 'calendar':
backup = CalendarBackup(user)
if backup:
backup.initialize()
backup.run()
return 0
if __name__ == '__main__':
sys.exit(main())