本文整理汇总了Python中manifestparser.ManifestParser.read方法的典型用法代码示例。如果您正苦于以下问题:Python ManifestParser.read方法的具体用法?Python ManifestParser.read怎么用?Python ManifestParser.read使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类manifestparser.ManifestParser
的用法示例。
在下文中一共展示了ManifestParser.read方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_sanity
# 需要导入模块: from manifestparser import ManifestParser [as 别名]
# 或者: from manifestparser.ManifestParser import read [as 别名]
def test_sanity(self):
"""Ensure basic parser is sane"""
parser = ManifestParser()
mozmill_example = os.path.join(here, 'mozmill-example.ini')
parser.read(mozmill_example)
tests = parser.tests
self.assertEqual(len(tests), len(file(mozmill_example).read().strip().splitlines()))
# Ensure that capitalization and order aren't an issue:
lines = ['[%s]' % test['name'] for test in tests]
self.assertEqual(lines, file(mozmill_example).read().strip().splitlines())
# Show how you select subsets of tests:
mozmill_restart_example = os.path.join(here, 'mozmill-restart-example.ini')
parser.read(mozmill_restart_example)
restart_tests = parser.get(type='restart')
self.assertTrue(len(restart_tests) < len(parser.tests))
self.assertEqual(len(restart_tests), len(parser.get(manifest=mozmill_restart_example)))
self.assertFalse([test for test in restart_tests
if test['manifest'] != os.path.join(here, 'mozmill-restart-example.ini')])
self.assertEqual(parser.get('name', tags=['foo']),
['restartTests/testExtensionInstallUninstall/test2.js',
'restartTests/testExtensionInstallUninstall/test1.js'])
self.assertEqual(parser.get('name', foo='bar'),
['restartTests/testExtensionInstallUninstall/test2.js'])
示例2: install_from_manifest
# 需要导入模块: from manifestparser import ManifestParser [as 别名]
# 或者: from manifestparser.ManifestParser import read [as 别名]
def install_from_manifest(self, filepath):
"""
Installs addons from a manifest
:param filepath: path to the manifest of addons to install
"""
manifest = ManifestParser()
manifest.read(filepath)
addons = manifest.get()
for addon in addons:
if '://' in addon['path'] or os.path.exists(addon['path']):
self.install_from_path(addon['path'])
continue
# No path specified, try to grab it off AMO
locale = addon.get('amo_locale', 'en_US')
query = 'https://services.addons.mozilla.org/' + locale + '/firefox/api/' + AMO_API_VERSION + '/'
if 'amo_id' in addon:
query += 'addon/' + addon['amo_id'] # this query grabs information on the addon base on its id
else:
query += 'search/' + addon['name'] + '/default/1' # this query grabs information on the first addon returned from a search
install_path = AddonManager.get_amo_install_path(query)
self.install_from_path(install_path)
self.installed_manifests.append(filepath)
示例3: install_from_manifest
# 需要导入模块: from manifestparser import ManifestParser [as 别名]
# 或者: from manifestparser.ManifestParser import read [as 别名]
def install_from_manifest(self, filepath):
"""
Installs addons from a manifest
:param filepath: path to the manifest of addons to install
"""
manifest = ManifestParser()
manifest.read(filepath)
addons = manifest.get()
for addon in addons:
if "://" in addon["path"] or os.path.exists(addon["path"]):
self.install_from_path(addon["path"])
continue
# No path specified, try to grab it off AMO
locale = addon.get("amo_locale", "en_US")
query = "https://services.addons.mozilla.org/" + locale + "/firefox/api/" + AMO_API_VERSION + "/"
if "amo_id" in addon:
query += "addon/" + addon["amo_id"] # this query grabs information on the addon base on its id
else:
query += (
"search/" + addon["name"] + "/default/1"
) # this query grabs information on the first addon returned from a search
install_path = AddonManager.get_amo_install_path(query)
self.install_from_path(install_path)
self.installed_manifests.append(filepath)
示例4: test_sanity
# 需要导入模块: from manifestparser import ManifestParser [as 别名]
# 或者: from manifestparser.ManifestParser import read [as 别名]
def test_sanity(self):
"""Ensure basic parser is sane"""
parser = ManifestParser()
mozmill_example = os.path.join(here, "mozmill-example.ini")
parser.read(mozmill_example)
tests = parser.tests
self.assertEqual(len(tests), len(file(mozmill_example).read().strip().splitlines()))
# Ensure that capitalization and order aren't an issue:
lines = ["[%s]" % test["name"] for test in tests]
self.assertEqual(lines, file(mozmill_example).read().strip().splitlines())
# Show how you select subsets of tests:
mozmill_restart_example = os.path.join(here, "mozmill-restart-example.ini")
parser.read(mozmill_restart_example)
restart_tests = parser.get(type="restart")
self.assertTrue(len(restart_tests) < len(parser.tests))
self.assertEqual(len(restart_tests), len(parser.get(manifest=mozmill_restart_example)))
self.assertFalse(
[test for test in restart_tests if test["manifest"] != os.path.join(here, "mozmill-restart-example.ini")]
)
self.assertEqual(
parser.get("name", tags=["foo"]),
[
"restartTests/testExtensionInstallUninstall/test2.js",
"restartTests/testExtensionInstallUninstall/test1.js",
],
)
self.assertEqual(parser.get("name", foo="bar"), ["restartTests/testExtensionInstallUninstall/test2.js"])
示例5: test_just_defaults
# 需要导入模块: from manifestparser import ManifestParser [as 别名]
# 或者: from manifestparser.ManifestParser import read [as 别名]
def test_just_defaults(self):
"""Ensure a manifest with just a DEFAULT section exposes that data."""
parser = ManifestParser()
manifest = os.path.join(here, 'just-defaults.ini')
parser.read(manifest)
self.assertEqual(len(parser.tests), 0)
self.assertTrue(manifest in parser.manifest_defaults)
self.assertEquals(parser.manifest_defaults[manifest]['foo'], 'bar')
示例6: test_manifest_list
# 需要导入模块: from manifestparser import ManifestParser [as 别名]
# 或者: from manifestparser.ManifestParser import read [as 别名]
def test_manifest_list(self):
"""
Ensure a manifest with just a DEFAULT section still returns
itself from the manifests() method.
"""
parser = ManifestParser()
manifest = os.path.join(here, 'no-tests.ini')
parser.read(manifest)
self.assertEqual(len(parser.tests), 0)
self.assertTrue(len(parser.manifests()) == 1)
示例7: test_manifest_ignore
# 需要导入模块: from manifestparser import ManifestParser [as 别名]
# 或者: from manifestparser.ManifestParser import read [as 别名]
def test_manifest_ignore(self):
"""test manifest `ignore` parameter for ignoring directories"""
stub = self.create_stub()
try:
ManifestParser.populate_directory_manifests([stub], filename="manifest.ini", ignore=("subdir",))
parser = ManifestParser()
parser.read(os.path.join(stub, "manifest.ini"))
self.assertEqual([i["name"] for i in parser.tests], ["bar", "fleem", "foo"])
self.assertFalse(os.path.exists(os.path.join(stub, "subdir", "manifest.ini")))
except:
raise
finally:
shutil.rmtree(stub)
示例8: test_manifest_ignore
# 需要导入模块: from manifestparser import ManifestParser [as 别名]
# 或者: from manifestparser.ManifestParser import read [as 别名]
def test_manifest_ignore(self):
"""test manifest `ignore` parameter for ignoring directories"""
stub = self.create_stub()
try:
ManifestParser.populate_directory_manifests([stub], filename='manifest.ini', ignore=('subdir',))
parser = ManifestParser()
parser.read(os.path.join(stub, 'manifest.ini'))
self.assertEqual([i['name'] for i in parser.tests],
['bar', 'fleem', 'foo'])
self.assertFalse(os.path.exists(os.path.join(stub, 'subdir', 'manifest.ini')))
except:
raise
finally:
shutil.rmtree(stub)
示例9: test_install_from_manifest
# 需要导入模块: from manifestparser import ManifestParser [as 别名]
# 或者: from manifestparser.ManifestParser import read [as 别名]
def test_install_from_manifest(self):
temp_manifest = addon_stubs.generate_manifest()
m = ManifestParser()
m.read(temp_manifest)
addons = m.get()
# Obtain details of addons to install from the manifest
addons_to_install = [self.am.addon_details(x['path'])['id'] for x in addons]
self.am.install_from_manifest(temp_manifest)
# Generate a list of addons installed in the profile
addons_installed = [unicode(x[:-len('.xpi')]) for x in os.listdir(os.path.join(
self.profile.profile, 'extensions', 'staged'))]
self.assertEqual(addons_installed.sort(), addons_to_install.sort())
# Cleanup the temporary addon and manifest directories
mozfile.rmtree(os.path.dirname(temp_manifest))
示例10: test_convert_directory_manifests_in_place
# 需要导入模块: from manifestparser import ManifestParser [as 别名]
# 或者: from manifestparser.ManifestParser import read [as 别名]
def test_convert_directory_manifests_in_place(self):
"""
keep the manifests in place
"""
stub = self.create_stub()
try:
ManifestParser.populate_directory_manifests([stub], filename="manifest.ini")
self.assertEqual(sorted(os.listdir(stub)), ["bar", "fleem", "foo", "manifest.ini", "subdir"])
parser = ManifestParser()
parser.read(os.path.join(stub, "manifest.ini"))
self.assertEqual([i["name"] for i in parser.tests], ["subfile", "bar", "fleem", "foo"])
parser = ManifestParser()
parser.read(os.path.join(stub, "subdir", "manifest.ini"))
self.assertEqual(len(parser.tests), 1)
self.assertEqual(parser.tests[0]["name"], "subfile")
except:
raise
finally:
shutil.rmtree(stub)
示例11: test_directory_to_manifest
# 需要导入模块: from manifestparser import ManifestParser [as 别名]
# 或者: from manifestparser.ManifestParser import read [as 别名]
def test_directory_to_manifest(self):
"""
Test our ability to convert a static directory structure to a
manifest.
"""
# First, stub out a directory with files in it::
def create_stub():
directory = tempfile.mkdtemp()
for i in 'foo', 'bar', 'fleem':
file(os.path.join(directory, i), 'w').write(i)
subdir = os.path.join(directory, 'subdir')
os.mkdir(subdir)
file(os.path.join(subdir, 'subfile'), 'w').write('baz')
return directory
stub = create_stub()
self.assertTrue(os.path.exists(stub) and os.path.isdir(stub))
# Make a manifest for it:
self.assertEqual(convert([stub]),
"""[bar]
[fleem]
[foo]
[subdir/subfile]""")
shutil.rmtree(stub) # cleanup
# Now do the same thing but keep the manifests in place:
stub = create_stub()
convert([stub], write='manifest.ini')
self.assertEqual(sorted(os.listdir(stub)),
['bar', 'fleem', 'foo', 'manifest.ini', 'subdir'])
parser = ManifestParser()
parser.read(os.path.join(stub, 'manifest.ini'))
self.assertEqual([i['name'] for i in parser.tests],
['subfile', 'bar', 'fleem', 'foo'])
parser = ManifestParser()
parser.read(os.path.join(stub, 'subdir', 'manifest.ini'))
self.assertEqual(len(parser.tests), 1)
self.assertEqual(parser.tests[0]['name'], 'subfile')
shutil.rmtree(stub)
示例12: test_convert_directory_manifests_in_place
# 需要导入模块: from manifestparser import ManifestParser [as 别名]
# 或者: from manifestparser.ManifestParser import read [as 别名]
def test_convert_directory_manifests_in_place(self):
"""
keep the manifests in place
"""
stub = self.create_stub()
try:
ManifestParser.populate_directory_manifests([stub], filename='manifest.ini')
self.assertEqual(sorted(os.listdir(stub)),
['bar', 'fleem', 'foo', 'manifest.ini', 'subdir'])
parser = ManifestParser()
parser.read(os.path.join(stub, 'manifest.ini'))
self.assertEqual([i['name'] for i in parser.tests],
['subfile', 'bar', 'fleem', 'foo'])
parser = ManifestParser()
parser.read(os.path.join(stub, 'subdir', 'manifest.ini'))
self.assertEqual(len(parser.tests), 1)
self.assertEqual(parser.tests[0]['name'], 'subfile')
except:
raise
finally:
shutil.rmtree(stub)
示例13: install_from_manifest
# 需要导入模块: from manifestparser import ManifestParser [as 别名]
# 或者: from manifestparser.ManifestParser import read [as 别名]
def install_from_manifest(self, filepath):
"""
Installs addons from a manifest
:param filepath: path to the manifest of addons to install
"""
try:
from manifestparser import ManifestParser
except ImportError:
module_logger.critical(
"Installing addons from manifest requires the"
" manifestparser package to be installed.")
raise
manifest = ManifestParser()
manifest.read(filepath)
addons = manifest.get()
for addon in addons:
if '://' in addon['path'] or os.path.exists(addon['path']):
self.install_from_path(addon['path'])
continue
# No path specified, try to grab it off AMO
locale = addon.get('amo_locale', 'en_US')
query = 'https://services.addons.mozilla.org/' + locale + '/firefox/api/' \
+ AMO_API_VERSION + '/'
if 'amo_id' in addon:
# this query grabs information on the addon base on its id
query += 'addon/' + addon['amo_id']
else:
# this query grabs information on the first addon returned from a search
query += 'search/' + addon['name'] + '/default/1'
install_path = AddonManager.get_amo_install_path(query)
self.install_from_path(install_path)
self.installed_manifests.append(filepath)