fd3237d20ec9ee6eeafa7e43aec52299a0bf9e76
1 # -*- coding: utf-8 -*-
3 from optparse
import OptionParser
, OptionGroup
6 class EpilogParser(OptionParser
):
7 def format_epilog(self
, formatter
):
12 """Return the command-line parser for the delete command."""
13 usage
= "usage: %prog [tx_options] delete OPTION [OPTIONS]"
15 "This command deletes translations for a resource in the remote server."
19 " To delete a translation:\n "
20 "$ tx delete -r project.resource -l <lang_code>\n\n"
21 " To delete a resource:\n $ tx delete -r project.resource\n"
23 parser
= EpilogParser(usage
=usage
, description
=description
, epilog
=epilog
)
25 "-r", "--resource", action
="store", dest
="resources", default
=None,
26 help="Specify the resource you want to delete (defaults to all)"
29 "-l","--language", action
="store", dest
="languages",
30 default
=None, help="Specify the translation you want to delete"
33 "--skip", action
="store_true", dest
="skip_errors", default
=False,
34 help="Don't stop on errors."
37 "-f","--force", action
="store_true", dest
="force_delete",
38 default
=False, help="Delete an entity forcefully."
44 """Return the command-line parser for the help command."""
45 usage
="usage: %prog help command"
46 description
="Lists all available commands in the transifex command"\
47 " client. If a command is specified, the help page of the specific"\
48 " command is displayed instead."
50 parser
= OptionParser(usage
=usage
, description
=description
)
55 """Return the command-line parser for the init command."""
56 usage
="usage: %prog [tx_options] init <path>"
57 description
="This command initializes a new project for use with"\
58 " transifex. It is recommended to execute this command in the"\
59 " top level directory of your project so that you can include"\
60 " all files under it in transifex. If no path is provided, the"\
61 " current working dir will be used."
62 parser
= OptionParser(usage
=usage
, description
=description
)
63 parser
.add_option("--host", action
="store", dest
="host",
64 default
=None, help="Specify a default Transifex host.")
65 parser
.add_option("--user", action
="store", dest
="user",
66 default
=None, help="Specify username for Transifex server.")
67 parser
.add_option("--pass", action
="store", dest
="password",
68 default
=None, help="Specify password for Transifex server.")
73 """Return the command-line parser for the pull command."""
74 usage
="usage: %prog [tx_options] pull [options]"
75 description
="This command pulls all outstanding changes from the remote"\
76 " Transifex server to the local repository. By default, only the"\
77 " files that are watched by Transifex will be updated but if you"\
78 " want to fetch the translations for new languages as well, use the"\
79 " -a|--all option. (Note: new translations are saved in the .tx folder"\
80 " and require the user to manually rename them and add then in "\
81 " transifex using the set_translation command)."
82 parser
= OptionParser(usage
=usage
,description
=description
)
83 parser
.add_option("-l","--language", action
="store", dest
="languages",
84 default
=[], help="Specify which translations you want to pull"
86 parser
.add_option("-r","--resource", action
="store", dest
="resources",
87 default
=[], help="Specify the resource for which you want to pull"
88 " the translations (defaults to all)")
89 parser
.add_option("-a","--all", action
="store_true", dest
="fetchall",
90 default
=False, help="Fetch all translation files from server (even new"
92 parser
.add_option("-s","--source", action
="store_true", dest
="fetchsource",
93 default
=False, help="Force the fetching of the source file (default:"
95 parser
.add_option("-f","--force", action
="store_true", dest
="force",
96 default
=False, help="Force download of translations files.")
97 parser
.add_option("--skip", action
="store_true", dest
="skip_errors",
98 default
=False, help="Don't stop on errors. Useful when pushing many"
99 " files concurrently.")
100 parser
.add_option("--disable-overwrite", action
="store_false",
101 dest
="overwrite", default
=True,
102 help="By default transifex will fetch new translations files and"\
103 " replace existing ones. Use this flag if you want to disable"\
105 parser
.add_option("--minimum-perc", action
="store", type="int",
106 dest
="minimum_perc", default
=0,
107 help="Specify the minimum acceptable percentage of a translation "
108 "in order to download it.")
110 "--mode", action
="store", dest
="mode", help=(
111 "Specify the mode of the translation file to pull (e.g. "
112 "'reviewed'). See http://bit.ly/txcmod1 for available values."
119 """Return the command-line parser for the push command."""
120 usage
="usage: %prog [tx_options] push [options]"
121 description
="This command pushes all local files that have been added to"\
122 " Transifex to the remote server. All new translations are merged"\
123 " with existing ones and if a language doesn't exists then it gets"\
124 " created. If you want to push the source file as well (either"\
125 " because this is your first time running the client or because"\
126 " you just have updated with new entries), use the -f|--force option."\
127 " By default, this command will push all files which are watched by"\
128 " Transifex but you can filter this per resource or/and language."
129 parser
= OptionParser(usage
=usage
, description
=description
)
130 parser
.add_option("-l","--language", action
="store", dest
="languages",
131 default
=None, help="Specify which translations you want to push"
132 " (defaults to all)")
133 parser
.add_option("-r","--resource", action
="store", dest
="resources",
134 default
=None, help="Specify the resource for which you want to push"
135 " the translations (defaults to all)")
136 parser
.add_option("-f","--force", action
="store_true", dest
="force_creation",
137 default
=False, help="Push source files without checking modification"
139 parser
.add_option("--skip", action
="store_true", dest
="skip_errors",
140 default
=False, help="Don't stop on errors. Useful when pushing many"
141 " files concurrently.")
142 parser
.add_option("-s", "--source", action
="store_true", dest
="push_source",
143 default
=False, help="Push the source file to the server.")
145 parser
.add_option("-t", "--translations", action
="store_true", dest
="push_translations",
146 default
=False, help="Push the translation files to the server")
147 parser
.add_option("--no-interactive", action
="store_true", dest
="no_interactive",
148 default
=False, help="Don't require user input when forcing a push.")
153 """Return the command-line parser for the set command."""
154 usage
="usage: %prog [tx_options] set [options] [args]"
155 description
="This command can be used to create a mapping between files"\
156 " and projects either using local files or using files from a remote"\
158 epilog
="\nExamples:\n"\
159 " To set the source file:\n $ tx set -r project.resource --source -l en <file>\n\n"\
160 " To set a single translation file:\n $ tx set -r project.resource -l de <file>\n\n"\
161 " To automatically detect and assign the source files and translations:\n"\
162 " $ tx set --auto-local -r project.resource 'expr' --source-lang en\n\n"\
163 " To set a specific file as a source and auto detect translations:\n"\
164 " $ tx set --auto-local -r project.resource 'expr' --source-lang en"\
165 " --source-file <file>\n\n"\
166 " To set a remote release/resource/project:\n"\
167 " $ tx set --auto-remote <transifex-url>\n"
168 parser
= EpilogParser(usage
=usage
, description
=description
, epilog
=epilog
)
169 parser
.add_option("--auto-local", action
="store_true", dest
="local",
170 default
=False, help="Used when auto configuring local project.")
171 parser
.add_option("--auto-remote", action
="store_true", dest
="remote",
172 default
=False, help="Used when adding remote files from Transifex"
174 parser
.add_option("-r","--resource", action
="store", dest
="resource",
175 default
=None, help="Specify the slug of the resource that you're"
176 " setting up (This must be in the following format:"
177 " `project_slug.resource_slug`).")
179 "--source", action
="store_true", dest
="is_source", default
=False,
181 "Specify that the given file is a source file "
182 "[doesn't work with the --auto-* commands]."
185 parser
.add_option("-l","--language", action
="store", dest
="language",
186 default
=None, help="Specify which translations you want to pull"
187 " [doesn't work with the --auto-* commands].")
188 parser
.add_option("-t", "--type", action
="store", dest
="i18n_type",
190 "Specify the i18n type of the resource(s). This is only needed, if "
191 "the resource(s) does not exist yet in Transifex. For a list of "
192 "available i18n types, see "
193 "http://help.transifex.com/features/formats.html"
196 parser
.add_option("--minimum-perc", action
="store", dest
="minimum_perc",
198 "Specify the minimum acceptable percentage of a translation "
199 "in order to download it."
203 "--mode", action
="store", dest
="mode", help=(
204 "Specify the mode of the translation file to pull (e.g. "
205 "'reviewed'). See http://help.transifex.com/features/client/"
206 "index.html#defining-the-mode-of-the-translated-file for the"
210 group
= OptionGroup(parser
, "Extended options", "These options can only be"
211 " used with the --auto-local command.")
212 group
.add_option("-s","--source-language", action
="store",
213 dest
="source_language",
214 default
=None, help="Specify the source language of a resource"
215 " [requires --auto-local].")
216 group
.add_option("-f","--source-file", action
="store", dest
="source_file",
217 default
=None, help="Specify the source file of a resource [requires"
219 group
.add_option("--execute", action
="store_true", dest
="execute",
220 default
=False, help="Execute commands [requires --auto-local].")
221 parser
.add_option_group(group
)
226 """Return the command-line parser for the status command."""
227 usage
="usage: %prog [tx_options] status [options]"
228 description
="Prints the status of the current project by reading the"\
229 " data in the configuration file."
230 parser
= OptionParser(usage
=usage
,description
=description
)
231 parser
.add_option("-r","--resource", action
="store", dest
="resources",
232 default
=[], help="Specify resources")
236 def parse_csv_option(option
):
237 """Return a list out of the comma-separated option or an empty list."""
239 return option
.split(',')