OLD | NEW |
(Empty) | |
| 1 #!/usr/bin/python2.4 |
| 2 # Copyright 2009 Google Inc. |
| 3 # |
| 4 # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 # you may not use this file except in compliance with the License. |
| 6 # You may obtain a copy of the License at |
| 7 # |
| 8 # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 # |
| 10 # Unless required by applicable law or agreed to in writing, software |
| 11 # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 # See the License for the specific language governing permissions and |
| 14 # limitations under the License. |
| 15 |
| 16 # This script does substitution on a list of files for |
| 17 # version-specific information relating to the plugin. |
| 18 |
| 19 import os.path |
| 20 import re |
| 21 import sys |
| 22 |
| 23 gflags_dir = os.path.join('..', '..', 'third_party', 'gflags', 'python') |
| 24 sys.path.append(gflags_dir) |
| 25 |
| 26 import gflags |
| 27 |
| 28 FLAGS = gflags.FLAGS |
| 29 gflags.DEFINE_boolean('kill_switch', False, |
| 30 'Generate version numbers for kill switch binary.') |
| 31 |
| 32 gflags.DEFINE_boolean('name', False, |
| 33 'Print out the plugin name and exit.') |
| 34 |
| 35 gflags.DEFINE_boolean('description', False, |
| 36 'Print out the plugin description and exit.') |
| 37 |
| 38 gflags.DEFINE_boolean('mimetype', False, |
| 39 'Print out the plugin mime type and exit.') |
| 40 |
| 41 gflags.DEFINE_boolean('version', False, |
| 42 'Print out the plugin version and exit.') |
| 43 |
| 44 |
| 45 def GetDotVersion(version): |
| 46 return '%d.%d.%d.%d' % version |
| 47 |
| 48 def GetCommaVersion(version): |
| 49 return '%d,%d,%d,%d' % version |
| 50 |
| 51 def DoReplace(in_filename, out_filename, replacements): |
| 52 '''Replace the version number in the given filename with the replacements.''' |
| 53 if not os.path.exists(in_filename): |
| 54 raise Exception(r'''Input template file %s doesn't exist.''' % file) |
| 55 input_file = open(in_filename, 'r') |
| 56 input = input_file.read() |
| 57 input_file.close() |
| 58 for (source, target) in replacements: |
| 59 input = re.sub(source, target, input) |
| 60 |
| 61 output_file = open(out_filename, 'wb') |
| 62 output_file.write(input) |
| 63 output_file.close() |
| 64 |
| 65 def main(argv): |
| 66 try: |
| 67 files = FLAGS(argv) # Parse flags |
| 68 except gflags.FlagsError, e: |
| 69 print '%s.\nUsage: %s [<options>] [<input_file> <output_file>]\n%s' % \ |
| 70 (e, sys.argv[0], FLAGS) |
| 71 sys.exit(1) |
| 72 |
| 73 # Strip off argv[0] |
| 74 files = files[1:] |
| 75 |
| 76 # Get version string from o3d_version.py |
| 77 o3d_version_vars = {} |
| 78 if FLAGS.kill_switch: |
| 79 execfile('../installer/win/o3d_kill_version.py', o3d_version_vars) |
| 80 else: |
| 81 execfile('../installer/win/o3d_version.py', o3d_version_vars) |
| 82 |
| 83 plugin_version = o3d_version_vars['plugin_version'] |
| 84 sdk_version = o3d_version_vars['sdk_version'] |
| 85 |
| 86 # This name is used by Javascript to find the plugin therefore it must |
| 87 # not change. If you change this you must change the name in |
| 88 # samples/o3djs/util.js but be aware, changing the name |
| 89 # will break all apps that use o3d on the web. |
| 90 O3D_PLUGIN_NAME = 'O3D Plugin' |
| 91 O3D_PLUGIN_VERSION = GetDotVersion(plugin_version) |
| 92 O3D_PLUGIN_VERSION_COMMAS = GetCommaVersion(plugin_version) |
| 93 O3D_SDK_VERSION = GetDotVersion(sdk_version) |
| 94 O3D_SDK_VERSION_COMMAS = GetCommaVersion(sdk_version) |
| 95 O3D_PLUGIN_DESCRIPTION = '%s version:%s' % (O3D_PLUGIN_NAME, |
| 96 O3D_PLUGIN_VERSION) |
| 97 O3D_PLUGIN_MIME_TYPE = 'application/vnd.o3d.auto' |
| 98 |
| 99 if FLAGS.name: |
| 100 print '%s' % O3D_PLUGIN_NAME |
| 101 sys.exit(0) |
| 102 |
| 103 if FLAGS.description: |
| 104 print '%s' % O3D_PLUGIN_DESCRIPTION |
| 105 sys.exit(0) |
| 106 |
| 107 if FLAGS.mimetype: |
| 108 print '%s' % O3D_PLUGIN_MIME_TYPE |
| 109 sys.exit(0) |
| 110 |
| 111 if FLAGS.version: |
| 112 print '%s' % O3D_PLUGIN_VERSION |
| 113 sys.exit(0) |
| 114 |
| 115 plugin_replace_strings = [ |
| 116 ('@@@PluginName@@@', O3D_PLUGIN_NAME), |
| 117 ('@@@ProductVersionCommas@@@', O3D_PLUGIN_VERSION_COMMAS), |
| 118 ('@@@ProductVersion@@@', O3D_PLUGIN_VERSION), |
| 119 ('@@@PluginDescription@@@', O3D_PLUGIN_DESCRIPTION), |
| 120 ('@@@PluginMimeType@@@', O3D_PLUGIN_MIME_TYPE), |
| 121 ] |
| 122 |
| 123 if len(files) == 2: |
| 124 DoReplace(files[0], files[1], plugin_replace_strings) |
| 125 elif len(files) > 0: |
| 126 raise Exception(r'You must supply and input and output filename for ' |
| 127 r'replacement.') |
| 128 |
| 129 if __name__ == '__main__': |
| 130 main(sys.argv) |
OLD | NEW |