PageRenderTime 202ms CodeModel.GetById 80ms app.highlight 3ms RepoModel.GetById 118ms app.codeStats 0ms

/silverlining/mgr-scripts/restore-services.py

https://bitbucket.org/ianb/silverlining/
Python | 34 lines | 29 code | 4 blank | 1 comment | 6 complexity | 4391ec85d43fd48e4af2baa294434c57 MD5 | raw file
 1#!/usr/bin/env python
 2import sys
 3sys.path.insert(0, '/usr/local/share/silverlining/lib')
 4import os
 5import optparse
 6import shutil
 7from silversupport.appconfig import AppConfig
 8from silversupport import transfermethods
 9
10parser = optparse.OptionParser(
11    usage='%prog LOCAL_BACKUP LOCATION')
12parser.add_option(
13    '--keep', action='store_true',
14    help="Keep the archive after restoring")
15
16
17def main():
18    options, args = parser.parse_args()
19    local_backup = args[0]
20    location = args[1]
21    app_config = AppConfig.from_location(location)
22    if transfermethods.is_archive(local_backup):
23        dir = transfermethods.make_temp_name()
24        transfermethods.unarchive(local_backup, dir)
25        if not options.keep:
26            os.unlink(local_backup)
27            options.keep = False
28        local_backup = dir
29    app_config.restore_services(local_backup)
30    if not options.keep:
31        shutil.rmtree(local_backup)
32
33if __name__ == '__main__':
34    main()