Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
77 changes: 37 additions & 40 deletions index.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

# Import stuff.
import shutil # Used to copy files
import os # Used for identifying project root
from pathlib import Path # Identify if folder exists.
import re # Regular expressions
import json # API endpoint generation
Expand All @@ -22,13 +21,13 @@ def main():
# Step 0: Clean up "docs" and "temp" folder
###########

root = os.path.dirname(os.path.abspath(__file__)) + "/"
root = Path(Path(__file__)).parent

# Remove everything except for the DEBs.
DepictionGenerator.CleanUp()

try:
shutil.rmtree(root + "temp/")
shutil.rmtree(f"{root}/temp/")
except Exception:
pass

Expand All @@ -53,7 +52,7 @@ def main():

# Create folder for each tweak
for tweak in tweak_release:
PackageLister.CreateFolder("docs/assets/" + tweak['bundle_id'])
PackageLister.CreateFolder(f"docs/assets/{tweak['bundle_id']}")

###########
# Step 2: Copy all images
Expand All @@ -62,63 +61,63 @@ def main():
package_bundle_id = PackageLister.DirNameToBundleID(package_name)

try:
shutil.copy(root + "Packages/" + package_name + "/silica_data/icon.png",
root + "docs/assets/" + package_bundle_id + "/icon.png")
shutil.copy(f"{root}/Packages/{package_name}/silica_data/icon.png",
f"{root}/docs/assets/{package_bundle_id}/icon.png")
except Exception:
category = PackageLister.ResolveCategory(tweak_release, package_bundle_id)
category = re.sub(r'\([^)]*\)', '', category).strip()
try:
shutil.copy(root + "Styles/Generic/Icon/" + category + ".png",
root + "docs/assets/" + package_bundle_id + "/icon.png")
shutil.copy(f"{root}/Styles/Generic/Icon/{category}.png",
f"{root}/docs/assets/{package_bundle_id}/icon.png")
except Exception:
try:
shutil.copy(root + "Styles/Generic/Icon/Generic.png",
root + "docs/assets/" + package_bundle_id + "/icon.png")
shutil.copy(f"{root}/Styles/Generic/Icon/Generic.png",
f"{root}/docs/assets/{package_bundle_id}/icon.png")
except Exception:
PackageLister.ErrorReporter("Configuration Error!", "You are missing a file at " + root +
"Styles/Generic/Icon/Generic.png. Please place an icon here to be the repo's default.")
"/Styles/Generic/Icon/Generic.png. Please place an icon here to be the repo's default.")

try:
shutil.copy(root + "Packages/" + package_name + "/silica_data/banner.png",
root + "docs/assets/" + package_bundle_id + "/banner.png")
shutil.copy(f"{root}/Packages/{package_name}/silica_data/banner.png",
f"{root}/docs/assets/{package_bundle_id}/banner.png")
except Exception:
category = PackageLister.ResolveCategory(tweak_release, package_bundle_id)
category = re.sub(r'\([^)]*\)', '', category).strip()
try:
shutil.copy(root + "Styles/Generic/Banner/" + category + ".png",
root + "docs/assets/" + package_bundle_id + "/banner.png")
shutil.copy(f"{root}/Styles/Generic/Banner/{category}.png",
f"{root}/docs/assets/{package_bundle_id}/banner.png")
except Exception:
try:
shutil.copy(root + "Styles/Generic/Banner/Generic.png",
root + "docs/assets/" + package_bundle_id + "/banner.png")
shutil.copy(f"{root}/Styles/Generic/Banner/Generic.png",
f"{root}/docs/assets/{package_bundle_id}/banner.png")
except Exception:
PackageLister.ErrorReporter("Configuration Error!", "You are missing a file at " + root +
"Styles/Generic/Banner/Generic.png. Please place a banner here to be the repo's default.")
"/Styles/Generic/Banner/Generic.png. Please place a banner here to be the repo's default.")

try:
shutil.copy(root + "Packages/" + package_name + "/silica_data/description.md",
root + "docs/assets/" + package_bundle_id + "/description.md")
shutil.copy(f"{root}/Packages/{package_name}/silica_data/description.md",
f"{root}/docs/assets/{package_bundle_id}/description.md")
except Exception:
pass

try:
shutil.copytree(root + "Packages/" + package_name + "/silica_data/screenshots",
root + "docs/assets/" + package_bundle_id + "/screenshot")
shutil.copytree(f"{root}/Packages/{package_name}/silica_data/screenshots",
f"{root}/docs/assets/{package_bundle_id}/screenshot")
except Exception:
pass
try:
shutil.copy(root + "Styles/icon.png", root + "docs/CydiaIcon.png")
shutil.copy(f"{root}/Styles/icon.png", f"{root}/docs/CydiaIcon.png")
except Exception:
PackageLister.ErrorReporter("Configuration Error!", "You are missing a file at " + root + "Styles/icon.png. "
PackageLister.ErrorReporter("Configuration Error!", "You are missing a file at " + root + "/Styles/icon.png. "
"Please add a PNG here to act as the repo's icon.")

###########
# Step 3: Generate HTML depictions and copy stylesheet
###########

# Copy CSS and JS over
shutil.copy(root + "Styles/index.css", root + "docs/web/index.css")
shutil.copy(root + "Styles/index.js", root + "docs/web/index.js")
shutil.copy(f"{root}/Styles/index.css", f"{root}/docs/web/index.css")
shutil.copy(f"{root}/Styles/index.js", f"{root}/docs/web/index.js")

# Generate index.html
index_html = DepictionGenerator.RenderIndexHTML()
Expand All @@ -128,7 +127,7 @@ def main():
# Generate per-tweak depictions
for tweak_data in tweak_release:
tweak_html = DepictionGenerator.RenderPackageHTML(tweak_data)
PackageLister.CreateFile("docs/depiction/web/" + tweak_data['bundle_id'] + ".html", tweak_html)
PackageLister.CreateFile(f"docs/depiction/web/{tweak_data['bundle_id']}.html", tweak_html)

if "github.io" not in repo_settings['cname'].lower():
PackageLister.CreateFile("docs/CNAME", repo_settings['cname'])
Expand All @@ -144,9 +143,9 @@ def main():
# Generate per-tweak depictions
for tweak_data in tweak_release:
tweak_json = DepictionGenerator.RenderPackageNative(tweak_data)
PackageLister.CreateFile("docs/depiction/native/" + tweak_data['bundle_id'] + ".json", tweak_json)
PackageLister.CreateFile(f"docs/depiction/native/{tweak_data['bundle_id']}.json", tweak_json)
help_depiction = DepictionGenerator.RenderNativeHelp(tweak_data)
PackageLister.CreateFile("docs/depiction/native/help/" + tweak_data['bundle_id'] + ".json", help_depiction)
PackageLister.CreateFile(f"docs/depiction/native/help/{tweak_data['bundle_id']}.json", help_depiction)

###########
# Step 5: Generate Release file from settings.json.
Expand All @@ -164,31 +163,29 @@ def main():
for package_name in PackageLister.ListDirNames():
bundle_id = PackageLister.DirNameToBundleID(package_name)
try:
shutil.copytree(root + "Packages/" + package_name, root + "temp/" + bundle_id)
shutil.rmtree(root + "temp/" + bundle_id + "/silica_data")
shutil.copytree(f"{root}/Packages/{package_name}", f"{root}/temp/{bundle_id}")
shutil.rmtree(f"{root}/temp/{bundle_id}/silica_data")
except Exception:
try:
shutil.rmtree(root + "temp/" + bundle_id + "/silica_data")
shutil.rmtree(f"{root}/temp/{bundle_id}/silica_data")
except Exception:
pass

script_check = Path(root + "Packages/" + package_name + "/silica_data/scripts/")
script_check = Path(f"{root}/Packages/{package_name}/silica_data/scripts/")
if script_check.is_dir():
shutil.copytree(root + "Packages/" + package_name + "/silica_data/scripts", root + "temp/" + bundle_id
+ "/DEBIAN")
shutil.copytree(f"{root}/Packages/{package_name}/silica_data/scripts", f"{root}/temp/{bundle_id}/DEBIAN")
else:
PackageLister.CreateFolder("temp/" + bundle_id + "/DEBIAN")
PackageLister.CreateFolder(f"temp/{bundle_id}/DEBIAN")

###########
# Step 7: Generate CONTROL and DEB files and move them to docs/
###########

for tweak_data in tweak_release:
control_file = DebianPackager.CompileControl(tweak_data, repo_settings)
PackageLister.CreateFile("temp/" + tweak_data['bundle_id'] + "/DEBIAN/control", control_file)
PackageLister.CreateFile(f"temp/{tweak_data['bundle_id']}/DEBIAN/control", control_file)
DebianPackager.CreateDEB(tweak_data['bundle_id'], tweak_data['version'])
shutil.copy(root + "temp/" + tweak_data['bundle_id'] + ".deb", root + "docs/pkg/" + tweak_data['bundle_id']
+ ".deb")
shutil.copy(f"{root}/temp/{tweak_data['bundle_id']}.deb", f"{root}/docs/pkg/{tweak_data['bundle_id']}.deb")

###########
# Step 8: Generate Package file and hash/sign the Release file.
Expand All @@ -209,7 +206,7 @@ def main():
# Step 10: Push to GitHub
###########

shutil.rmtree(root + "temp/") # Clean-up the now-unneeded temp folder.
shutil.rmtree(f"{root}/temp/") # Clean-up the now-unneeded temp folder.

try:
if repo_settings['automatic_git'].lower() == "true":
Expand Down
4 changes: 1 addition & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
pathlib
pystache
datetime
mistune
arpy
Pillow
pydpkg
pydpkg
45 changes: 23 additions & 22 deletions util/PackageLister.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import json # Used to parse various JSON files
import os # Used to navigate files so we know what tweak folders exist.

from pathlib import Path # Used to navigate files so we know what tweak folders exist.
from PIL import Image # Used to get image screenshot size.


Expand All @@ -12,7 +13,7 @@ class PackageLister:
def __init__(self, version):
super(PackageLister, self).__init__()
self.version = version
self.root = os.path.dirname(os.path.abspath(__file__)) + "/../"
self.root = f"{Path(Path(__file__)).parent}/.."

def CreateFile(self, path, contents):
"""
Expand All @@ -21,7 +22,7 @@ def CreateFile(self, path, contents):
String path: A file location to create a file at. Is relative to project root.
String contents: The contents of the file to be created.
"""
with open(self.root + path, "w") as text_file:
with open(f"{self.root}/{path}", "w") as text_file:
text_file.write(contents)

def CreateFolder(self, path):
Expand All @@ -30,8 +31,8 @@ def CreateFolder(self, path):

String path: A file location to create a folder at. Is relative to project root.
"""
if not os.path.exists(self.root + path):
os.makedirs(self.root + path)
if not Path(f"{self.root}/{path}").exists():
Path(f"{self.root}/{path}").mkdir()
else:
pass

Expand All @@ -40,7 +41,7 @@ def ListDirNames(self):
List the file names for package entries.
"""
package_list = []
for folder in os.listdir(self.root + "Packages"):
for folder in Path(f"{self.root}/Packages").iterdir():
if folder.lower() != ".ds_store":
package_list.append(folder)
return package_list
Expand All @@ -52,12 +53,12 @@ def GetTweakRelease(self):
"""
tweak_release = []
for tweakEntry in PackageLister.ListDirNames(self):
with open(self.root + "Packages/" + tweakEntry + "/silica_data/index.json", "r") as content_file:
with open(f"{self.root}/Packages/{tweakEntry}/silica_data/index.json", "r") as content_file:
try:
data = json.load(content_file)
except Exception:
PackageLister.ErrorReporter(self, "Configuration Error!", "The package configuration file at \"" +
self.root + "Packages/" + tweakEntry + "/silica_data/index.json\" is malformatted. Please check"
self.root + f"/Packages/{tweakEntry}/silica_data/index.json\" is malformatted. Please check"
" for any syntax errors in a JSON linter and run Silica again.")
tweak_release.append(data)
return tweak_release
Expand All @@ -70,7 +71,7 @@ def GetScreenshots(self, tweak_data):
"""
image_list = []
try:
for folder in os.listdir(self.root + "docs/assets/" + tweak_data['bundle_id'] + "/screenshot/"):
for folder in Path(f"{self.root}/docs/assets/{tweak_data.get('bundle_id')}/screenshot/").iterdir():
if folder.lower() != ".ds_store":
image_list.append(folder)
except:
Expand All @@ -84,9 +85,9 @@ def GetScreenshotSize(self, tweak_data):
Object tweak_data: A single index of a "tweak release" object.
"""
try:
for folder in os.listdir(self.root + "docs/assets/" + tweak_data['bundle_id'] + "/screenshot/"):
for folder in Path(f"{self.root}/docs/assets/{tweak_data.get('bundle_id')}/screenshot/").iterdir():
if folder.lower() != ".ds_store":
with Image.open(self.root + "docs/assets/" + tweak_data['bundle_id'] + "/screenshot/" + folder) as img:
with Image.open(f"{self.root}/docs/assets/{tweak_data['bundle_id']}/screenshot/{folder}") as img:
width, height = img.size
# Make sure it's not too big.
# If height > width, make height 300, width proportional.
Expand All @@ -108,9 +109,9 @@ def DirNameToBundleID(self, package_name):
String package_name: The name of a folder in Packages/ that holds tweak information.
"""

with open(self.root + "Packages/" + package_name + "/silica_data/index.json", "r") as content_file:
with open(f"{self.root}/Packages/{package_name}/silica_data/index.json", "r") as content_file:
data = json.load(content_file)
return data['bundle_id']
return data.get('bundle_id')

def BundleIdToDirName(self, bundle_id):
"""
Expand All @@ -125,7 +126,7 @@ def BundleIdToDirName(self, bundle_id):
return None

def GetRepoSettings(self):
with open(self.root + "Styles/settings.json", "r") as content_file:
with open(f"{self.root}/Styles/settings.json", "r") as content_file:
try:
return json.load(content_file)
except Exception:
Expand All @@ -141,8 +142,8 @@ def FullPathCname(self, repo_settings):
Object repo_settings: An object of repo settings.
"""
try:
if repo_settings['subfolder'] != "":
subfolder = "/" + repo_settings['subfolder']
if repo_settings.get('subfolder') != "":
subfolder = f"/{repo_settings.get('subfolder')}"
except Exception:
subfolder = ""
return subfolder
Expand All @@ -155,8 +156,8 @@ def ResolveCategory(self, tweak_release, bundle_id):
String bundle_id: The bundle ID of the tweak.
"""
for tweak in tweak_release:
if tweak['bundle_id'] == bundle_id:
return tweak['section']
if tweak.get('bundle_id') == bundle_id:
return tweak.get('section')

def ResolveVersion(self, tweak_release, bundle_id):
"""
Expand All @@ -166,9 +167,9 @@ def ResolveVersion(self, tweak_release, bundle_id):
String bundle_id: The bundle ID of the tweak.
"""
for tweak in tweak_release:
if tweak['bundle_id'] == bundle_id:
return tweak['version']
if tweak.get('bundle_id') == bundle_id:
return tweak.get('version')

def ErrorReporter(self, title, message):
print('\033[91m- {0} -\n{1}\033[0m'.format(title, message))
quit()
print(f'\033[91m- {title} -\n{message}\033[0m')
quit()