├── .gitignore
├── LICENSE
├── README.md
├── addons.xml
├── addons.xml.md5
├── addonslist.txt
├── exclude.txt
├── index.html
├── repository.librarytools-master
├── addon.xml
├── fanart.jpg
├── icon.png
└── index.html
├── repository.librarytools
├── addon.xml
├── fanart.jpg
├── icon.png
├── index.html
├── repository.librarytools-1.0.0.zip
└── repository.librarytools-1.0.0.zip.md5
├── script.library.integration.tool
├── addon.xml
├── fanart.jpg
├── icon.png
├── index.html
├── script.library.integration.tool-0.1.0.zip
├── script.library.integration.tool-0.1.0.zip.md5
├── script.library.integration.tool-0.2.0.zip
├── script.library.integration.tool-0.2.0.zip.md5
├── script.library.integration.tool-0.2.1.zip
├── script.library.integration.tool-0.2.1.zip.md5
├── script.library.integration.tool-0.2.2.zip
├── script.library.integration.tool-0.2.2.zip.md5
├── script.library.integration.tool-0.3.0.zip
├── script.library.integration.tool-0.3.0.zip.md5
├── script.library.integration.tool-0.3.1.zip
├── script.library.integration.tool-0.3.1.zip.md5
├── script.library.integration.tool-0.3.2.zip
├── script.library.integration.tool-0.3.2.zip.md5
├── script.library.integration.tool-0.4.0.zip
├── script.library.integration.tool-0.4.0.zip.md5
├── script.library.integration.tool-0.4.1.zip
└── script.library.integration.tool-0.4.1.zip.md5
├── update-directory-structure.sh
├── update_repo.py
└── update_repo.sh
/.gitignore:
--------------------------------------------------------------------------------
1 | temp
2 | .DS_Store
3 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "{}"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright {yyyy} {name of copyright owner}
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # repository.librarytools
2 | Kodi repository for script.library.integration.tool
3 |
--------------------------------------------------------------------------------
/addons.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |7 | 8 | 9 | -------------------------------------------------------------------------------- /repository.librarytools-master/addon.xml: -------------------------------------------------------------------------------- 1 | 2 |
6 |7 | 8 | 9 | -------------------------------------------------------------------------------- /repository.librarytools/addon.xml: -------------------------------------------------------------------------------- 1 | 2 |
6 |7 | 8 | 9 | -------------------------------------------------------------------------------- /repository.librarytools/repository.librarytools-1.0.0.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patrick-klein/repository.librarytools/2c3de54ccb55c178487f5316ce794b06099bea18/repository.librarytools/repository.librarytools-1.0.0.zip -------------------------------------------------------------------------------- /repository.librarytools/repository.librarytools-1.0.0.zip.md5: -------------------------------------------------------------------------------- 1 | b4414b12ad2606550c1b3d3f5951272f 2 | 3 | -------------------------------------------------------------------------------- /script.library.integration.tool/addon.xml: -------------------------------------------------------------------------------- 1 | 2 |
6 |7 | 8 | 9 | -------------------------------------------------------------------------------- /script.library.integration.tool/script.library.integration.tool-0.1.0.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patrick-klein/repository.librarytools/2c3de54ccb55c178487f5316ce794b06099bea18/script.library.integration.tool/script.library.integration.tool-0.1.0.zip -------------------------------------------------------------------------------- /script.library.integration.tool/script.library.integration.tool-0.1.0.zip.md5: -------------------------------------------------------------------------------- 1 | e350aca23c998eafba9e1fcca6773954 2 | 3 | -------------------------------------------------------------------------------- /script.library.integration.tool/script.library.integration.tool-0.2.0.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patrick-klein/repository.librarytools/2c3de54ccb55c178487f5316ce794b06099bea18/script.library.integration.tool/script.library.integration.tool-0.2.0.zip -------------------------------------------------------------------------------- /script.library.integration.tool/script.library.integration.tool-0.2.0.zip.md5: -------------------------------------------------------------------------------- 1 | 86fe66abf0abf42c87adeb8e65cb62c6 2 | 3 | -------------------------------------------------------------------------------- /script.library.integration.tool/script.library.integration.tool-0.2.1.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patrick-klein/repository.librarytools/2c3de54ccb55c178487f5316ce794b06099bea18/script.library.integration.tool/script.library.integration.tool-0.2.1.zip -------------------------------------------------------------------------------- /script.library.integration.tool/script.library.integration.tool-0.2.1.zip.md5: -------------------------------------------------------------------------------- 1 | b68f1249108b6e77a7003e1deda53db6 2 | 3 | -------------------------------------------------------------------------------- /script.library.integration.tool/script.library.integration.tool-0.2.2.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patrick-klein/repository.librarytools/2c3de54ccb55c178487f5316ce794b06099bea18/script.library.integration.tool/script.library.integration.tool-0.2.2.zip -------------------------------------------------------------------------------- /script.library.integration.tool/script.library.integration.tool-0.2.2.zip.md5: -------------------------------------------------------------------------------- 1 | bdad33d30b7cc4a9c3422499b6dbdcad 2 | 3 | -------------------------------------------------------------------------------- /script.library.integration.tool/script.library.integration.tool-0.3.0.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patrick-klein/repository.librarytools/2c3de54ccb55c178487f5316ce794b06099bea18/script.library.integration.tool/script.library.integration.tool-0.3.0.zip -------------------------------------------------------------------------------- /script.library.integration.tool/script.library.integration.tool-0.3.0.zip.md5: -------------------------------------------------------------------------------- 1 | 57b24b1449b1a16c2c12388e1c9eb6df 2 | 3 | -------------------------------------------------------------------------------- /script.library.integration.tool/script.library.integration.tool-0.3.1.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patrick-klein/repository.librarytools/2c3de54ccb55c178487f5316ce794b06099bea18/script.library.integration.tool/script.library.integration.tool-0.3.1.zip -------------------------------------------------------------------------------- /script.library.integration.tool/script.library.integration.tool-0.3.1.zip.md5: -------------------------------------------------------------------------------- 1 | 214595c602e56b13066d55d76beefae4 2 | 3 | -------------------------------------------------------------------------------- /script.library.integration.tool/script.library.integration.tool-0.3.2.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patrick-klein/repository.librarytools/2c3de54ccb55c178487f5316ce794b06099bea18/script.library.integration.tool/script.library.integration.tool-0.3.2.zip -------------------------------------------------------------------------------- /script.library.integration.tool/script.library.integration.tool-0.3.2.zip.md5: -------------------------------------------------------------------------------- 1 | 4d98c54e27a1a0bd519e304c19770814 2 | 3 | -------------------------------------------------------------------------------- /script.library.integration.tool/script.library.integration.tool-0.4.0.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patrick-klein/repository.librarytools/2c3de54ccb55c178487f5316ce794b06099bea18/script.library.integration.tool/script.library.integration.tool-0.4.0.zip -------------------------------------------------------------------------------- /script.library.integration.tool/script.library.integration.tool-0.4.0.zip.md5: -------------------------------------------------------------------------------- 1 | 4c60c1d27ce9e135c4718a27e41a5960 2 | 3 | -------------------------------------------------------------------------------- /script.library.integration.tool/script.library.integration.tool-0.4.1.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patrick-klein/repository.librarytools/2c3de54ccb55c178487f5316ce794b06099bea18/script.library.integration.tool/script.library.integration.tool-0.4.1.zip -------------------------------------------------------------------------------- /script.library.integration.tool/script.library.integration.tool-0.4.1.zip.md5: -------------------------------------------------------------------------------- 1 | 232bb4d786932f213a8b9d5734fed395 2 | 3 | -------------------------------------------------------------------------------- /update-directory-structure.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Check if we are in the right directory 4 | ROOT=$(pwd) 5 | if [[ "$ROOT" != *repository.librarytools ]] 6 | then 7 | echo -e "Run this script inside the repository's root directory!" 8 | exit 1 9 | fi 10 | echo "Root Path: ${ROOT}" 11 | 12 | # Generate md5 checksum for every .zip file 13 | for ZIP in $(find ${ROOT} -name '*.zip'); do 14 | md5sum ${ZIP} | grep -o '^\S*' > ${ZIP}.md5 15 | echo "Updated ${ZIP}.md5" 16 | done 17 | 18 | # Update addons.xml md5 checksum 19 | md5sum ${ROOT}/addons.xml | grep -o '^\S*' > ${ROOT}/addons.xml.md5 20 | echo "Updated ${ROOT}/addons.xml.md5" 21 | 22 | # Generate index.html files 23 | for DIR in $(find ${ROOT} -path ${ROOT}/.git -prune -o -type d); do 24 | ( 25 | echo -e "\n\n
" 26 | ls -1pa -I.git "${DIR}" | grep -v "^\./$" | grep -v "^index\.html$" | awk '{ printf "%s\n",$1,$1 }' 27 | echo -e "\n\n" 28 | ) > "${DIR}/index.html" 29 | echo "Updated ${DIR}/index.html" 30 | done 31 | -------------------------------------------------------------------------------- /update_repo.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | r""" 3 | Create a Kodi add-on repository from add-on sources 4 | 5 | This tool extracts Kodi add-ons from their respective locations and 6 | copies the appropriate files into a Kodi add-on repository. Each add-on 7 | is placed in its own directory. Each contains the add-on metadata files 8 | and a zip archive. In addition, the repository catalog "addons.xml" is 9 | placed in the repository folder. 10 | 11 | Each add-on location is either a local path or a URL. If it is a local 12 | path, it can be to either an add-on folder or an add-on ZIP archive. If 13 | it is a URL, it should be to a Git repository and it should use the 14 | format: 15 | REPOSITORY_URL#BRANCH:PATH 16 | The first segment is the Git URL that would be used to clone the 17 | repository, (e.g., 18 | "https://github.com/chadparry/kodi-repository.chad.parry.org.git"). 19 | That is followed by an optional "#" sign and a branch or tag name, 20 | (e.g. "release-1.0"). If no branch name is specified, then the default 21 | is the repository's currently active branch, which is the same default 22 | as git-clone. Next comes an optional ":" sign and path. The path 23 | denotes the location of the add-on within the repository. If no path is 24 | specified, then the default is ".". 25 | 26 | For example, if you are in the directory that should contain addons.xml 27 | and you just copied a new version of the only add-on 28 | "repository.chad.parry.org" to a subdirectory, then you can create or 29 | update the addons.xml file with this command: 30 | 31 | ./create_repository.py repository.chad.parry.org 32 | 33 | As another example, here is the command that generates Chad Parry's 34 | Repository: 35 | 36 | create_repository.py \ 37 | --datadir=~/html/software/kodi \ 38 | --compressed \ 39 | https://github.com/chadparry\ 40 | /kodi-repository.chad.parry.org.git:repository.chad.parry.org \ 41 | https://github.com/chadparry\ 42 | /kodi-plugin.program.remote.control.browser.git\ 43 | :plugin.program.remote.control.browser 44 | 45 | This script has been tested with Python 2.7.6 and Python 3.4.3. It 46 | depends on the GitPython module. 47 | """ 48 | 49 | __author__ = "Chad Parry" 50 | __contact__ = "github@chad.parry.org" 51 | __copyright__ = "Copyright 2016 Chad Parry" 52 | __license__ = "GNU GENERAL PUBLIC LICENSE. Version 2, June 1991" 53 | __version__ = "1.2.2" 54 | 55 | 56 | import argparse 57 | import collections 58 | import gzip 59 | import hashlib 60 | import io 61 | import os 62 | import re 63 | import shutil 64 | import sys 65 | import tempfile 66 | import threading 67 | import xml.etree.ElementTree 68 | import zipfile 69 | import time 70 | from traceback import format_exc 71 | import platform 72 | import subprocess 73 | 74 | AddonMetadata = collections.namedtuple( 75 | 'AddonMetadata', ('id', 'version', 'root')) 76 | WorkerResult = collections.namedtuple( 77 | 'WorkerResult', ('addon_metadata', 'exc_info')) 78 | AddonWorker = collections.namedtuple('AddonWorker', ('thread', 'result_slot')) 79 | 80 | 81 | INFO_BASENAME = 'addon.xml' 82 | METADATA_BASENAMES = ( 83 | INFO_BASENAME, 84 | 'icon.png', 85 | 'fanart.jpg') 86 | 87 | 88 | def get_archive_basename(addon_metadata): 89 | return '{}-{}.zip'.format(addon_metadata.id, addon_metadata.version) 90 | 91 | 92 | def get_metadata_basenames(addon_metadata): 93 | return ([(basename, basename) for basename in METADATA_BASENAMES] + 94 | [( 95 | 'changelog.txt', 96 | 'changelog-{}.txt'.format(addon_metadata.version))]) 97 | 98 | 99 | def is_url(addon_location): 100 | return bool(re.match('[A-Za-z0-9+.-]+://.', addon_location)) 101 | 102 | 103 | def parse_metadata(metadata_file): 104 | # Parse the addon.xml metadata. 105 | tree = xml.etree.ElementTree.parse(metadata_file) 106 | root = tree.getroot() 107 | addon_metadata = AddonMetadata( 108 | root.get('id'), 109 | root.get('version'), 110 | root) 111 | # Validate the add-on ID. 112 | if (addon_metadata.id is None or 113 | re.search('[^a-z0-9._-]', addon_metadata.id)): 114 | raise RuntimeError('Invalid addon ID: ' + str(addon_metadata.id)) 115 | if (addon_metadata.version is None or 116 | not re.match(r'\d+\.\d+\.\d+$', addon_metadata.version)): 117 | raise RuntimeError( 118 | 'Invalid addon verson: ' + str(addon_metadata.version)) 119 | return addon_metadata 120 | 121 | 122 | def copy_metadata_files(source_folder, addon_target_folder, addon_metadata): 123 | for (source_basename, target_basename) in get_metadata_basenames( 124 | addon_metadata): 125 | source_path = os.path.join(source_folder, source_basename) 126 | if os.path.isfile(source_path): 127 | shutil.copyfile( 128 | source_path, 129 | os.path.join(addon_target_folder, target_basename)) 130 | 131 | 132 | def fetch_addon_from_git(addon_location, target_folder, temp_folder): 133 | alt_addonid = "" 134 | alt_addonname = "" 135 | git_branch = "master" 136 | addon_vars = addon_location.split("#") 137 | git_location = addon_vars[0] 138 | if len(addon_vars) > 1: 139 | git_branch = addon_vars[1] 140 | if len(addon_vars) > 2: 141 | alt_addonid = addon_vars[2] 142 | if len(addon_vars) > 3: 143 | alt_addonname = addon_vars[3] 144 | 145 | download_url = git_location + "/archive/%s.zip" % git_branch 146 | addon_id = git_location.split("/")[-1] 147 | 148 | zip_file = os.path.join(temp_folder, "%s%s.zip" %(addon_id,alt_addonid)) 149 | zip_file = os.path.abspath(zip_file) 150 | 151 | #download zip file for addon 152 | import requests 153 | response = requests.get(download_url, stream=True) 154 | with open(zip_file, 'wb') as out_file: 155 | shutil.copyfileobj(response.raw, out_file) 156 | del response 157 | 158 | #unzip 159 | addon_temp = os.path.join(temp_folder,addon_id + alt_addonid) 160 | addon_temp = os.path.abspath(addon_temp) 161 | os.makedirs(addon_temp) 162 | do_unzip(zip_file, addon_temp) 163 | addon_temp = os.path.join(addon_temp, "%s-%s" %(addon_id, git_branch) ) 164 | 165 | #if alt addonid is given, change the addonid (used for beta skin versions) 166 | if alt_addonid and alt_addonname: 167 | addon_file = os.path.join(addon_temp, "addon.xml") 168 | f = open(addon_file,'r') 169 | filedata = f.read() 170 | f.close() 171 | 172 | newdata = filedata.replace(addon_id, alt_addonid) 173 | body = newdata.replace('\r', '').replace('\n', '').replace('\t', '') 174 | addon_name = re.compile('name="(.*?)"').findall(body)[0] 175 | newdata = newdata.replace(addon_name, alt_addonname) 176 | f = open(addon_file,'w') 177 | f.write(newdata) 178 | f.close() 179 | 180 | 181 | #proceed with lookup from folder 182 | addon_metadata = fetch_addon_from_folder(addon_temp, target_folder) 183 | 184 | return addon_metadata 185 | 186 | 187 | def fetch_addon_from_folder(raw_addon_location, target_folder): 188 | try: 189 | addon_location = os.path.abspath(raw_addon_location) 190 | metadata_path = os.path.join(addon_location, INFO_BASENAME) 191 | addon_metadata = parse_metadata(metadata_path) 192 | addon_target_folder = os.path.join(target_folder, addon_metadata.id) 193 | 194 | #check current version 195 | cur_metadata_path = os.path.join(addon_target_folder, INFO_BASENAME) 196 | if os.path.exists(cur_metadata_path): 197 | cur_metadata = parse_metadata(cur_metadata_path) 198 | if cur_metadata.version == addon_metadata.version: 199 | print "Addon %s already has version %s on the repo, skipping..." % (addon_metadata.id, addon_metadata.version) 200 | return cur_metadata 201 | 202 | #if skin addon, build textures... 203 | if addon_metadata.id.startswith("skin."): 204 | buildskintextures(raw_addon_location) 205 | 206 | # Create the compressed add-on archive. 207 | if not os.path.isdir(addon_target_folder): 208 | os.mkdir(addon_target_folder) 209 | archive_path = os.path.join( 210 | addon_target_folder, get_archive_basename(addon_metadata)) 211 | 212 | with zipfile.ZipFile( 213 | archive_path, 'w', compression=zipfile.ZIP_DEFLATED) as archive: 214 | for (root, dirs, files) in os.walk(addon_location.decode("utf-8")): 215 | relative_root = os.path.join( 216 | addon_metadata.id, 217 | os.path.relpath(root, addon_location)) 218 | for relative_path in files: 219 | sourcefile = os.path.join(root, relative_path) 220 | destfile = os.path.join(relative_root, relative_path) 221 | archive.write(sourcefile, destfile) 222 | 223 | copy_metadata_files( 224 | addon_location, addon_target_folder, addon_metadata) 225 | 226 | except Exception as exc: 227 | print format_exc(sys.exc_info()) 228 | raise exc 229 | 230 | return addon_metadata 231 | 232 | def buildskintextures(addon_folder): 233 | #build skin media files and themes with texturepacker 234 | themes_dir = os.path.join(addon_folder, "themes") 235 | media_dir = os.path.join(addon_folder, "media") 236 | if os.path.isdir(media_dir): 237 | if not os.path.isdir(themes_dir): 238 | os.mkdir(themes_dir) 239 | #move existing media folder to themes dir 240 | shutil.move(media_dir, os.path.join(themes_dir, "Textures")) 241 | #recreate empty media dir 242 | os.makedirs(media_dir) 243 | for item in os.listdir(themes_dir): 244 | themedir = os.path.join(themes_dir, item) 245 | if os.path.isdir(themedir): 246 | theme_file = os.path.join(media_dir, "%s.xbt" % item) 247 | tpargs = '-dupecheck -input %s -output %s' %(themedir, theme_file) 248 | if "Windows" in platform.platform(): 249 | subprocess.Popen( ('TexturePacker.exe', tpargs )).wait() 250 | else: 251 | cmd = "./TexturePacker %s" % tpargs 252 | subprocess.Popen(cmd, shell=True).wait() 253 | #remove themes dir 254 | shutil.rmtree(themes_dir, ignore_errors=False) 255 | 256 | def samefile(file1, file2): 257 | return os.stat(file1) == os.stat(file2) 258 | 259 | def fetch_addon_from_zip(raw_addon_location, target_folder): 260 | addon_location = os.path.abspath(raw_addon_location) 261 | with zipfile.ZipFile( 262 | addon_location, compression=zipfile.ZIP_DEFLATED) as archive: 263 | # Find out the name of the archive's root folder. 264 | roots = frozenset( 265 | next(iter(path.split(os.path.sep)), '') 266 | for path in archive.namelist()) 267 | if len(roots) != 1: 268 | raise RuntimeError('Archive should contain one directory') 269 | root = next(iter(roots)) 270 | if not root: 271 | raise RuntimeError('Archive should contain a directory') 272 | 273 | metadata_file = archive.open(os.path.join(root, INFO_BASENAME)) 274 | addon_metadata = parse_metadata(metadata_file) 275 | addon_target_folder = os.path.join(target_folder, addon_metadata.id) 276 | 277 | # Copy the metadata files. 278 | if not os.path.isdir(addon_target_folder): 279 | os.mkdir(addon_target_folder) 280 | for (source_basename, target_basename) in get_metadata_basenames( 281 | addon_metadata): 282 | try: 283 | source_file = archive.open(os.path.join(root, source_basename)) 284 | except KeyError: 285 | continue 286 | with open( 287 | os.path.join(addon_target_folder, target_basename), 288 | 'wb') as target_file: 289 | shutil.copyfileobj(source_file, target_file) 290 | 291 | # Copy the archive. 292 | archive_basename = get_archive_basename(addon_metadata) 293 | archive_path = os.path.join(addon_target_folder, archive_basename) 294 | if (not samefile( 295 | os.path.dirname(addon_location), addon_target_folder) or 296 | os.path.basename(addon_location) != archive_basename): 297 | shutil.copyfile(addon_location, archive_path) 298 | 299 | return addon_metadata 300 | 301 | def do_unzip(zip_path, targetdir): 302 | zip_file = zipfile.ZipFile(zip_path, 'r', allowZip64=True) 303 | for fileinfo in zip_file.infolist(): 304 | #filename = fileinfo.filename 305 | filename = fileinfo.filename 306 | if not filename.endswith("/"): 307 | cur_path = os.path.join(targetdir, filename) 308 | basedir = os.path.dirname(cur_path) 309 | if not os.path.isdir(basedir): 310 | os.makedirs(basedir) 311 | #use shutil to support non-ascii formatted files in the zip 312 | outputfile = open(cur_path, "wb") 313 | shutil.copyfileobj(zip_file.open(fileinfo.filename), outputfile) 314 | outputfile.close() 315 | zip_file.close() 316 | print "UNZIP DONE of file %s" %(zip_path) 317 | 318 | def fetch_addon(addon_location, target_folder, result_slot, temp_folder): 319 | try: 320 | print "Processing %s" %addon_location 321 | if is_url(addon_location): 322 | addon_metadata = fetch_addon_from_git( 323 | addon_location, target_folder, temp_folder) 324 | elif os.path.isdir(addon_location): 325 | addon_metadata = fetch_addon_from_folder( 326 | addon_location, target_folder) 327 | elif os.path.isfile(addon_location): 328 | addon_metadata = fetch_addon_from_zip( 329 | addon_location, target_folder) 330 | else: 331 | raise RuntimeError('Path not found: ' + addon_location) 332 | result_slot.append(WorkerResult(addon_metadata, None)) 333 | except: 334 | result_slot.append(WorkerResult(None, sys.exc_info())) 335 | 336 | 337 | def get_addon_worker(addon_location, target_folder, temp_folder): 338 | result_slot = [] 339 | thread = threading.Thread(target=lambda: fetch_addon( 340 | addon_location, target_folder, result_slot, temp_folder)) 341 | return AddonWorker(thread, result_slot) 342 | 343 | def cleanup_dir(dirname): 344 | #cleanup directory from disk 345 | if "Windows" in platform.platform(): 346 | cmd = 'cmd' 347 | cmdargs = '/c rd /s /q %s' % dirname 348 | subprocess.Popen( (cmd, cmdargs )).wait() 349 | else: 350 | cmd = 'rm -Rf %s' % dirname 351 | subprocess.Popen( cmd, shell=True).wait() 352 | 353 | while os.path.isdir(dirname): 354 | print "wait for folder deletion" 355 | time.sleep(1) 356 | 357 | 358 | def create_repository( 359 | addon_locations, 360 | target_folder, 361 | info_path, 362 | checksum_path, 363 | is_compressed): 364 | 365 | # Import git lazily. 366 | if any(is_url(addon_location) for addon_location in addon_locations): 367 | try: 368 | global git 369 | import git 370 | except ImportError: 371 | raise RuntimeError( 372 | 'Please install GitPython: pip install gitpython') 373 | # Create the target folder. 374 | if not os.path.isdir(target_folder): 375 | os.mkdir(target_folder) 376 | 377 | # create temp folder 378 | #data_path = os.path.abspath(args.datadir) 379 | 380 | temp_folder = os.path.abspath(os.path.join(target_folder, "temp")) 381 | cleanup_dir(temp_folder) 382 | if not os.path.isdir(temp_folder): 383 | os.makedirs(temp_folder) 384 | 385 | # Fetch all the add-on sources in parallel. 386 | workers = [ 387 | get_addon_worker(addon_location, target_folder, temp_folder) 388 | for addon_location in addon_locations] 389 | for worker in workers: 390 | worker.thread.start() 391 | for worker in workers: 392 | worker.thread.join() 393 | 394 | # Collect the results from all the threads. 395 | metadata = [] 396 | for worker in workers: 397 | try: 398 | result = next(iter(worker.result_slot)) 399 | except StopIteration: 400 | raise RuntimeError('Addon worker did not report result') 401 | if result.exc_info is not None: 402 | raise result.exc_info[1] 403 | metadata.append(result.addon_metadata) 404 | 405 | # Generate the addons.xml file. 406 | root = xml.etree.ElementTree.Element('addons') 407 | for addon_metadata in metadata: 408 | root.append(addon_metadata.root) 409 | tree = xml.etree.ElementTree.ElementTree(root) 410 | with io.BytesIO() as info_file: 411 | tree.write(info_file, encoding='UTF-8', xml_declaration=True) 412 | info_contents = info_file.getvalue() 413 | 414 | if is_compressed: 415 | info_file = gzip.open(info_path, 'wb') 416 | else: 417 | info_file = open(info_path, 'wb') 418 | with info_file: 419 | info_file.write(info_contents) 420 | 421 | # Calculate the signature. 422 | digest = hashlib.md5(info_contents).hexdigest() 423 | with open(checksum_path, 'w') as sig: 424 | sig.write(digest) 425 | 426 | #cleanup temp files 427 | cleanup_dir(temp_folder) 428 | 429 | def main(): 430 | parser = argparse.ArgumentParser( 431 | description='Create a Kodi add-on repository from add-on sources') 432 | parser.add_argument( 433 | '--datadir', 434 | '-d', 435 | default='.', 436 | help='Path to place the add-ons [current directory]') 437 | parser.add_argument( 438 | '--info', 439 | '-i', 440 | help='''Path for the addons.xml file [DATADIR/addons.xml or 441 | DATADIR/addons.xml.gz if compressed]''') 442 | parser.add_argument( 443 | '--checksum', 444 | '-c', 445 | help='Path for the addons.xml.md5 file [DATADIR/addons.xml.md5]') 446 | parser.add_argument( 447 | '--compressed', 448 | '-z', 449 | action='store_true', 450 | help='Compress addons.xml with gzip') 451 | parser.add_argument( 452 | 'addon', 453 | nargs='*', 454 | metavar='ADDON', 455 | help='''Location of the add-on: either a path to a local folder or 456 | to a zip archive or a URL for a Git repository with the 457 | format REPOSITORY_URL#BRANCH:PATH''') 458 | 459 | #read addons to include from addonslist.txt file 460 | args = parser.parse_args() 461 | if os.path.exists("addonslist.txt"): 462 | with open("addonslist.txt") as f: 463 | for line in f.readlines(): 464 | if not line.startswith("#"): 465 | args.addon.append(line.strip('\n').strip('\t')) 466 | 467 | data_path = os.path.abspath(args.datadir) 468 | if args.info is None: 469 | if args.compressed: 470 | info_basename = 'addons.xml.gz' 471 | else: 472 | info_basename = 'addons.xml' 473 | info_path = os.path.join(data_path, info_basename) 474 | else: 475 | info_path = os.path.abspath(args.info) 476 | 477 | checksum_path = ( 478 | os.path.abspath(args.checksum) if args.checksum is not None 479 | else os.path.join(data_path, 'addons.xml.md5')) 480 | create_repository( 481 | args.addon, data_path, info_path, checksum_path, args.compressed) 482 | 483 | 484 | if __name__ == "__main__": 485 | main() 486 | -------------------------------------------------------------------------------- /update_repo.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | python update_repo.py 4 | ./update-directory-structure.sh 5 | --------------------------------------------------------------------------------