fd3237d20ec9ee6eeafa7e43aec52299a0bf9e76
[pub/Android/ownCloud.git] / third_party / transifex-client / txclib / parsers.py
1 # -*- coding: utf-8 -*-
2
3 from optparse import OptionParser, OptionGroup
4
5
6 class EpilogParser(OptionParser):
7 def format_epilog(self, formatter):
8 return self.epilog
9
10
11 def delete_parser():
12 """Return the command-line parser for the delete command."""
13 usage = "usage: %prog [tx_options] delete OPTION [OPTIONS]"
14 description = (
15 "This command deletes translations for a resource in the remote server."
16 )
17 epilog = (
18 "\nExamples:\n"
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"
22 )
23 parser = EpilogParser(usage=usage, description=description, epilog=epilog)
24 parser.add_option(
25 "-r", "--resource", action="store", dest="resources", default=None,
26 help="Specify the resource you want to delete (defaults to all)"
27 )
28 parser.add_option(
29 "-l","--language", action="store", dest="languages",
30 default=None, help="Specify the translation you want to delete"
31 )
32 parser.add_option(
33 "--skip", action="store_true", dest="skip_errors", default=False,
34 help="Don't stop on errors."
35 )
36 parser.add_option(
37 "-f","--force", action="store_true", dest="force_delete",
38 default=False, help="Delete an entity forcefully."
39 )
40 return parser
41
42
43 def help_parser():
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."
49
50 parser = OptionParser(usage=usage, description=description)
51 return parser
52
53
54 def init_parser():
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.")
69 return parser
70
71
72 def pull_parser():
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"
85 " (defaults to all)")
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"
91 " ones)")
92 parser.add_option("-s","--source", action="store_true", dest="fetchsource",
93 default=False, help="Force the fetching of the source file (default:"
94 " False)")
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"\
104 " this feature")
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.")
109 parser.add_option(
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."
113 )
114 )
115 return parser
116
117
118 def push_parser():
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"
138 " times.")
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.")
144
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.")
149 return parser
150
151
152 def set_parser():
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"\
157 " Transifex server."
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"
173 " server.")
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`).")
178 parser.add_option(
179 "--source", action="store_true", dest="is_source", default=False,
180 help=(
181 "Specify that the given file is a source file "
182 "[doesn't work with the --auto-* commands]."
183 )
184 )
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",
189 help=(
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"
194 )
195 )
196 parser.add_option("--minimum-perc", action="store", dest="minimum_perc",
197 help=(
198 "Specify the minimum acceptable percentage of a translation "
199 "in order to download it."
200 )
201 )
202 parser.add_option(
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"
207 "available values."
208 )
209 )
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"
218 " --auto-local].")
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)
222 return parser
223
224
225 def status_parser():
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")
233 return parser
234
235
236 def parse_csv_option(option):
237 """Return a list out of the comma-separated option or an empty list."""
238 if option:
239 return option.split(',')
240 else:
241 return []