forked from clintmod/macprefs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmacprefs
More file actions
executable file
·114 lines (96 loc) · 3.61 KB
/
macprefs
File metadata and controls
executable file
·114 lines (96 loc) · 3.61 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#!/usr/bin/env python3
import argparse
import sys
import logging as log
import config
from version import __version__
import dotfiles
import preferences
import shared_file_lists
import system_preferences
import ssh_files
import startup_items
import app_store_preferences
import internet_accounts
preference_choices = [
'system_preferences',
'startup_items',
'dotfiles',
'shared_file_lists',
'ssh_files',
'preferences',
'app_store_preferences',
'internet_accounts'
]
def backup(choices=[]):
if not choices or 'system_preferences' in choices:
system_preferences.backup()
if not choices or 'startup_items' in choices:
startup_items.backup()
if not choices or 'dotfiles' in choices:
dotfiles.backup()
if not choices or 'shared_file_lists' in choices:
shared_file_lists.backup()
if not choices or 'ssh_files' in choices:
ssh_files.backup()
if not choices or 'preferences' in choices:
preferences.backup()
if not choices or 'app_store_preferences' in choices:
app_store_preferences.backup()
if not choices or 'internet_accounts' in choices:
internet_accounts.backup()
print('Backup Complete.')
def restore(choices=[]):
if not choices or 'system_preferences' in choices:
system_preferences.restore()
if not choices or 'startup_items' in choices:
startup_items.restore()
if not choices or 'dotfiles' in choices:
dotfiles.restore()
if not choices or 'shared_file_lists' in choices:
shared_file_lists.restore()
if not choices or 'ssh_files' in choices:
ssh_files.restore()
if not choices or 'preferences' in choices:
preferences.restore()
if not choices or 'app_store_preferences' in choices:
app_store_preferences.restore()
if not choices or 'internet_accounts' in choices:
internet_accounts.restore()
print('Restore Complete.')
def invoke_func(args):
if args.func is not None:
if args.name == 'backup' or args.name == 'restore':
args.func(args.t)
else:
args.func()
def configure_logging(verbose):
if verbose > 0:
log.basicConfig(format="%(message)s", level=log.DEBUG)
log.debug('Verbose logging enabled')
else:
log.basicConfig(format="%(message)s", level=log.INFO)
def main():
backup_dir = config.get_macprefs_dir()
parser = argparse.ArgumentParser(
prog='macprefs', description='backup and restore mac system preferences')
parser.add_argument('--version', action='version', version=__version__)
parser.add_argument('--verbose', '-v', action='count', help='log everything to the console')
subparsers = parser.add_subparsers(title='commands', metavar='')
backup_parser = subparsers.add_parser(
'backup', help='backup preferences to ' + backup_dir)
backup_parser.set_defaults(name='backup', func=backup)
backup_parser.add_argument('-t', nargs='*', metavar='type', help='preferences you want to backup', choices=preference_choices, action="extend")
restore_parser = subparsers.add_parser(
'restore', help='restore preferences from ' + backup_dir)
restore_parser.set_defaults(name='restore', func=restore)
restore_parser.add_argument('-t', nargs='*', metavar='type', help='preferences you want to restore', choices=preference_choices, action="extend")
if len(sys.argv) == 1:
parser.print_help()
sys.exit(0)
args = parser.parse_args()
verbosity = 0 if args.verbose is None else args.verbose
configure_logging(verbosity)
invoke_func(args)
if __name__ == '__main__':
main()