appstream-python 0.8__tar.gz → 0.8.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (25) hide show
  1. {appstream-python-0.8/appstream_python.egg-info → appstream_python-0.8.1}/PKG-INFO +1 -1
  2. {appstream-python-0.8 → appstream_python-0.8.1}/appstream_python/Collection.py +19 -3
  3. {appstream-python-0.8 → appstream_python-0.8.1}/appstream_python/Component.py +3 -3
  4. appstream_python-0.8.1/appstream_python/version.txt +1 -0
  5. {appstream-python-0.8 → appstream_python-0.8.1/appstream_python.egg-info}/PKG-INFO +1 -1
  6. {appstream-python-0.8 → appstream_python-0.8.1}/appstream_python.egg-info/SOURCES.txt +1 -0
  7. {appstream-python-0.8 → appstream_python-0.8.1}/tests/test_appstream_data.py +2 -0
  8. appstream_python-0.8.1/tests/test_collection.py +92 -0
  9. appstream-python-0.8/appstream_python/version.txt +0 -1
  10. {appstream-python-0.8 → appstream_python-0.8.1}/LICENSE +0 -0
  11. {appstream-python-0.8 → appstream_python-0.8.1}/MANIFEST.in +0 -0
  12. {appstream-python-0.8 → appstream_python-0.8.1}/README.md +0 -0
  13. {appstream-python-0.8 → appstream_python-0.8.1}/appstream_python/Release.py +0 -0
  14. {appstream-python-0.8 → appstream_python-0.8.1}/appstream_python/Shared.py +0 -0
  15. {appstream-python-0.8 → appstream_python-0.8.1}/appstream_python/StandardConstants.py +0 -0
  16. {appstream-python-0.8 → appstream_python-0.8.1}/appstream_python/__init__.py +0 -0
  17. {appstream-python-0.8 → appstream_python-0.8.1}/appstream_python/_helper.py +0 -0
  18. {appstream-python-0.8 → appstream_python-0.8.1}/appstream_python.egg-info/dependency_links.txt +0 -0
  19. {appstream-python-0.8 → appstream_python-0.8.1}/appstream_python.egg-info/requires.txt +0 -0
  20. {appstream-python-0.8 → appstream_python-0.8.1}/appstream_python.egg-info/top_level.txt +0 -0
  21. {appstream-python-0.8 → appstream_python-0.8.1}/pyproject.toml +0 -0
  22. {appstream-python-0.8 → appstream_python-0.8.1}/setup.cfg +0 -0
  23. {appstream-python-0.8 → appstream_python-0.8.1}/tests/test_description.py +0 -0
  24. {appstream-python-0.8 → appstream_python-0.8.1}/tests/test_display_length.py +0 -0
  25. {appstream-python-0.8 → appstream_python-0.8.1}/tests/test_releases.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: appstream-python
3
- Version: 0.8
3
+ Version: 0.8.1
4
4
  Summary: A library for dealing with Freedesktop Appstream data
5
5
  Author-email: JakobDev <jakobdev@gmx.de>
6
6
  License: BSD-2-Clause
@@ -12,13 +12,24 @@ class AppstreamCollection:
12
12
  def _add_appstream_tag(self, tag: etree.Element) -> None:
13
13
  component_data = AppstreamComponent()
14
14
  component_data.parse_component_tag(tag)
15
+ self.add_component(component_data)
15
16
 
16
- self._components[component_data.id] = component_data
17
+ def add_component(self, component: AppstreamComponent) -> None:
18
+ "Adds a AppstreamComponent to the collection"
19
+ self._components[component.id] = component
17
20
 
18
- for i in component_data.categories:
21
+ for i in component.categories:
19
22
  if i not in self._categories:
20
23
  self._categories[i] = []
21
- self._categories[i].append(component_data.id)
24
+ self._categories[i].append(component.id)
25
+
26
+ def load_uncompressed_appstream_collection(self, path: str) -> None:
27
+ "Loads a uncompressed collection"
28
+ with open(path, "rb") as f:
29
+ root = etree.fromstring(f.read())
30
+
31
+ for i in root.findall("component"):
32
+ self._add_appstream_tag(i)
22
33
 
23
34
  def load_compressed_appstream_collection(self, path: str) -> None:
24
35
  "Loads a GZIP compressed collection"
@@ -72,5 +83,10 @@ class AppstreamCollection:
72
83
  with open(path, "w", encoding="utf-8") as f:
73
84
  f.write(etree.tostring(self.get_collection_tag(), pretty_print=True, xml_declaration=True, encoding="utf-8").decode("utf-8"))
74
85
 
86
+ def write_compressed_file(self, path: str) -> None:
87
+ "Writes a Uncompressed collection file"
88
+ with gzip.open(path, "wb") as f:
89
+ f.write(etree.tostring(self.get_collection_tag(), pretty_print=True, xml_declaration=True, encoding="utf-8"))
90
+
75
91
  def __len__(self) -> int:
76
92
  return len(self._components)
@@ -357,7 +357,7 @@ class AppstreamComponent:
357
357
 
358
358
  def get_available_languages(self) -> list[str]:
359
359
  "Returns a list with all available languages of the Component"
360
- lang_list = self.name.get_available_languages() + self.summary.get_available_languages() + self.developer_name.get_available_languages()
360
+ lang_list = self.name.get_available_languages() + self.summary.get_available_languages() + self.developer.name.get_available_languages()
361
361
  return list(set(lang_list))
362
362
 
363
363
  def _parse_relation_tag(self, tag: etree.Element) -> None:
@@ -409,11 +409,11 @@ class AppstreamComponent:
409
409
  self.description.load_tags(description_tag)
410
410
 
411
411
  metadata_license_tag = tag.find("metadata_license")
412
- if metadata_license_tag is not None:
412
+ if metadata_license_tag is not None and metadata_license_tag.text is not None:
413
413
  self.metadata_license = metadata_license_tag.text.strip()
414
414
 
415
415
  project_license_tag = tag.find("project_license")
416
- if project_license_tag is not None:
416
+ if project_license_tag is not None and project_license_tag.text is not None:
417
417
  self.project_license = project_license_tag.text.strip()
418
418
 
419
419
  categories_tag = tag.find("categories")
@@ -0,0 +1 @@
1
+ 0.8.1
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: appstream-python
3
- Version: 0.8
3
+ Version: 0.8.1
4
4
  Summary: A library for dealing with Freedesktop Appstream data
5
5
  Author-email: JakobDev <jakobdev@gmx.de>
6
6
  License: BSD-2-Clause
@@ -16,6 +16,7 @@ appstream_python.egg-info/dependency_links.txt
16
16
  appstream_python.egg-info/requires.txt
17
17
  appstream_python.egg-info/top_level.txt
18
18
  tests/test_appstream_data.py
19
+ tests/test_collection.py
19
20
  tests/test_description.py
20
21
  tests/test_display_length.py
21
22
  tests/test_releases.py
@@ -33,6 +33,8 @@ def assert_component_jdtextedit(component: appstream_python.AppstreamComponent)
33
33
  assert component.display_length["recommends"][0].px == 760
34
34
  assert component.display_length["recommends"][0].compare == "ge"
35
35
 
36
+ assert component.get_available_languages() == ["de"]
37
+
36
38
 
37
39
  def test_from_component_tag() -> None:
38
40
  root = etree.parse(JDTEXTEDIT_METAINFO)
@@ -0,0 +1,92 @@
1
+ import appstream_python
2
+ import pathlib
3
+
4
+
5
+ def _create_test_collection() -> appstream_python.AppstreamCollection:
6
+ collection = appstream_python.AppstreamCollection()
7
+
8
+ a_component = appstream_python.AppstreamComponent()
9
+ a_component.id = "com.example.A"
10
+ a_component.categories.append("Utility")
11
+ collection.add_component(a_component)
12
+
13
+ b_component = appstream_python.AppstreamComponent()
14
+ b_component.id = "com.example.B"
15
+ b_component.categories.append("Utility")
16
+ b_component.categories.append("Game")
17
+ collection.add_component(b_component)
18
+
19
+ c_component = appstream_python.AppstreamComponent()
20
+ c_component.id = "com.example.C"
21
+ c_component.categories.append("Game")
22
+ c_component.categories.append("System")
23
+ collection.add_component(c_component)
24
+
25
+ return collection
26
+
27
+
28
+ def test_collection_load_appstream_file() -> None:
29
+ collection = appstream_python.AppstreamCollection()
30
+ collection.load_appstream_file(pathlib.Path(__file__).parent / "data" / "AppStream" / "com.gitlab.JakobDev.jdTextEdit.metainfo.xml")
31
+ assert collection.get_component("com.gitlab.JakobDev.jdTextEdit").id == "com.gitlab.JakobDev.jdTextEdit"
32
+ assert len(collection) == 1
33
+
34
+
35
+ def test_collection_get_component_list() -> None:
36
+ component_list = _create_test_collection().get_component_list()
37
+ assert component_list[0].id == "com.example.A"
38
+ assert component_list[1].id == "com.example.B"
39
+ assert component_list[2].id == "com.example.C"
40
+ assert len(component_list) == 3
41
+
42
+
43
+ def test_collection_get_component_id_list() -> None:
44
+ assert _create_test_collection().get_component_id_list() == ["com.example.A", "com.example.B", "com.example.C"]
45
+
46
+
47
+ def test_collection_get_component() -> None:
48
+ collection = _create_test_collection()
49
+ assert collection.get_component("com.example.A").id == "com.example.A"
50
+ assert collection.get_component("com.example.B").id == "com.example.B"
51
+ assert collection.get_component("com.example.C").id == "com.example.C"
52
+ assert collection.get_component("com.example.D") is None
53
+
54
+
55
+ def test_collection_find_by_category() -> None:
56
+ collection = _create_test_collection()
57
+
58
+ utility_list = collection.find_by_category("Utility")
59
+ assert utility_list[0].id == "com.example.A"
60
+ assert utility_list[1].id == "com.example.B"
61
+ assert len(utility_list) == 2
62
+
63
+ game_list = collection.find_by_category("Game")
64
+ assert game_list[0].id == "com.example.B"
65
+ assert game_list[1].id == "com.example.C"
66
+ assert len(game_list) == 2
67
+
68
+ system_list = collection.find_by_category("System")
69
+ assert system_list[0].id == "com.example.C"
70
+ assert len(system_list) == 1
71
+
72
+ assert len(collection.find_by_category("Office")) == 0
73
+
74
+
75
+ def test_collection_write_load_uncompressed_collection(tmp_path: pathlib.Path) -> None:
76
+ old_collection = _create_test_collection()
77
+ old_collection.write_uncompressed_file(tmp_path / "test.xml")
78
+
79
+ new_collection = appstream_python.AppstreamCollection()
80
+ new_collection.load_uncompressed_appstream_collection(tmp_path / "test.xml")
81
+
82
+ assert old_collection.get_component_id_list() == new_collection.get_component_id_list()
83
+
84
+
85
+ def test_collection_write_load_compressed_collection(tmp_path: pathlib.Path) -> None:
86
+ old_collection = _create_test_collection()
87
+ old_collection.write_compressed_file(tmp_path / "test.xml.gz")
88
+
89
+ new_collection = appstream_python.AppstreamCollection()
90
+ new_collection.load_compressed_appstream_collection(tmp_path / "test.xml.gz")
91
+
92
+ assert old_collection.get_component_id_list() == new_collection.get_component_id_list()
@@ -1 +0,0 @@
1
- 0.8
File without changes