Update and fix Python 3 syntax

This commit is contained in:
Arszilla
2022-08-19 18:16:14 +03:00
parent 40554a9e3c
commit b4115fd0b2
8 changed files with 292 additions and 320 deletions

View File

@@ -1,14 +1,16 @@
#!/usr/bin/env python3
import sys
from datetime import datetime
import yaml # python3 -m pip install pyyaml --user
OUTPUT_FILE = './device-stats.md'
INPUT_FILE = './devices.yml'
OUTPUT_FILE = "./device-stats.md"
INPUT_FILE = "./devices.yml"
repo_msg = "\n_This table was [generated automatically](https://gitlab.com/kalilinux/build-scripts/kali-arm/-/blob/master/devices.yml) on {} from the [Kali ARM GitLab repository](https://gitlab.com/kalilinux/build-scripts/kali-arm)_\n".format(
datetime.now().strftime("%Y-%B-%d %H:%M:%S"))
repo_msg = f"""
_This table was [generated automatically](https://gitlab.com/kalilinux/build-scripts/kali-arm/-/blob/master/devices.yml) on {datetime.now().strftime('%Y-%B-%d %H:%M:%S')} from the [Kali ARM GitLab repository](https://gitlab.com/kalilinux/build-scripts/kali-arm)_
"""
qty_devices = 0
qty_images = 0
@@ -21,10 +23,10 @@ qty_images = 0
def yaml_parse(content):
result = ""
lines = content.split('\n')
lines = content.split("\n")
for line in lines:
if line.strip() and not line.strip().startswith('#'):
if line.strip() and not line.strip().startswith("#"):
result += line + "\n"
return yaml.safe_load(result)
@@ -39,18 +41,15 @@ def generate_table(data):
table += "|--------|-----------------------|-----------------------|\n"
# Iterate over per input (depth 1)
for yaml in data['devices']:
for yaml in data["devices"]:
# Iterate over vendors
for vendor in yaml.keys():
# Iterate over board (depth 2)
for board in yaml[vendor]:
qty_devices += 1
qty_images += len(board.get('images', default))
qty_images += len(board.get("images", default))
table += "| {} | {} | {} |\n".format(vendor,
board.get(
'name', default),
len(board.get('images', default)))
table += f"| {vendor} | {board.get('name', default)} | {len(board.get('images', default))} |\n"
return table
@@ -59,42 +58,39 @@ def read_file(file):
try:
with open(file) as f:
data = f.read()
f.close()
except Exception as e:
print("[-] Cannot open input file: {} - {}".format(file, e))
print(f"[-] Cannot open input file: {file} - {e}")
return data
def write_file(data, file):
try:
with open(file, 'w') as f:
meta = '---\n'
meta += 'title: Kali ARM Device Statistics\n'
meta += '---\n\n'
with open(file, "w") as f:
meta = "---\n"
meta += "title: Kali ARM Device Statistics\n"
meta += "---\n\n"
stats = "- The official [Kali ARM repository](https://gitlab.com/kalilinux/build-scripts/kali-arm) contains [build-scripts]((https://gitlab.com/kalilinux/build-scripts/kali-arm)) to support [**{}** Kali ARM devices](devices.html)\n".format(
str(str(qty_devices)))
stats = f"- The official [Kali ARM repository](https://gitlab.com/kalilinux/build-scripts/kali-arm) contains [build-scripts]((https://gitlab.com/kalilinux/build-scripts/kali-arm)) to support [**{qty_devices}** Kali ARM devices](devices.html)\n"
stats += "- [Kali ARM Statistics](index.html)\n\n"
f.write(str(meta))
f.write(str(stats))
f.write(str(data))
f.write(str(repo_msg))
f.close()
print('[+] File: {} successfully written'.format(OUTPUT_FILE))
print(f"[+] File: {OUTPUT_FILE} successfully written")
except Exception as e:
print("[-] Cannot write to output file: {} - {}".format(file, e))
print(f"[-] Cannot write to output file: {file} - {e}")
return 0
def print_summary():
print('Devices: {}'.format(qty_devices))
print('Images : {}'.format(qty_images))
print(f"Devices: {qty_devices}")
print(f"Images : {qty_images}")
def main(argv):

View File

@@ -1,15 +1,17 @@
#!/usr/bin/env python3
import re
import sys
from datetime import datetime
import yaml # python3 -m pip install pyyaml --user
OUTPUT_FILE = './devices.md'
INPUT_FILE = './devices.yml'
OUTPUT_FILE = "./devices.md"
INPUT_FILE = "./devices.yml"
repo_msg = "\n_This table was [generated automatically](https://gitlab.com/kalilinux/build-scripts/kali-arm/-/blob/master/devices.yml) on {} from the [Kali ARM GitLab repository](https://gitlab.com/kalilinux/build-scripts/kali-arm)_\n".format(
datetime.now().strftime("%Y-%B-%d %H:%M:%S"))
repo_msg = f"""
_This table was [generated automatically](https://gitlab.com/kalilinux/build-scripts/kali-arm/-/blob/master/devices.yml) on {datetime.now().strftime('%Y-%B-%d %H:%M:%S')} from the [Kali ARM GitLab repository](https://gitlab.com/kalilinux/build-scripts/kali-arm)_
"""
qty_devices = 0
@@ -50,7 +52,7 @@ def generate_table(data):
table += "|--------|-------|-----|-----------|-----|-----|---------------|----------|---------------------|-------|-----------|------|------|---------|---------------------|\n"
# Iterate over per input (depth 1)
for yaml in data['devices']:
for yaml in data["devices"]:
# Iterate over vendors
for vendor in yaml.keys():
# Iterate over board (depth 2)
@@ -63,48 +65,25 @@ def generate_table(data):
i = 0
for f in natural_sort(board.get('ram-size', default)):
for f in natural_sort(board.get("ram-size", default)):
if i > 0:
ram_size += ", "
ram_size += f
i += 1
i = 0
for f in natural_sort(board.get('storage', default)):
for f in natural_sort(board.get("storage", default)):
if i > 0:
storage += ", "
storage += f
i += 1
table += "| {} | {} | {} | {} | {} | {} | {} | {} | {} | {} | {} | {} | {} | {} | {} |\n".format(vendor,
board.get(
'name', default),
board.get(
'cpu', default),
board.get(
'cpu-cores', default),
board.get(
'gpu', default),
board.get(
'ram', default),
ram_size,
board.get(
'ethernet', default),
board.get(
'ethernet-speed', default),
board.get(
'wifi', default),
board.get(
'bluetooth', default),
board.get(
'usb2', default),
board.get(
'usb3', default),
storage,
board.get('notes', default))
table += f"| {vendor} | {board.get('name', default)} | {board.get('cpu', default)} | {board.get('cpu-cores', default)} | {board.get('gpu', default)} | {board.get('ram', default)} | {ram_size} | {board.get('ethernet', default)} | {board.get('ethernet-speed', default)} | {board.get('wifi', default)} | {board.get('bluetooth', default)} | {board.get('usb2', default)} | {board.get('usb3', default)} | {storage} | {board.get('notes', default)} |\n"
return table
@@ -113,41 +92,38 @@ def read_file(file):
try:
with open(file) as f:
data = f.read()
f.close()
except Exception as e:
print("[-] Cannot open input file: {} - {}".format(file, e))
print(f"[-] Cannot open input file: {file} - {e}")
return data
def write_file(data, file):
try:
with open(file, 'w') as f:
meta = '---\n'
meta += 'title: Kali ARM Devices\n'
meta += '---\n\n'
with open(file, "w") as f:
meta = "---\n"
meta += "title: Kali ARM Devices\n"
meta += "---\n\n"
stats = "- The official [Kali ARM repository](https://gitlab.com/kalilinux/build-scripts/kali-arm) contains build-scripts to support [**{}** Kali ARM devices](device-stats.html)\n".format(
str(str(qty_devices)))
stats = f"- The official [Kali ARM repository](https://gitlab.com/kalilinux/build-scripts/kali-arm) contains build-scripts to support [**{qty_devices}** Kali ARM devices](device-stats.html)\n"
stats += "- [Kali ARM Statistics](index.html)\n\n"
f.write(str(meta))
f.write(str(stats))
f.write(str(data))
f.write(str(repo_msg))
f.close()
print('[+] File: {} successfully written'.format(OUTPUT_FILE))
print(f"[+] File: {OUTPUT_FILE} successfully written")
except Exception as e:
print("[-] Cannot write to output file: {} - {}".format(file, e))
print(f"[-] Cannot write to output file: {file} - {e}")
return 0
def print_summary():
print('Devices: {}'.format(qty_devices))
print(f"Devices: {qty_devices}")
def main(argv):

View File

@@ -1,15 +1,17 @@
#!/usr/bin/env python3
# REF: https://www.kali.org/docs/arm/
import sys
from datetime import datetime
import yaml # python3 -m pip install pyyaml --user
OUTPUT_FILE = './image-overview.md'
INPUT_FILE = './devices.yml'
OUTPUT_FILE = "./image-overview.md"
INPUT_FILE = "./devices.yml"
repo_msg = "\n_This table was [generated automatically](https://gitlab.com/kalilinux/build-scripts/kali-arm/-/blob/master/devices.yml) on {} from the [Kali ARM GitLab repository](https://gitlab.com/kalilinux/build-scripts/kali-arm)_\n".format(
datetime.now().strftime("%Y-%B-%d %H:%M:%S"))
repo_msg = f"""
_This table was [generated automatically](https://gitlab.com/kalilinux/build-scripts/kali-arm/-/blob/master/devices.yml) on {datetime.now().strftime('%Y-%B-%d %H:%M:%S')} from the [Kali ARM GitLab repository](https://gitlab.com/kalilinux/build-scripts/kali-arm)_
"""
qty_devices = 0
qty_images = 0
@@ -26,10 +28,10 @@ qty_image_unknown = 0
def yaml_parse(content):
result = ""
lines = content.split('\n')
lines = content.split("\n")
for line in lines:
if line.strip() and not line.strip().startswith('#'):
if line.strip() and not line.strip().startswith("#"):
result += line + "\n"
return yaml.safe_load(result)
@@ -46,39 +48,40 @@ def generate_table(data):
table += "|---------------|--------------|----------------|-----------------|---------------|\n"
# Iterate over per input (depth 1)
for yaml in data['devices']:
for yaml in data["devices"]:
# Iterate over vendors
for vendor in yaml.keys():
# Iterate over board (depth 2)
for board in yaml[vendor]:
qty_devices += 1
# Iterate over per board
for key in board.keys():
# Check if there is an image for the board
if 'images' in key:
if "images" in key:
# Iterate over image (depth 3)
for image in board[key]:
if image['name'] not in images:
# ALT: images.append(image['image'])
images.append(image['name'])
if image["name"] not in images:
# ALT: images.append(image["image"])
images.append(image["name"])
qty_images += 1
build_script = image.get(
'build-script', default)
"build-script",
default
)
if build_script:
build_script = "[{0}](https://gitlab.com/kalilinux/build-scripts/kali-arm/-/blob/master/{0})".format(
build_script)
build_script = f"[{build_script}](https://gitlab.com/kalilinux/build-scripts/kali-arm/-/blob/master/{build_script})"
name = image.get('name', default)
slug = image.get('slug', default)
name = image.get("name", default)
slug = image.get("slug", default)
if name and slug:
name = "[{}](https://www.kali.org/docs/arm/{}/)".format(
name, slug)
name = f"[{name}](https://www.kali.org/docs/arm/{slug}/)"
support = image.get('support', default)
support = image.get("support", default)
if support == "kali":
status = "x | | "
@@ -96,15 +99,13 @@ def generate_table(data):
status = " | | "
qty_image_unknown += 1
table += "| {} | {} | {} |\n".format(name,
build_script,
status)
table += f"| {name} | {build_script} | {status} |\n"
# else:
# print('DUP {} / {}'.format(image['name'], image['image']))
# print(f"DUP {image["name"]} / {image["image"]}")
if 'images' not in board.keys():
print("[i] Possible issue with: " +
board.get('board', default) + " (no images)")
if "images" not in board.keys():
print(f"[i] Possible issue with: {board.get('board', default)} (no images)")
return table
@@ -113,48 +114,44 @@ def read_file(file):
try:
with open(file) as f:
data = f.read()
f.close()
except Exception as e:
print("[-] Cannot open input file: {} - {}".format(file, e))
print(f"[-] Cannot open input file: {file} - {e}")
return data
def write_file(data, file):
try:
with open(file, 'w') as f:
meta = '---\n'
meta += 'title: Kali ARM Image Overview\n'
meta += '---\n\n'
with open(file, "w") as f:
meta = "---\n"
meta += "title: Kali ARM Image Overview\n"
meta += "---\n\n"
stats = "- The official [Kali ARM repository](https://gitlab.com/kalilinux/build-scripts/kali-arm) contains [build-scripts]((https://gitlab.com/kalilinux/build-scripts/kali-arm)) to create [**{}** unique Kali ARM images](image-stats.html) for **{}** devices\n".format(
str(qty_images), str(qty_devices))
stats += "- The [next release](https://www.kali.org/releases/) cycle will include [**{}** Kali ARM images](image-stats.html) _([ready to download](https://www.kali.org/get-kali/#kali-arm))_, **{}** images which can be [built](https://gitlab.com/kalilinux/build-scripts/kali-arm), and {} retired images\n".format(
str(qty_image_kali), str(qty_image_community), str(qty_image_eol))
stats = f"- The official [Kali ARM repository](https://gitlab.com/kalilinux/build-scripts/kali-arm) contains [build-scripts]((https://gitlab.com/kalilinux/build-scripts/kali-arm)) to create [**{qty_images}** unique Kali ARM images](image-stats.html) for **{qty_devices}** devices\n"
stats += f"- The [next release](https://www.kali.org/releases/) cycle will include [**{qty_image_kali}** Kali ARM images](image-stats.html) _([ready to download](https://www.kali.org/get-kali/#kali-arm))_, **{qty_image_community}** images which can be [built](https://gitlab.com/kalilinux/build-scripts/kali-arm), and {qty_image_eol} retired images\n"
stats += "- [Kali ARM Statistics](index.html)\n\n"
f.write(str(meta))
f.write(str(stats))
f.write(str(data))
f.write(str(repo_msg))
f.close()
print('[+] File: {} successfully written'.format(OUTPUT_FILE))
print(f"[+] File: {OUTPUT_FILE} successfully written")
except Exception as e:
print("[-] Cannot write to output file: {} - {}".format(file, e))
print(f"[-] Cannot write to output file: {file} - {e}")
return 0
def print_summary():
print('Devices: {}'.format(qty_devices))
print('Images : {}'.format(qty_images))
print('- Kali : {}'.format(qty_image_kali))
print('- Community: {}'.format(qty_image_community))
print('- EOL : {}'.format(qty_image_eol))
print('- Unknown : {}'.format(qty_image_unknown))
print(f"Devices: {qty_devices}")
print(f"Images : {qty_images}")
print(f"- Kali : {qty_image_kali}")
print(f"- Community: {qty_image_community}")
print(f"- EOL : {qty_image_eol}")
print(f"- Unknown : {qty_image_unknown}")
def main(argv):

View File

@@ -1,16 +1,18 @@
#!/usr/bin/env python3
# REF: https://gitlab.com/kalilinux/nethunter/build-scripts/kali-nethunter-devices/-/blob/52cbfb36/scripts/generate_images_stats.py
import sys
from datetime import datetime
import yaml # python3 -m pip install pyyaml --user
OUTPUT_FILE = './image-stats.md'
OUTPUT_FILE = "./image-stats.md"
INPUT_FILE = './devices.yml'
INPUT_FILE = "./devices.yml"
repo_msg = "\n_This table was [generated automatically](https://gitlab.com/kalilinux/build-scripts/kali-arm/-/blob/master/devices.yml) on {} from the [Kali ARM GitLab repository](https://gitlab.com/kalilinux/build-scripts/kali-arm)_\n".format(
datetime.now().strftime("%Y-%B-%d %H:%M:%S"))
repo_msg = f"""
_This table was [generated automatically](https://gitlab.com/kalilinux/build-scripts/kali-arm/-/blob/master/devices.yml) on {datetime.now().strftime('%Y-%B-%d %H:%M:%S')} from the [Kali ARM GitLab repository](https://gitlab.com/kalilinux/build-scripts/kali-arm)_
"""
qty_images = 0
@@ -22,10 +24,10 @@ qty_images = 0
def yaml_parse(content):
result = ""
lines = content.split('\n')
lines = content.split("\n")
for line in lines:
if line.strip() and not line.strip().startswith('#'):
if line.strip() and not line.strip().startswith("#"):
result += line + "\n"
return yaml.safe_load(result)
@@ -39,7 +41,7 @@ def generate_table(data):
default = ""
# Iterate over per input (depth 1)
for yaml in data['devices']:
for yaml in data["devices"]:
# Iterate over vendors
for vendor in yaml.keys():
# Iterate over board (depth 2)
@@ -47,22 +49,20 @@ def generate_table(data):
# Iterate over per board
for key in board.keys():
# Check if there is an image for the board
if 'images' in key:
if "images" in key:
# Iterate over image (depth 3)
for image in board[key]:
images.append("{} ({})".format(image.get('name', default),
image.get('architecture', default)))
images.append(f"{image.get('name', default)} ({image.get('architecture', default)})")
if 'images' not in board.keys():
print("[i] Possible issue with: " +
board.get('board', default) + " (no images)")
if "images" not in board.keys():
print(f"[i] Possible issue with: {board.get('board', default)} (no images)")
table = "| [Image Name](images.html) (Architecture) |\n"
table += "|---------------------------|\n"
# iterate over all the devices
for device in sorted(set(images)):
table += "| {} |\n".format(device)
table += f"| {device} |\n"
qty_images = len(set(images))
@@ -73,7 +73,6 @@ def read_file(file):
try:
with open(file) as f:
data = f.read()
f.close()
except Exception as e:
print("[-] Cannot open input file: {} - {}".format(file, e))
@@ -83,10 +82,10 @@ def read_file(file):
def write_file(data, file):
try:
with open(file, 'w') as f:
meta = '---\n'
meta += 'title: Kali ARM Image Statistics\n'
meta += '---\n\n'
with open(file, "w") as f:
meta = "---\n"
meta += "title: Kali ARM Image Statistics\n"
meta += "---\n\n"
stats = "- The official [Kali ARM repository](https://gitlab.com/kalilinux/build-scripts/kali-arm) contains [build-scripts]((https://gitlab.com/kalilinux/build-scripts/kali-arm)) to create [**{}** unique Kali ARM images](images.html)\n".format(str(qty_images))
stats += "- [Kali ARM Statistics](index.html)\n\n"
@@ -95,18 +94,17 @@ def write_file(data, file):
f.write(str(stats))
f.write(str(data))
f.write(str(repo_msg))
f.close()
print('[+] File: {} successfully written'.format(OUTPUT_FILE))
print(f"[+] File: {OUTPUT_FILE} successfully written")
except Exception as e:
print("[-] Cannot write to output file: {} - {}".format(file, e))
print(f"[-] Cannot write to output file: {file} - {e}")
return 0
def print_summary():
print('Images: {}'.format(qty_images))
print(f"Images: {qty_images}")
def main(argv):

View File

@@ -5,12 +5,13 @@ from datetime import datetime
import yaml # python3 -m pip install pyyaml --user
OUTPUT_FILE = './images.md'
OUTPUT_FILE = "./images.md"
INPUT_FILE = './devices.yml'
INPUT_FILE = "./devices.yml"
repo_msg = "\n_This table was [generated automatically](https://gitlab.com/kalilinux/build-scripts/kali-arm/-/blob/master/devices.yml) on {} from the [Kali ARM GitLab repository](https://gitlab.com/kalilinux/build-scripts/kali-arm)_\n".format(
datetime.now().strftime("%Y-%B-%d %H:%M:%S"))
repo_msg = f"""
_This table was [generated automatically](https://gitlab.com/kalilinux/build-scripts/kali-arm/-/blob/master/devices.yml) on {datetime.now().strftime('%Y-%B-%d %H:%M:%S')} from the [Kali ARM GitLab repository](https://gitlab.com/kalilinux/build-scripts/kali-arm)_
"""
qty_devices = 0
qty_images = 0
@@ -24,10 +25,10 @@ qty_images_released = 0
def yaml_parse(content):
result = ""
lines = content.split('\n')
lines = content.split("\n")
for line in lines:
if line.strip() and not line.strip().startswith('#'):
if line.strip() and not line.strip().startswith("#"):
result += line + "\n"
return yaml.safe_load(result)
@@ -46,7 +47,7 @@ def generate_table(data):
table += "|------------|----------|--------------|-----------|---------|-------------------------------------------------|-----------------------|----------------|-------|\n"
# Iterate over per input (depth 1)
for yaml in data['devices']:
for yaml in data["devices"]:
# Iterate over vendors
for vendor in yaml.keys():
# Iterate over board (depth 2)
@@ -56,44 +57,29 @@ def generate_table(data):
# Iterate over per board
for key in board.keys():
# Check if there is an image for the board
if 'images' in key:
if "images" in key:
# Iterate over image (depth 3)
for image in board[key]:
#qty_images += 1
images.append("{}".format(
image.get('name', default)))
images.append(f"{image.get('name', default)}")
support = image.get('support', default)
support = image.get("support", default)
if support == "kali":
#qty_images_released += 1
images_released.append(
"{}".format(image.get('name', default)))
f"{image.get('name', default)}")
slug = image.get('slug', default)
slug = image.get("slug", default)
if slug:
slug = "[{0}](https://www.kali.org/docs/arm/{0}/)".format(slug)
slug = f"[{slug}](https://www.kali.org/docs/arm/{slug}/)"
table += "| {} | {} | {} | {} | {} | {} | {} | {} |\n".format(image.get('name', default),
image.get(
'image', default),
image.get(
'architecture', default),
image.get(
'preferred-image', default),
image.get(
'support', default),
slug,
image.get(
'kernel', default),
image.get(
'kernel-version', default),
image.get('image-notes', default))
table += f"| {image.get('name', default)} | {image.get('image', default)} | {image.get('architecture', default)} | {image.get('preferred-image', default)} | {image.get('support', default)} | {slug} | {image.get('kernel', default)} | {image.get('kernel-version', default)} | {image.get('image-notes', default)} |\n"
if 'images' not in board.keys():
print("[i] Possible issue with: " +
board.get('board', default) + " (no images)")
if "images" not in board.keys():
print(
f"[i] Possible issue with: {board.get('board', default)} (no images)")
qty_images = len(set(images))
qty_images_released = len(set(images_released))
@@ -105,45 +91,41 @@ def read_file(file):
try:
with open(file) as f:
data = f.read()
f.close()
except Exception as e:
print("[-] Cannot open input file: {} - {}".format(file, e))
print(f"[-] Cannot open input file: {file} - {e}")
return data
def write_file(data, file):
try:
with open(file, 'w') as f:
meta = '---\n'
meta += 'title: Kali ARM Images\n'
meta += '---\n\n'
with open(file, "w") as f:
meta = "---\n"
meta += "title: Kali ARM Images\n"
meta += "---\n\n"
stats = "- The official [Kali ARM repository](https://gitlab.com/kalilinux/build-scripts/kali-arm) contains [build-scripts]((https://gitlab.com/kalilinux/build-scripts/kali-arm)) to create [**{}** unique Kali ARM images](image-stats.html) for **{}** devices\n".format(
str(qty_images), str(qty_devices))
stats += "- The [next release](https://www.kali.org/releases/) cycle will include [**{}** Kali ARM images](image-stats.html) _([ready to download](https://www.kali.org/get-kali/#kali-arm))_\n".format(
str(qty_images_released))
stats = f"- The official [Kali ARM repository](https://gitlab.com/kalilinux/build-scripts/kali-arm) contains [build-scripts]((https://gitlab.com/kalilinux/build-scripts/kali-arm)) to create [**{qty_images}** unique Kali ARM images](image-stats.html) for **{qty_devices}** devices\n"
stats += f"- The [next release](https://www.kali.org/releases/) cycle will include [**{qty_images_released}** Kali ARM images](image-stats.html) _([ready to download](https://www.kali.org/get-kali/#kali-arm))_\n"
stats += "- [Kali ARM Statistics](index.html)\n\n"
f.write(str(meta))
f.write(str(stats))
f.write(str(data))
f.write(str(repo_msg))
f.close()
print('[+] File: {} successfully written'.format(OUTPUT_FILE))
print(f"[+] File: {OUTPUT_FILE} successfully written")
except Exception as e:
print("[-] Cannot write to output file: {} - {}".format(file, e))
print(f"[-] Cannot write to output file: {file} - {e}")
return 0
def print_summary():
print('Devices : {}'.format(qty_devices))
print('Images : {}'.format(qty_images))
print('Images Released: {}'.format(qty_images_released))
print(f"Devices : {qty_devices}")
print(f"Images : {qty_images}")
print(f"Images Released: {qty_images_released}")
def main(argv):

View File

@@ -5,18 +5,19 @@ from datetime import datetime
import yaml # python3 -m pip install pyyaml --user
OUTPUT_FILE = './kernel-stats.md'
OUTPUT_FILE = "./kernel-stats.md"
INPUT_FILE = './devices.yml'
INPUT_FILE = "./devices.yml"
repo_msg = "\n_This table was [generated automatically](https://gitlab.com/kalilinux/build-scripts/kali-arm/-/blob/master/devices.yml) on {} from the [Kali ARM GitLab repository](https://gitlab.com/kalilinux/build-scripts/kali-arm)_\n".format(
datetime.now().strftime("%Y-%B-%d %H:%M:%S"))
repo_msg = f"""
_This table was [generated automatically](https://gitlab.com/kalilinux/build-scripts/kali-arm/-/blob/master/devices.yml) on {datetime.now().strftime('%Y-%B-%d %H:%M:%S')} from the [Kali ARM GitLab repository](https://gitlab.com/kalilinux/build-scripts/kali-arm)_
"""
qty_kernels = 0
qty_versions = {
'custom': 0,
'kali': 0,
'vendor': 0
"custom": 0,
"kali": 0,
"vendor": 0
}
# Input:
@@ -27,10 +28,10 @@ qty_versions = {
def yaml_parse(content):
result = ""
lines = content.split('\n')
lines = content.split("\n")
for line in lines:
if line.strip() and not line.strip().startswith('#'):
if line.strip() and not line.strip().startswith("#"):
result += line + "\n"
return yaml.safe_load(result)
@@ -43,7 +44,7 @@ def generate_table(data):
default = "unknown"
# Iterate over per input (depth 1)
for yaml in data['devices']:
for yaml in data["devices"]:
# Iterate over vendors
for vendor in yaml.keys():
# Iterate over board (depth 2)
@@ -51,31 +52,28 @@ def generate_table(data):
# Iterate over per board
for key in board.keys():
# Check if there is an image for the board
if 'images' in key:
if "images" in key:
# Iterate over image (depth 3)
for image in board[key]:
if image['name'] not in images:
# ALT: images.append(image['image'])
images.append(image['name'])
if image["name"] not in images:
# ALT: images.append(image["image"])
images.append(image["name"])
qty_kernels += 1
qty_versions[(
image.get('kernel', default))] += 1
qty_versions[(image.get("kernel", default))] += 1
# else:
# print('DUP {} / {}'.format(image['name'], image['image']))
# print(f"DUP {image['name']} / {image['image']}")
if 'images' not in board.keys():
print("[i] Possible issue with: " +
board.get('board', default) + " (no images)")
if "images" not in board.keys():
print(f"[i] Possible issue with: {board.get('board', default)} (no images)")
table = "| Kernel | Qty |\n"
table += "|--------|-----|\n"
# iterate over all the devices
for v in qty_versions:
table += "| {} | {} |\n".format(v.capitalize(),
str(qty_versions[v]))
table += f"| {v.capitalize()} | {qty_versions[v]} |\n"
return table
@@ -84,40 +82,38 @@ def read_file(file):
try:
with open(file) as f:
data = f.read()
f.close()
except Exception as e:
print("[-] Cannot open input file: {} - {}".format(file, e))
print(f"[-] Cannot open input file: {file} - {e}")
return data
def write_file(data, file):
try:
with open(file, 'w') as f:
meta = '---\n'
meta += 'title: Kali ARM Kernel Statistics\n'
meta += '---\n\n'
with open(file, "w") as f:
meta = "---\n"
meta += "title: Kali ARM Kernel Statistics\n"
meta += "---\n\n"
stats = "- The official [Kali ARM repository](https://gitlab.com/kalilinux/build-scripts/kali-arm) contains [build-scripts]((https://gitlab.com/kalilinux/build-scripts/kali-arm)) to create [**{}** unique Kali ARM images](images.html)\n".format(str(qty_kernels))
stats = f"- The official [Kali ARM repository](https://gitlab.com/kalilinux/build-scripts/kali-arm) contains [build-scripts]((https://gitlab.com/kalilinux/build-scripts/kali-arm)) to create [**{qty_kernels}** unique Kali ARM images](images.html)\n"
stats += "- [Kali ARM Statistics](index.html)\n\n"
f.write(str(meta))
f.write(str(stats))
f.write(str(data))
f.write(str(repo_msg))
f.close()
print('[+] File: {} successfully written'.format(OUTPUT_FILE))
print(f"[+] File: {OUTPUT_FILE} successfully written")
except Exception as e:
print("[-] Cannot write to output file: {} - {}".format(file, e))
print(f"[-] Cannot write to output file: {file} - {e}")
return 0
def print_summary():
print('Kernels: {}'.format(qty_kernels))
print(f"Kernels: {qty_kernels}")
def main(argv):

View File

@@ -5,18 +5,18 @@
###############################################
# Script to prepare the rpi-imager json script for Kali ARM quarterly releases.
# Based on ./bin/pre-release.py
##
#
# This should be run after images are created.
##
#
# It parses the YAML sections of the devices.yml and creates:
# - "<imagedir>/rpi-imager.json = "manifest file mapping image name to display name
##
#
# Dependencies:
# sudo apt -y install python3 python3-yaml xz-utils
##
#
# Usage:
# ./bin/post-release.py -i <input file> -r <release> -o <image directory>
##
#
# E.g.:
# ./bin/post-release.py -i devices.yml -r 2022.3 -o images/
@@ -43,7 +43,11 @@ qty_devices = 0
qty_images = 0
qty_release_images = 0
file_ext = ['xz', 'xz.sha256sum', 'sha256sum']
file_ext = [
"xz",
"xz.sha256sum",
"sha256sum"
]
# Input:
# ------------------------------------------------------------
@@ -61,16 +65,14 @@ def bail(message="", strerror=""):
prog = sys.argv[0]
if message != "":
outstr = "\nError: {}".format(message)
outstr = f"\nError: {message}"
if strerror != "":
outstr += "\nMessage: {}\n".format(strerror)
outstr += f"\nMessage: {strerror}\n"
else:
outstr += "\n\nUsage: {} -i <input file> -o <output directory> -r <release>".format(
prog)
outstr += "\nE.g. : {} -i devices.yml -o images/ -r {}.1\n".format(
prog, datetime.datetime.now().year)
outstr += f"\n\nUsage: {prog} -i <input file> -o <output directory> -r <release>"
outstr += f"\nE.g. : {prog} -i devices.yml -o images/ -r {datetime.datetime.now().year}.1\n"
print(outstr)
@@ -82,14 +84,21 @@ def getargs(argv):
try:
opts, args = getopt.getopt(
argv, "hi:o:r:", ["inputfile=", "imagedir=", "release="])
argv,
"hi:o:r:",
[
"inputfile=",
"imagedir=",
"release="
]
)
except getopt.GetoptError as e:
bail("Incorrect arguments: {}".format(e))
bail(f"Incorrect arguments: {e}")
if opts:
for opt, arg in opts:
if opt == '-h':
if opt == "-h":
bail()
elif opt in ("-i", "--inputfile"):
@@ -102,7 +111,7 @@ def getargs(argv):
imagedir = arg.rstrip("/")
else:
bail("Unrecognised argument: " + opt)
bail(f"Unrecognised argument: {opt}")
else:
bail("Failed to read arguments")
@@ -116,10 +125,10 @@ def getargs(argv):
def yaml_parse(content):
result = ""
lines = content.split('\n')
lines = content.split("\n")
for line in lines:
if line.strip() and not line.strip().startswith('#'):
if line.strip() and not line.strip().startswith("#"):
result += line + "\n"
return yaml.safe_load(result)
@@ -131,7 +140,7 @@ def jsonarray(devices, vendor, name, url, extract_size, extract_sha256, image_do
jsondata = {
"name": name,
"description": "Kali Linux ARM image for the {}".format(name),
"description": f"Kali Linux ARM image for the {name}",
"url": url,
"icon": "https://www.kali.org/images/favicon.svg",
"website": "https://www.kali.org/",
@@ -155,7 +164,7 @@ def generate_manifest(data):
devices = {}
# Iterate over per input (depth 1)
for yaml in data['devices']:
for yaml in data["devices"]:
# Iterate over vendors
for vendor in yaml.keys():
# @g0tmi1k: Feels like there is a cleaner way todo this
@@ -172,62 +181,69 @@ def generate_manifest(data):
# Iterate over per board
for key in board.keys():
# Check if there is an image for the board
if 'images' in key:
if "images" in key:
# Iterate over image (depth 3)
for image in board[key]:
qty_images += 1
# Check that it's not EOL or community supported
if image.get('support') == "kali":
name = image.get('name', default)
if image.get("support") == "kali":
name = image.get("name", default)
# If we haven't seen this image before for this vendor
if name not in img_seen:
img_seen.add(name)
qty_release_images += 1
filename = "kali-linux-{}-{}".format(
release, image.get('image', default))
filename = f"kali-linux-{release}-{image.get('image', default)}"
# Check to make sure files got created
for ext in file_ext:
check_file = '{}/{}.{}'.format(
imagedir, filename, ext)
check_file = f"{imagedir}/{filename}.{ext}"
if not os.path.isfile(check_file):
bail("Missing: '{}'".format(
check_file), "Please create the image before running")
bail(
f"Missing: '{check_file}'! Please create the image before running")
with open('{}/{}.xz.sha256sum'.format(imagedir, filename)) as f:
image_download_sha256 = f.read().split()[
0]
with open(f"{imagedir}/{filename}.xz.sha256sum") as f:
image_download_sha256 = f.read().split()[0]
with open('{}/{}.sha256sum'.format(imagedir, filename)) as f:
with open(f"{imagedir}/{filename}.sha256sum") as f:
extract_sha256 = f.read().split()[0]
url = "https://kali.download/arm-images/kali-{}/{}.xz".format(
release, filename)
url = f"https://kali.download/arm-images/kali-{release}/{filename}.xz"
# @g0tmi1k: not happy about external OS, rather keep it in python (import lzma)
try:
unxz = subprocess.check_output(
"unxz --verbose --list {}/{}.xz | grep 'Uncompressed'".format(imagedir, filename), shell=True)
f"unxz --verbose --list {imagedir}/{filename}.xz | grep 'Uncompressed'", shell=True)
extract_size = re.findall(
r'\((.*?) B\)', str(unxz))[0]
r"\((.*?) B\)",
str(unxz)
)[0]
extract_size = extract_size.replace(
',', '')
",",
""
)
extract_size = int(extract_size)
except subprocess.CalledProcessError as e:
#print("command '{}' return with error (code {})".format(e.cmd, e.returncode))
#print(f"command "{e.cmd}" return with error (code {e.returncode})")
extract_size = 0
#image_download_size = os.stat('{}/{}.xz'.format(imagedir, filename)).st_size
image_download_size = os.path.getsize(
'{}/{}.xz'.format(imagedir, filename))
jsonarray(devices, 'os_list', name, url, extract_size,
extract_sha256, image_download_size, image_download_sha256)
#image_download_size = os.stat(f'{imagedir}/{filename}.xz').st_size
image_download_size = os.path.getsize(f"{imagedir}/{filename}.xz")
jsonarray(
devices,
"os_list",
name,
url,
extract_size,
extract_sha256,
image_download_size,
image_download_sha256
)
return json.dumps(devices, indent=2)
@@ -238,7 +254,7 @@ def createdir(dir):
os.makedirs(dir)
except:
bail('Directory "' + dir + '" does not exist and cannot be created')
bail(f"Directory {dir} does not exist and cannot be created")
return 0
@@ -247,22 +263,20 @@ def readfile(file):
try:
with open(file) as f:
data = f.read()
f.close()
except:
bail("Cannot open input file: " + file)
bail(f"Cannot open input file: {file}")
return data
def writefile(data, file):
try:
with open(file, 'w') as f:
with open(file, "w") as f:
f.write(str(data))
f.close()
except:
bail("Cannot write to output file: " + file)
bail(f"Cannot write to output file: {file}")
return 0
@@ -278,7 +292,7 @@ def main(argv):
bail("Missing arguments")
# Assign variables
manifest = imagedir + "/rpi-imager.json"
manifest = f"{imagedir}/rpi-imager.json"
data = readfile(inputfile)
# Get data
@@ -292,12 +306,12 @@ def main(argv):
writefile(manifest_list, manifest)
# Print result and exit
print('\nStats:')
print(' - Total devices\t: {}'.format(qty_devices))
print(' - Total images\t: {}'.format(qty_images))
print(' - {} rpi images\t: {}'.format(release, qty_release_images))
print("\nStats:")
print(f" - Total devices\t: {qty_devices}")
print(f" - Total images\t: {qty_images}")
print(f" - {release} rpi images\t: {qty_release_images}")
print("\n")
print('Manifest file created\t: {}'.format(manifest))
print(f"Manifest file created\t: {manifest}")
exit(0)

View File

@@ -5,18 +5,18 @@
###############################################
# Script to prepare Kali ARM quarterly release
##
#
# This should be run either before or after images are created.
##
#
# It parses the YAML sections of the devices.yml and creates:
# - "<outputdir>/manifest.json": manifest file mapping image name to display name
##
#
# Dependencies:
# sudo apt -y install python3 python3-yaml
##
#
# Usage:
# ./bin/pre-release.py -i <input file> -r <release> -o <output directory>
##
#
# E.g.:
# ./bin/pre-release.py -i devices.yml -r 2022.3 -o images/
@@ -27,9 +27,9 @@ import os
import stat
import sys
import yaml # python3 -m pip install pyyaml --user
import yaml # python3 -m pip install pyyaml --user
manifest = "" # Generated automatically (<outputdir>/manifest.json)
manifest = "" # Generated automatically (<outputdir>/manifest.json)
release = ""
@@ -53,16 +53,14 @@ def bail(message="", strerror=""):
prog = sys.argv[0]
if message != "":
outstr = "\nError: {}".format(message)
outstr = f"\nError: {message}"
if strerror != "":
outstr += "\nMessage: {}\n".format(strerror)
outstr += f"\nMessage: {strerror}\n"
else:
outstr += "\n\nUsage: {} -i <input file> -o <output directory> -r <release>".format(
prog)
outstr += "\nE.g. : {} -i devices.yml -o images/ -r {}.1\n".format(
prog, datetime.datetime.now().year)
outstr += f"\n\nUsage: {prog} -i <input file> -o <output directory> -r <release>"
outstr += f"\nE.g. : {prog} -i devices.yml -o images/ -r {datetime.datetime.now().year}.1\n"
print(outstr)
@@ -74,14 +72,21 @@ def getargs(argv):
try:
opts, args = getopt.getopt(
argv, "hi:o:r:", ["inputfile=", "outputdir=", "release="])
argv,
"hi:o:r:",
[
"inputfile=",
"outputdir=",
"release="
]
)
except getopt.GetoptError as e:
bail("Incorrect arguments: {}".format(e))
bail(f"Incorrect arguments: {e}")
if opts:
for opt, arg in opts:
if opt == '-h':
if opt == "-h":
bail()
elif opt in ("-i", "--inputfile"):
@@ -94,7 +99,8 @@ def getargs(argv):
outputdir = arg.rstrip("/")
else:
bail("Unrecognised argument: " + opt)
bail("Unrecognized argument: " + opt)
else:
bail("Failed to read arguments")
@@ -107,10 +113,10 @@ def getargs(argv):
def yaml_parse(content):
result = ""
lines = content.split('\n')
lines = content.split("\n")
for line in lines:
if line.strip() and not line.strip().startswith('#'):
if line.strip() and not line.strip().startswith("#"):
result += line + "\n"
return yaml.safe_load(result)
@@ -120,10 +126,12 @@ def jsonarray(devices, vendor, name, filename, preferred, slug):
if not vendor in devices:
devices[vendor] = []
jsondata = {"name": name,
"filename": filename,
"preferred": preferred,
"slug": slug}
jsondata = {
"name": name,
"filename": filename,
"preferred": preferred,
"slug": slug
}
devices[vendor].append(jsondata)
@@ -138,7 +146,7 @@ def generate_manifest(data):
devices = {}
# Iterate over per input (depth 1)
for yaml in data['devices']:
for yaml in data["devices"]:
# Iterate over vendors
for vendor in yaml.keys():
# Ready to have a unique name in the entry
@@ -151,14 +159,14 @@ def generate_manifest(data):
# Iterate over per board
for key in board.keys():
# Check if there is an image for the board
if 'images' in key:
if "images" in key:
# Iterate over image (depth 3)
for image in board[key]:
qty_images += 1
# Check that it's not EOL or community supported
if image.get('support') == "kali":
name = image.get('name', default)
if image.get("support") == "kali":
name = image.get("name", default)
# If we haven't seen this image before for this vendor
if name not in img_seen:
@@ -166,16 +174,23 @@ def generate_manifest(data):
qty_release_images += 1
filename = "kali-linux-{}-{}".format(
release, image.get('image', default))
filename = f"kali-linux-{release}-{image.get('image', default)}"
preferred = image.get(
'preferred-image', default)
"preferred-image",
default
)
slug = image.get('slug', default)
slug = image.get("slug", default)
jsonarray(devices, vendor, name,
filename, preferred, slug)
jsonarray(
devices,
vendor,
name,
filename,
preferred,
slug
)
return json.dumps(devices, indent=2)
@@ -186,7 +201,7 @@ def createdir(dir):
os.makedirs(dir)
except:
bail('Directory "' + dir + '" does not exist and cannot be created')
bail(f"Directory {dir} does not exist and cannot be created")
return 0
@@ -195,22 +210,20 @@ def readfile(file):
try:
with open(file) as f:
data = f.read()
f.close()
except:
bail("Cannot open input file: " + file)
bail(f"Cannot open input file: {file}")
return data
def writefile(data, file):
try:
with open(file, 'w') as f:
with open(file, "w") as f:
f.write(str(data))
f.close()
except:
bail("Cannot write to output file: " + file)
bail(f"Cannot write to output file: {file}")
return 0
@@ -240,12 +253,12 @@ def main(argv):
writefile(manifest_list, manifest)
# Print result and exit
print('\nStats:')
print(' - Total devices\t: {}'.format(qty_devices))
print(' - Total images\t: {}'.format(qty_images))
print(' - {} images\t: {}'.format(release, qty_release_images))
print("\nStats:")
print(f" - Total devices\t: {qty_devices}")
print(f" - Total images\t: {qty_images}")
print(f" - {release} images\t: {qty_release_images}")
print("\n")
print('Manifest file created\t: {}'.format(manifest))
print(f"Manifest file created\t: {manifest}")
exit(0)