Detect non existing projects.

Julien LepillerSat Aug 31 12:16:02+0200 2019

40e48ca

Detect non existing projects.

offlate/systems/git.py

2323
from ..formats.gettext import GettextFormat
2424
from ..formats.ts import TSFormat
2525
from ..formats.yaml import YamlFormat
26+
from .systemException import ProjectNotFoundSystemException
2627
2728
def rmdir(dir):
2829
    dir = Path(dir)

106107
        return translationfiles
107108
108109
    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)
110114
        repo = pygit2.Repository(directory)
111115
        branch = repo.lookup_branch(self.branch)
112116
        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

3131
3232
from ..formats.entry import POEntry
3333
from ..formats.gettext import GettextFormat
34+
from .systemException import ProjectNotFoundSystemException
3435
3536
class TPProject:
3637
    def __init__(self, conf, name, lang, data = {}):

7778
    def updateVersion(self):
7879
        url = 'https://translationproject.org/domain/' + self.name + '.html'
7980
        page = requests.get(url)
81+
        if page.status_code != '200':
82+
            raise ProjectNotFoundSystemException(self.name)
8083
        tree = html.fromstring(page.content)
8184
        pot = tree.xpath('//a[contains(@href,"POT-file")]/text()')
8285
        self.version = re.sub(self.name+'-(.*).pot$', '\\1', str(pot[0]))

offlate/systems/transifex.py

2121
from requests.auth import HTTPBasicAuth
2222
from ..formats.yaml import YamlFormat
2323
from ..formats.formatException import UnsupportedFormatException
24+
from .systemException import ProjectNotFoundSystemException
2425
2526
class TransifexProject:
2627
    def __init__(self, conf, name, lang, data={}):

5657
            l = json.loads(ans.text)
5758
            self.slugs = [x['slug'] for x in l]
5859
            self.files = l
60+
        else:
61+
            raise ProjectNotFoundSystemException(self.name)
5962
6063
    def update(self, callback):
6164
        self.updateFileList()

offlate/ui/manager.py

3030
from ..manager import ProjectManager
3131
3232
from ..formats.formatException import UnsupportedFormatException
33+
from ..systems.systemException import ProjectNotFoundSystemException
3334
3435
class ProjectManagerWindow(QMainWindow):
3536
    _instance = None

298299
            self.error = self.parent.tr('The project you added uses the {} format, \
299300
but it is not supported yet by Offlate. You can try to update the application, \
300301
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))
301306
        else:
302307
            self.error = self.parent.tr('An unexpected error occured while \
303308
fetching the project: {}. You should report this as a bug.'.format(str(error)))