-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #142 from Rechi/check/reverseDependencies
add reverse dependencies check
- Loading branch information
Showing
9 changed files
with
180 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
""" | ||
Copyright (C) 2018 Team Kodi | ||
This file is part of Kodi - kodi.tv | ||
SPDX-License-Identifier: GPL-3.0-only | ||
See LICENSES/README.md for more information. | ||
""" | ||
|
||
from .AddonDependency import AddonDependency | ||
|
||
import xml.etree.ElementTree as ET | ||
|
||
|
||
class Addon(object): | ||
def __init__(self, addon_xml: ET.Element): | ||
super(Addon, self).__init__() | ||
self.id = addon_xml.get('id') | ||
self.version = addon_xml.get('version') | ||
self.dependencies = [] | ||
for dependency in addon_xml.findall('./requires/import'): | ||
self.dependencies.append(AddonDependency(dependency)) | ||
|
||
def __eq__(self, other): | ||
return self.id == other.id and self.version == other.version | ||
|
||
def dependsOn(self, addonId): | ||
for dependency in self.dependencies: | ||
if dependency.id == addonId: | ||
return True | ||
return False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
""" | ||
Copyright (C) 2018 Team Kodi | ||
This file is part of Kodi - kodi.tv | ||
SPDX-License-Identifier: GPL-3.0-only | ||
See LICENSES/README.md for more information. | ||
""" | ||
|
||
from distutils.version import LooseVersion | ||
import xml.etree.ElementTree as ET | ||
|
||
|
||
class AddonDependency(object): | ||
def __init__(self, import_xml: ET.Element): | ||
super(AddonDependency, self).__init__() | ||
self.id = import_xml.get('addon') | ||
self.version = None | ||
if import_xml.get('version') is not None: | ||
self.version = LooseVersion(import_xml.get('version')) | ||
self.optional = import_xml.get('optional', False) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
""" | ||
Copyright (C) 2018 Team Kodi | ||
This file is part of Kodi - kodi.tv | ||
SPDX-License-Identifier: GPL-3.0-only | ||
See LICENSES/README.md for more information. | ||
""" | ||
|
||
from .Addon import Addon | ||
|
||
import gzip | ||
import requests | ||
import xml.etree.ElementTree as ET | ||
from io import BytesIO | ||
|
||
|
||
class Repository(object): | ||
def __init__(self, version, path): | ||
super(Repository, self).__init__() | ||
self.version = version | ||
self.path = path | ||
gz_file = requests.get(path, timeout=(10, 10)).content | ||
with gzip.open(BytesIO(gz_file), 'rb') as xml_file: | ||
content = xml_file.read() | ||
tree = ET.fromstring(content) | ||
self.addons = [] | ||
for addon in tree.findall("addon"): | ||
self.addons.append(Addon(addon)) | ||
|
||
def __contains__(self, addonId): | ||
for addon in self.addons: | ||
if addon.id == addonId: | ||
return True | ||
return False | ||
|
||
def find(self, addonId): | ||
for addon in self.addons: | ||
if addon.id == addonId: | ||
return addon | ||
return None | ||
|
||
def rdepends(self, addonId): | ||
rdepends = [] | ||
for addon in self.addons: | ||
if addon.dependsOn(addonId): | ||
rdepends.append(addon) | ||
return rdepends |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
""" | ||
Copyright (C) 2018 Team Kodi | ||
This file is part of Kodi - kodi.tv | ||
SPDX-License-Identifier: GPL-3.0-only | ||
See LICENSES/README.md for more information. | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters