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
21 gen_app_yaml.py [-f] APPLICATION_NAME
24 APPLICATION_NAME: the name to use for the application (no underscores)
27 -f: overwrite an existing app.yaml (default=false)
30 from __future__
import with_statement
33 # alphabetical order by last name, please
34 '"Dan Bentley" <dbentley@google.com>',
42 def generateAppYaml(application_name
, force
=False):
43 """Generate the app.yaml file.
46 application_name: str, the name to write into the application filed
47 force: bool, whether to overwrite an existing app.yaml
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
):
60 sys
.exit("%s exists; exiting. To overwrite, pass -f on the command-line"
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
)
77 """Print an error message and the usage of the program; then quit.
80 sys
.exit('Error: %s\n\n%s' % (msg
, __doc__
))
88 usage("No arguments supplied.")
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