Partial fix for displaying mentors and students on Organization home page.
[Melange.git] / scripts / gen_app_yaml.py
blob22bb80dbd79c2589d0d2ee57265a8d08b4ab1747
1 #! /usr/bin/python2.5
3 # Copyright 2009 the Melange authors.
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
17 """A script to generate the app.yaml from the template with an application
18 name filled in.
20 Usage:
21 gen_app_yaml.py [-f] APPLICATION_NAME
23 Arguments:
24 APPLICATION_NAME: the name to use for the application (no underscores)
26 Flags:
27 -f: overwrite an existing app.yaml (default=false)
28 """
30 from __future__ import with_statement
32 __authors__ = [
33 # alphabetical order by last name, please
34 '"Dan Bentley" <dbentley@google.com>',
38 import os
39 import sys
42 def generateAppYaml(application_name, force=False):
43 """Generate the app.yaml file.
45 Args:
46 application_name: str, the name to write into the application filed
47 force: bool, whether to overwrite an existing app.yaml
48 """
50 scripts_directory = os.path.dirname(__file__)
51 app_dir = os.path.abspath(os.path.join(scripts_directory, '../app'))
52 template_path = os.path.join(app_dir, 'app.yaml.template')
53 app_yaml_path = os.path.join(app_dir, 'app.yaml')
55 if not os.path.exists(template_path):
56 sys.exit("Template file %s non-existent. Corrupt client?" % template_path)
58 if os.path.exists(app_yaml_path):
59 if not force:
60 sys.exit("%s exists; exiting. To overwrite, pass -f on the command-line"
61 % app_yaml_path)
63 with open(template_path) as infile:
64 template_contents = infile.read()
66 app_yaml_contents = template_contents.replace(
67 '# application: FIXME',
68 'application: '+ application_name)
70 with open(app_yaml_path, 'w') as outfile:
71 outfile.write(app_yaml_contents)
73 print "Wrote application name %s to %s." % (application_name, app_yaml_path)
76 def usage(msg):
77 """Print an error message and the usage of the program; then quit.
78 """
80 sys.exit('Error: %s\n\n%s' % (msg, __doc__))
83 def main(args):
84 """Main program.
85 """
87 if not args:
88 usage("No arguments supplied.")
90 if args[0] == '-f':
91 force = True
92 args = args[1:]
93 else:
94 force = False
96 if len(args) != 1:
97 usage("No application name supplied.")
99 application_name = args[0]
100 generateAppYaml(application_name, force=force)
103 if __name__ == '__main__':
104 main(sys.argv[1:]) # strip off the binary name