PageRenderTime 101ms CodeModel.GetById 60ms app.highlight 4ms RepoModel.GetById 36ms app.codeStats 0ms

/silverlining/mgr-scripts/prepare-temp.py

https://bitbucket.org/ianb/silverlining/
Python | 35 lines | 33 code | 1 blank | 1 comment | 0 complexity | f26701f19557798f937a2f5242d98d50 MD5 | raw file
 1#!/usr/bin/env python
 2import sys
 3sys.path.insert(0, '/usr/local/share/silverlining/lib')
 4import os
 5from optparse import OptionParser
 6from silversupport import appdata
 7from silversupport.shell import run
 8
 9parser = OptionParser(
10    usage="%prog TMP_LOCATION HOSTNAME APP_NAME",
11    description="""\
12Copy the application (or app instance) into the temporary location
13""")
14parser.add_option(
15    '--instance-name',
16    metavar='NAME',
17    help="A specific instance name to select")
18
19def main():
20    options, args = parser.parse_args()
21    tmp_location = args[0]
22    hostname = args[1]
23    app_name = args[2]
24    instance_name = options.instance_name
25    if not instance_name:
26        instance_name = appdata.instance_for_app_name(hostname, app_name)
27        if not instance_name:
28            print 'Error: No instance can be found under http://%s with the name %r' % (
29                hostname, app_name)
30    location = os.path.join('/var/www', instance_name)
31    run(['cp', '-arl', location, tmp_location])
32
33
34if __name__ == '__main__':
35    main()