Skip to content

Commit

Permalink
Modernize Python 2 code
Browse files Browse the repository at this point in the history
  • Loading branch information
cclauss committed Feb 2, 2025
1 parent e5818cc commit e8549ef
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 25 deletions.
3 changes: 2 additions & 1 deletion hardware/firmware/audio_board/helpers/generate_mutes.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env python3

from __future__ import print_function
channels = ['IN1', 'IN2', 'IN3', 'PC', 'USB1', 'USB2']
buses = ['OUT1', 'OUT2', 'HP1', 'HP2', 'USB1', 'USB2']

Expand Down Expand Up @@ -28,7 +29,7 @@ def main():
for i, ch in enumerate(channels):
for j, bus in enumerate(buses):
if not(mutes & mute_mask(i, j)):
print(ch, bus)
print((ch, bus))

if __name__ == "__main__":
main()
5 changes: 3 additions & 2 deletions hardware/firmware/tools/audio_crashreport.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env python3
from __future__ import print_function
import serial
import os.path
import time
Expand Down Expand Up @@ -27,11 +28,11 @@
line = ser.readline().decode()
if "Check code" in line:
addr = line.split()[3]
print('Crash at', addr)
print(('Crash at', addr))
subprocess.run(['arm-none-eabi-addr2line','-f', '-e', args.elf, addr.strip()])
elif 'mysketch' in line:
continue
else:
print("::", line.strip())
print(("::", line.strip()))
except Exception as e:
time.sleep(1)
1 change: 1 addition & 0 deletions hardware/firmware/tools/osc_control.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env python3
from __future__ import print_function
import argparse
import tabulate

Expand Down
1 change: 1 addition & 0 deletions hardware/frontplate/combine.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# - laserbed.svg exists and is a blank SVG of 350mm x 550mm
# - arguments are basenames of SVG files of 40mm x 426.5mm (one per front plate)

from __future__ import print_function
import sys
import svgutils.transform as svg

Expand Down
15 changes: 8 additions & 7 deletions software/processdump/create_json.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#! /usr/bin/python

from __future__ import print_function
from slugify import slugify
import json
import os
Expand All @@ -12,21 +13,21 @@
penta_url='https://archive.fosdem.org/2016/schedule/xml'
outdir ='/tmp/jsonfiles'

print "Checking if we have the schedule..."
print("Checking if we have the schedule...")
if os.path.isfile(os.path.basename(penta_url)):
penta = os.path.basename(penta_url)
else:
print "Getting the schedule..."
print("Getting the schedule...")
penta = wget.download(penta_url)

print "Parsing the schedule file..."
print("Parsing the schedule file...")
pentaparse = ET.parse(penta).getroot()

print "Finding the talks to process into json files..."
print("Finding the talks to process into json files...")
talks = pentaparse.findall(".//event")

for talk in talks:
print "Creating relevant file names for this talk..."
print("Creating relevant file names for this talk...")
title = talk.find('title').text
track = talk.find('track').text
slug_track = slugify(track)
Expand All @@ -35,9 +36,9 @@
track_dir = outdir + "/"+ slug_track
jsonfilename = slug_title+ '.json'

print "Creating track_dir..."
print("Creating track_dir...")
try:
os.makedirs(track_dir, 0755)
os.makedirs(track_dir, 0o755)
except:
pass

Expand Down
31 changes: 16 additions & 15 deletions software/processdump/split_video.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#! /usr/bin/python

from __future__ import print_function
from PIL import Image
from PIL import ImageFont
from PIL import ImageDraw
Expand Down Expand Up @@ -28,21 +29,21 @@
# FIXME. Do something
sys.exit(1)

print "Checking if we have the schedule..."
print("Checking if we have the schedule...")
if os.path.isfile(os.path.basename(penta_url)):
penta = os.path.basename(penta_url)
else:
print "Getting the schedule..."
print("Getting the schedule...")
penta = wget.download(penta_url)

print "Parsing the schedule file..."
print("Parsing the schedule file...")
pentaparse = ET.parse(penta).getroot()
# FIXME Either keep the downloaded penta xml file and make sure it doesn't get downloaded again, or throw it out and always get a fresh one.

print "Finding the talk to process..."
print("Finding the talk to process...")
talk = pentaparse.find(".//event[@id='"+data['event_id']+"']")

print "Creating relevant file names for this talk..."
print("Creating relevant file names for this talk...")
title = talk.find('title').text
track = talk.find('track').text
slug_track = slugify(track)
Expand All @@ -60,44 +61,44 @@
postrolltsname = postrollbasename+ '.ts'
finalcut = outdir+ videobasename+ '.mp4'

print "Creating tmpdir"
print("Creating tmpdir")
try:
os.makedirs(tmpdir, 0755)
os.makedirs(tmpdir, 0o755)
except:
pass

print "Creating outdir..."
print("Creating outdir...")
try:
os.makedirs(outdir, 0755)
os.makedirs(outdir, 0o755)
except:
pass

print "Getting list of speakers for this talk..."
print("Getting list of speakers for this talk...")
persons = [p.text for p in talk.find('persons')]
personsline = ''
for p in persons:
personsline += p + ' '

print "Grabbing the part of the video we need..."
print("Grabbing the part of the video we need...")
url = data['url'] + "?start=" + data['start'] + "&end=" + data['end']
filename = wget.download(url,out=nakedvideomp4name)

print "Creating custom preroll image from talk metadata..."
print("Creating custom preroll image from talk metadata...")
img = Image.open("preroll.jpg")
draw = ImageDraw.Draw(img)
font = ImageFont.truetype("/usr/share/fonts/truetype/dejavu/DejaVuSansMono.ttf", 64)
draw.text((0, 0),title,(0,0,0),font=font)
draw.text((0, 100),personsline,(0,0,0),font=font)
img.save(prerollimgname)

print "Processing preroll and postroll images into video..."
print("Processing preroll and postroll images into video...")
subprocess.check_call(['ffmpeg', '-y', '-loop', '1' , '-i', prerollimgname, '-c:v', 'libx264', '-r', '25', '-frames:v', '125', prerolltsname])
subprocess.check_call(['ffmpeg', '-y', '-loop', '1' , '-i', "postroll.jpg", '-c:v', 'libx264', '-r', '25', '-frames:v', '125', postrolltsname])

print "Concatenating preroll, video and postroll..."
print("Concatenating preroll, video and postroll...")
subprocess.check_call(['ffmpeg', '-y', '-i', nakedvideomp4name, '-c', 'copy', nakedvideotsname])
concatcommand = 'ffmpeg -y -f mpegts -i "concat:'+prerolltsname+ '|'+ nakedvideotsname+ '|'+ postrolltsname+'" -c copy -bsf:a aac_adtstoasc '+ finalcut
subprocess.check_call(concatcommand, shell=True)

print "Cleaning up temporary directory..."
print("Cleaning up temporary directory...")
shutil.rmtree(tmpdir)

0 comments on commit e8549ef

Please sign in to comment.