Detect non existing projects.
offlate/systems/git.py
23 | 23 | from ..formats.gettext import GettextFormat | |
24 | 24 | from ..formats.ts import TSFormat | |
25 | 25 | from ..formats.yaml import YamlFormat | |
26 | + | from .systemException import ProjectNotFoundSystemException | |
26 | 27 | ||
27 | 28 | def rmdir(dir): | |
28 | 29 | dir = Path(dir) | |
… | |||
106 | 107 | return translationfiles | |
107 | 108 | ||
108 | 109 | def clone(self, directory, callback=None): | |
109 | - | pygit2.clone_repository(self.uri, directory, callbacks=Progress(callback)) | |
110 | + | try: | |
111 | + | pygit2.clone_repository(self.uri, directory, callbacks=Progress(callback)) | |
112 | + | except: | |
113 | + | raise ProjectNotFoundSystemException(self.name) | |
110 | 114 | repo = pygit2.Repository(directory) | |
111 | 115 | branch = repo.lookup_branch(self.branch) | |
112 | 116 | ref = repo.lookup_reference(branch.name) |
offlate/systems/systemException.py unknown status 1
1 | + | # Copyright (c) 2019 Julien Lepiller <julien@lepiller.eu> | |
2 | + | # | |
3 | + | # This program is free software: you can redistribute it and/or modify | |
4 | + | # it under the terms of the GNU Affero General Public License as | |
5 | + | # published by the Free Software Foundation, either version 3 of the | |
6 | + | # License, or (at your option) any later version. | |
7 | + | # | |
8 | + | # This program is distributed in the hope that it will be useful, | |
9 | + | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
10 | + | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
11 | + | # GNU Affero General Public License for more details. | |
12 | + | # | |
13 | + | # You should have received a copy of the GNU Affero General Public License | |
14 | + | # along with this program. If not, see <https://www.gnu.org/licenses/>. | |
15 | + | #### | |
16 | + | ||
17 | + | class ProjectNotFoundSystemException(Exception): | |
18 | + | def __init__(self, message): | |
19 | + | super().__init__('Project not found: '+message) | |
20 | + | self.projectNotFound = message |
offlate/systems/tp.py
31 | 31 | ||
32 | 32 | from ..formats.entry import POEntry | |
33 | 33 | from ..formats.gettext import GettextFormat | |
34 | + | from .systemException import ProjectNotFoundSystemException | |
34 | 35 | ||
35 | 36 | class TPProject: | |
36 | 37 | def __init__(self, conf, name, lang, data = {}): | |
… | |||
77 | 78 | def updateVersion(self): | |
78 | 79 | url = 'https://translationproject.org/domain/' + self.name + '.html' | |
79 | 80 | page = requests.get(url) | |
81 | + | if page.status_code != '200': | |
82 | + | raise ProjectNotFoundSystemException(self.name) | |
80 | 83 | tree = html.fromstring(page.content) | |
81 | 84 | pot = tree.xpath('//a[contains(@href,"POT-file")]/text()') | |
82 | 85 | self.version = re.sub(self.name+'-(.*).pot$', '\\1', str(pot[0])) |
offlate/systems/transifex.py
21 | 21 | from requests.auth import HTTPBasicAuth | |
22 | 22 | from ..formats.yaml import YamlFormat | |
23 | 23 | from ..formats.formatException import UnsupportedFormatException | |
24 | + | from .systemException import ProjectNotFoundSystemException | |
24 | 25 | ||
25 | 26 | class TransifexProject: | |
26 | 27 | def __init__(self, conf, name, lang, data={}): | |
… | |||
56 | 57 | l = json.loads(ans.text) | |
57 | 58 | self.slugs = [x['slug'] for x in l] | |
58 | 59 | self.files = l | |
60 | + | else: | |
61 | + | raise ProjectNotFoundSystemException(self.name) | |
59 | 62 | ||
60 | 63 | def update(self, callback): | |
61 | 64 | self.updateFileList() |
offlate/ui/manager.py
30 | 30 | from ..manager import ProjectManager | |
31 | 31 | ||
32 | 32 | from ..formats.formatException import UnsupportedFormatException | |
33 | + | from ..systems.systemException import ProjectNotFoundSystemException | |
33 | 34 | ||
34 | 35 | class ProjectManagerWindow(QMainWindow): | |
35 | 36 | _instance = None | |
… | |||
298 | 299 | self.error = self.parent.tr('The project you added uses the {} format, \ | |
299 | 300 | but it is not supported yet by Offlate. You can try to update the application, \ | |
300 | 301 | or if you are on the latest version already, report it as a bug.'.format(error.unsupportedFormat)) | |
302 | + | elif isinstance(error, ProjectNotFoundSystemException): | |
303 | + | self.error = self.parent.tr('The project {} you added could not be found \ | |
304 | + | in the translation platform you selected. Did you make a typo while entering the \ | |
305 | + | name or other parameters?'.format(error.projectNotFound)) | |
301 | 306 | else: | |
302 | 307 | self.error = self.parent.tr('An unexpected error occured while \ | |
303 | 308 | fetching the project: {}. You should report this as a bug.'.format(str(error))) |