Exemple #1
0
def downloadAppInfo(url):
    downloader = Downloader(DOWNLOAD_TIMEOUT)

    try:
        xml_content = downloader.download(url)
        appinfo = AppInfoFactory.fromString(xml_content, '')
    except ValueError:
        appinfo = AppInfoFactory.fromString('', '')

    return appinfo
Exemple #2
0
def test_fromXmlAppInfo_website_missing():
    xmlAppInfo = XmlAppInfo()
    xmlAppInfo.website.set_for_language('en', 'http://example.com')
    language = 'ru'
    appInfo = AppInfoFactory.fromXmlAppInfo(xmlAppInfo, language)

    assert appInfo.website == ''
Exemple #3
0
def test_fromXmlAppInfo_description():
    xmlAppInfo = XmlAppInfo()
    xmlAppInfo.description.set_for_language('en', 'bla-bla-bla')
    language = 'en'
    appInfo = AppInfoFactory.fromXmlAppInfo(xmlAppInfo, language)

    assert appInfo.description == 'bla-bla-bla'
Exemple #4
0
def test_fromXmlAppInfo_app_name():
    xmlAppInfo = XmlAppInfo()
    xmlAppInfo.app_name.set_for_language('en', 'John')
    language = 'en'
    appInfo = AppInfoFactory.fromXmlAppInfo(xmlAppInfo, language)

    assert appInfo.app_name == 'John'
Exemple #5
0
def test_fromXmlAppInfo_app_info_version():
    xmlAppInfo = XmlAppInfo()
    xmlAppInfo.version = XmlVersionInfo('1.0.1', status='beta')
    language = ''
    appInfo = AppInfoFactory.fromXmlAppInfo(xmlAppInfo, language)

    assert appInfo.version == Version(1, 0, 1, status=StatusSet.BETA)
Exemple #6
0
    def getInfo(self, pluginname: str, langlist=["en"]) -> Optional[AppInfo]:
        """
        Retrieve a AppInfo for plugin_name

        :param pluginname:
            name of the loaded plugin
        :param lang:
            langlist - list of the languages name ("en", "ru_RU" etc)
        :return:
            AppInfo for pluginname
            if pluginname cannot be located, then None is returned.
        :exception IOError:
            if plugin.xml cannot be read
        """
        if pluginname in self.loadedPlugins:
            module = self.loadedPlugins[pluginname].__class__.__module__
        else:
            module = ''

        xml_content = pkgutil.get_data(module, PLUGIN_INFO_FILE_NAME)
        if xml_content:
            language = ''
            return AppInfoFactory.fromString(xml_content.decode(), language)

        return None
Exemple #7
0
    def getAppInfoFromUrl(self, url):
        """
        Get a AppInfo object for url.

        :param url:
            URL of path to file to read versions information.
        :returns:
            AppInfo or None
        """
        if url is None:
            return None

        logger.info(u'Downloading {}'.format(url))

        try:
            text = self._loader.load(url)
        except (urllib.error.HTTPError, urllib.error.URLError, ValueError):
            logger.warning(u"Can't download {}".format(url))
            return None

        try:
            appinfo = AppInfoFactory.fromString(text, '')
        except ValueError:
            logger.warning(u'Invalid format of {}'.format(url))
            return None

        if not appinfo.app_name.strip():
            return None

        return appinfo
Exemple #8
0
def test_fromXmlAppInfo_description_default():
    xmlAppInfo = XmlAppInfo()
    xmlAppInfo.description.set_for_language('', 'bla-bla-bla')
    xmlAppInfo.description.set_for_language('ru', 'бла-бла-бла')
    language = 'jp'
    appInfo = AppInfoFactory.fromXmlAppInfo(xmlAppInfo, language)

    assert appInfo.description == 'bla-bla-bla'
Exemple #9
0
def test_fromXmlAppInfo_website_lang_alternative():
    xmlAppInfo = XmlAppInfo()
    xmlAppInfo.website.set_for_language('en', 'http://example.com')
    xmlAppInfo.website.set_for_language('ru', 'http://example.com/ru')
    language = 'ru_RU'
    appInfo = AppInfoFactory.fromXmlAppInfo(xmlAppInfo, language)

    assert appInfo.website == 'http://example.com/ru'
Exemple #10
0
def test_fromString_empty():
    appInfo = AppInfoFactory.fromString('', language='ru')

    assert appInfo.app_name == ''
    assert appInfo.website == ''
    assert appInfo.description == ''
    assert appInfo.version is None
    assert appInfo.authors == []
Exemple #11
0
def test_fromXmlAppInfo_website_default():
    xmlAppInfo = XmlAppInfo()
    xmlAppInfo.website.set_for_language('', 'http://example.com')
    xmlAppInfo.website.set_for_language('jp', 'http://example.com/jp')
    language = 'ru_RU'
    appInfo = AppInfoFactory.fromXmlAppInfo(xmlAppInfo, language)

    assert appInfo.website == 'http://example.com'
Exemple #12
0
    def __loadPluginInfo(self, plugin_fname):
        if not os.path.exists(plugin_fname):
            return None

        xml_content = readTextFile(plugin_fname)
        language = ''
        appinfo = AppInfoFactory.fromString(xml_content, language)
        return appinfo
Exemple #13
0
def test_fromXmlAppInfo_app_name_alternative_02():
    xmlAppInfo = XmlAppInfo()
    xmlAppInfo.app_name.set_for_language('en', 'John')
    xmlAppInfo.app_name.set_for_language('en_US', 'John Smith')
    language = 'en_US'
    appInfo = AppInfoFactory.fromXmlAppInfo(xmlAppInfo, language)

    assert appInfo.app_name == 'John Smith'
Exemple #14
0
def test_fromXmlAppInfo_requirements_single():
    xmlAppInfo = XmlAppInfo()
    xmlAppInfo.requirements.os_list = ['Windows']
    xmlAppInfo.requirements.api_list = [(3, 868)]

    language = 'en'
    appInfo = AppInfoFactory.fromXmlAppInfo(xmlAppInfo, language)

    assert appInfo.requirements.os_list == ['Windows']
    assert appInfo.requirements.api_list == [(3, 868)]
Exemple #15
0
def test_fromXmlAppInfo_requirements_several():
    xmlAppInfo = XmlAppInfo()
    xmlAppInfo.requirements.os_list = ['Windows', 'Linux']
    xmlAppInfo.requirements.api_list = [(3, 868), (2, 800)]

    language = 'en'
    appInfo = AppInfoFactory.fromXmlAppInfo(xmlAppInfo, language)

    assert appInfo.requirements.os_list == ['Windows', 'Linux']
    assert appInfo.requirements.api_list == [(3, 868), (2, 800)]
Exemple #16
0
def test_fromXmlAppInfo_empty():
    xmlAppInfo = XmlAppInfo()
    language = ''
    appInfo = AppInfoFactory.fromXmlAppInfo(xmlAppInfo, language)

    assert appInfo.app_name == ''
    assert appInfo.website == ''
    assert appInfo.description == ''
    assert appInfo.authors == []
    assert appInfo.requirements.os_list == []
    assert appInfo.requirements.api_list == []
    assert appInfo.version is None
Exemple #17
0
def test_fromXmlAppInfo_authors():
    xmlAppInfo = XmlAppInfo()
    author_en = XmlAuthorInfo(name='John',
                              email='*****@*****.**',
                              website='http://example.com')
    xmlAppInfo.authors.set_for_language('en', [author_en])

    language = 'en'
    appInfo = AppInfoFactory.fromXmlAppInfo(xmlAppInfo, language)

    assert appInfo.authors[0].name == 'John'
    assert appInfo.authors[0].email == '*****@*****.**'
    assert appInfo.authors[0].website == 'http://example.com'
Exemple #18
0
def test_fromString_lang_default():
    appinfo = AppInfoFactory.fromString(xmlexample, language='jp')

    assert appinfo.app_name == 'Application name'
    assert appinfo.website == 'http://jenyay.net/en/'
    assert appinfo.description == 'Description'

    assert appinfo.authors[0].name == 'John'
    assert appinfo.authors[0].email == '*****@*****.**'
    assert appinfo.authors[0].website == 'http://example.com'

    assert appinfo.authors[1].name == 'Andrey'
    assert appinfo.authors[1].email == '*****@*****.**'
    assert appinfo.authors[1].website == 'http://example.com/andrey'

    assert appinfo.version == Version(2, 0, status=StatusSet.DEV)

    assert appinfo.requirements.os_list == ['Windows', 'Linux']
    assert appinfo.requirements.api_list == [(2, 222), (3, 333)]
Exemple #19
0
def test_fromXmlAppInfo_authors_default():
    xmlAppInfo = XmlAppInfo()

    author_default = XmlAuthorInfo(name='John',
                                   email='*****@*****.**',
                                   website='http://example.com')
    xmlAppInfo.authors.set_for_language('', [author_default])

    author_ru = XmlAuthorInfo(name='Джон',
                              email='*****@*****.**',
                              website='http://example.com/ru')
    xmlAppInfo.authors.set_for_language('ru', [author_ru])

    language = 'jp'
    appInfo = AppInfoFactory.fromXmlAppInfo(xmlAppInfo, language)

    assert appInfo.authors[0].name == 'John'
    assert appInfo.authors[0].email == '*****@*****.**'
    assert appInfo.authors[0].website == 'http://example.com'
Exemple #20
0
def test_fromString_lang_ru_RU():
    appinfo = AppInfoFactory.fromString(xmlexample, language='ru_RU')

    assert appinfo.app_name == 'Имя приложения'
    assert appinfo.website == 'http://jenyay.net/ru/'
    assert appinfo.description == 'Описание'

    assert appinfo.authors[0].name == 'Джон'
    assert appinfo.authors[0].email == '*****@*****.**'
    assert appinfo.authors[0].website == 'http://example.com/ru'

    assert appinfo.authors[1].name == 'Андрей'
    assert appinfo.authors[1].email == '*****@*****.**'
    assert appinfo.authors[1].website == 'http://example.com/andrey/ru'

    assert appinfo.version == Version(2, 0, status=StatusSet.DEV)

    assert appinfo.requirements.os_list == ['Windows', 'Linux']
    assert appinfo.requirements.api_list == [(2, 222), (3, 333)]
Exemple #21
0
def readAppInfo(fname: str) -> AppInfo:
    text = readTextFile(fname)
    return AppInfoFactory.fromString(text, '')