1#!/usr/bin/env python 2# Copyright (c) 2012 The Chromium Authors. All rights reserved. 3# Use of this source code is governed by a BSD-style license that can be 4# found in the LICENSE file. 5 6'''Tool to create a new, empty .grd file with all the basic sections. 7''' 8 9from grit.tool import interface 10from grit import constants 11from grit import util 12 13# The contents of the new .grd file 14_FILE_CONTENTS = '''\ 15<?xml version="1.0" encoding="UTF-8"?> 16<grit base_dir="." latest_public_release="0" current_release="1" 17 source_lang_id="en" enc_check="%s"> 18 <outputs> 19 <!-- TODO add each of your output files. Modify the three below, and add 20 your own for your various languages. See the user's guide for more 21 details. 22 Note that all output references are relative to the output directory 23 which is specified at build time. --> 24 <output filename="resource.h" type="rc_header" /> 25 <output filename="en_resource.rc" type="rc_all" /> 26 <output filename="fr_resource.rc" type="rc_all" /> 27 </outputs> 28 <translations> 29 <!-- TODO add references to each of the XTB files (from the Translation 30 Console) that contain translations of messages in your project. Each 31 takes a form like <file path="english.xtb" />. Remember that all file 32 references are relative to this .grd file. --> 33 </translations> 34 <release seq="1"> 35 <includes> 36 <!-- TODO add a list of your included resources here, e.g. BMP and GIF 37 resources. --> 38 </includes> 39 <structures> 40 <!-- TODO add a list of all your structured resources here, e.g. HTML 41 templates, menus, dialogs etc. Note that for menus, dialogs and version 42 information resources you reference an .rc file containing them.--> 43 </structures> 44 <messages> 45 <!-- TODO add all of your "string table" messages here. Remember to 46 change nontranslateable parts of the messages into placeholders (using the 47 <ph> element). You can also use the 'grit add' tool to help you identify 48 nontranslateable parts and create placeholders for them. --> 49 </messages> 50 </release> 51</grit>''' % constants.ENCODING_CHECK 52 53 54class NewGrd(interface.Tool): 55 '''Usage: grit newgrd OUTPUT_FILE 56 57Creates a new, empty .grd file OUTPUT_FILE with comments about what to put 58where in the file.''' 59 60 def ShortDescription(self): 61 return 'Create a new empty .grd file.' 62 63 def Run(self, global_options, my_arguments): 64 if not len(my_arguments) == 1: 65 print 'This tool requires exactly one argument, the name of the output file.' 66 return 2 67 filename = my_arguments[0] 68 with util.WrapOutputStream(open(filename, 'w'), 'utf-8') as out: 69 out.write(_FILE_CONTENTS) 70 print "Wrote file %s" % filename 71