Left: | ||
Right: |
LEFT | RIGHT |
---|---|
1 # This file is part of the Adblock Plus web scripts, | 1 # This file is part of the Adblock Plus web scripts, |
2 # Copyright (C) 2006-present eyeo GmbH | 2 # Copyright (C) 2006-present eyeo GmbH |
3 # | 3 # |
4 # Adblock Plus is free software: you can redistribute it and/or modify | 4 # Adblock Plus is free software: you can redistribute it and/or modify |
5 # it under the terms of the GNU General Public License version 3 as | 5 # it under the terms of the GNU General Public License version 3 as |
6 # published by the Free Software Foundation. | 6 # published by the Free Software Foundation. |
7 # | 7 # |
8 # Adblock Plus is distributed in the hope that it will be useful, | 8 # Adblock Plus is distributed in the hope that it will be useful, |
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of | 9 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
(...skipping 15 matching lines...) Expand all Loading... | |
26 ) | 26 ) |
27 import cms.translations.xtm.constants as const | 27 import cms.translations.xtm.constants as const |
28 from cms.translations.xtm.projects_handler import ( | 28 from cms.translations.xtm.projects_handler import ( |
29 create_project, upload_files, download_files, | 29 create_project, upload_files, download_files, |
30 ) | 30 ) |
31 from cms.translations.xtm.utils import input_fn, read_token, get_api_url | 31 from cms.translations.xtm.utils import input_fn, read_token, get_api_url |
32 from cms.sources import create_source | 32 from cms.sources import create_source |
33 | 33 |
34 | 34 |
35 def handle_projects(args): | 35 def handle_projects(args): |
36 token = read_token() | 36 try: |
Vasily Kuznetsov
2019/01/10 17:45:23
Wouldn't it be better to keep this inside of try/e
Tudor Avram
2019/09/17 12:25:02
Done.
| |
37 with create_source(args.source_dir, cached=True) as fs: | 37 token = read_token() |
38 try: | 38 with create_source(args.source_dir, cached=True) as fs: |
39 api = XTMCloudAPI(token, get_api_url(args, fs)) | 39 api = XTMCloudAPI(token, get_api_url(args, fs)) |
40 except Exception as err: | 40 args.projects_func(args, api, fs) |
41 sys.exit(err) | 41 except Exception as err: |
42 args.projects_func(args, api, fs) | 42 sys.exit(err) |
43 | 43 |
44 | 44 |
45 def generate_token(args): | 45 def generate_token(args): |
46 """Generate an API token from username and password.""" | 46 """Generate an API token from username and password.""" |
47 username = input_fn('Username: ') | 47 username = input_fn('Client name: ') |
48 user_id = input_fn('User ID: ') | 48 user_id = input_fn('User ID: ') |
49 password = getpass.getpass(prompt='Password: ') | 49 password = getpass.getpass(prompt='Password: ') |
50 | 50 |
51 logging.info(const.InfoMessages.GENERATING_TOKEN.format(username, user_id)) | 51 logging.info(const.InfoMessages.GENERATING_TOKEN.format(username, user_id)) |
52 try: | 52 try: |
53 token = get_token(username, password, int(user_id), | 53 token = get_token(username, password, int(user_id), |
54 get_api_url(args, None)) | 54 get_api_url(args, None)) |
55 logging.info(const.InfoMessages.TOKEN_GENERATED.format(token)) | 55 logging.info(const.InfoMessages.TOKEN_GENERATED.format(token)) |
56 | 56 |
57 cmd = const.Token.SAVE_COMMAND.format(const.Token.ENV_VAR, token) | 57 cmd = const.Token.SAVE_COMMAND.format(const.Token.ENV_VAR, token) |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
92 project_create_parser.add_argument( | 92 project_create_parser.add_argument( |
93 '--name', required=True, | 93 '--name', required=True, |
94 help=const.ArgumentsHelp.ProjectCreate.NAME, | 94 help=const.ArgumentsHelp.ProjectCreate.NAME, |
95 ) | 95 ) |
96 project_create_parser.add_argument( | 96 project_create_parser.add_argument( |
97 '--desc', required=True, | 97 '--desc', required=True, |
98 help=const.ArgumentsHelp.ProjectCreate.DESC, | 98 help=const.ArgumentsHelp.ProjectCreate.DESC, |
99 ) | 99 ) |
100 | 100 |
101 project_create_parser.add_argument( | 101 project_create_parser.add_argument( |
102 '--client-id', required=True, type=int, | 102 '--customer-id', required=True, type=int, |
103 help=const.ArgumentsHelp.ProjectCreate.CLIENT_ID, | 103 help=const.ArgumentsHelp.ProjectCreate.CUSTOMER_ID, |
104 ) | 104 ) |
105 project_create_parser.add_argument( | 105 project_create_parser.add_argument( |
106 '--ref-id', required=True, | 106 '--ref-id', required=True, |
107 help=const.ArgumentsHelp.ProjectCreate.REF_ID, | 107 help=const.ArgumentsHelp.ProjectCreate.REF_ID, |
108 ) | 108 ) |
109 project_create_parser.add_argument( | 109 project_create_parser.add_argument( |
110 '--workflow-id', type=int, | 110 '--workflow-id', type=int, |
111 help=const.ArgumentsHelp.ProjectCreate.WORKFLOW_ID, | 111 help=const.ArgumentsHelp.ProjectCreate.WORKFLOW_ID, |
112 ) | 112 ) |
113 project_create_parser.add_argument( | 113 project_create_parser.add_argument( |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
153 ) | 153 ) |
154 | 154 |
155 return parser.parse_args() | 155 return parser.parse_args() |
156 | 156 |
157 | 157 |
158 def main(): | 158 def main(): |
159 """Run XTM integration script.""" | 159 """Run XTM integration script.""" |
160 args = parse_args() | 160 args = parse_args() |
161 | 161 |
162 if args.verbose: | 162 if args.verbose: |
163 logging.basicConfig(level=logging.INFO) | 163 logging.basicConfig(level=logging.INFO, stream=sys.stderr) |
164 | 164 |
165 args.func(args) | 165 args.func(args) |
166 | 166 |
167 | 167 |
168 if __name__ == '__main__': | 168 if __name__ == '__main__': |
169 main() | 169 main() |
LEFT | RIGHT |