mirror of
https://github.com/MarlinFirmware/Marlin.git
synced 2024-11-25 21:07:32 +00:00
🧑💻 Python scripts cleanup, improve (#27533)
This commit is contained in:
parent
8d864d797a
commit
a7bd35b993
@ -37,7 +37,7 @@ if pioutil.is_pio_build():
|
|||||||
#
|
#
|
||||||
# platformio.ini will accept this for a Windows upload port designation: 'upload_port = L:'
|
# platformio.ini will accept this for a Windows upload port designation: 'upload_port = L:'
|
||||||
# Windows - doesn't care about the disk's name, only cares about the drive letter
|
# Windows - doesn't care about the disk's name, only cares about the drive letter
|
||||||
import subprocess,string
|
import subprocess, string
|
||||||
from ctypes import windll
|
from ctypes import windll
|
||||||
from pathlib import PureWindowsPath
|
from pathlib import PureWindowsPath
|
||||||
|
|
||||||
|
@ -16,10 +16,7 @@
|
|||||||
# location: <https://www.gnu.org/licenses/>.
|
# location: <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
import argparse
|
import argparse, textwrap, os, zlib
|
||||||
import textwrap
|
|
||||||
import os
|
|
||||||
import zlib
|
|
||||||
|
|
||||||
def deflate(data):
|
def deflate(data):
|
||||||
return zlib.compress(data)
|
return zlib.compress(data)
|
||||||
|
@ -17,8 +17,7 @@
|
|||||||
|
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
import argparse
|
import argparse, textwrap
|
||||||
import textwrap
|
|
||||||
|
|
||||||
def pack_rle(data):
|
def pack_rle(data):
|
||||||
"""Use run-length encoding to pack the bytes"""
|
"""Use run-length encoding to pack the bytes"""
|
||||||
|
@ -17,11 +17,7 @@
|
|||||||
|
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
import argparse
|
import argparse, textwrap, os, sys, zlib
|
||||||
import textwrap
|
|
||||||
import os
|
|
||||||
import sys
|
|
||||||
import zlib
|
|
||||||
|
|
||||||
class WriteSource:
|
class WriteSource:
|
||||||
def __init__(self, mode):
|
def __init__(self, mode):
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
# location: <https://www.gnu.org/licenses/>.
|
# location: <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
import argparse,re,sys
|
import argparse, re, sys
|
||||||
|
|
||||||
from html.parser import HTMLParser
|
from html.parser import HTMLParser
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
|
||||||
import sys, os,config
|
import sys, os, config
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
args = sys.argv[1:]
|
args = sys.argv[1:]
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
|
||||||
import sys, os,config
|
import sys, os, config
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
args = sys.argv[1:]
|
args = sys.argv[1:]
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
# will be picked up by PlatformIO just like any other variant.
|
# will be picked up by PlatformIO just like any other variant.
|
||||||
#
|
#
|
||||||
import pioutil, re
|
import pioutil, re
|
||||||
|
|
||||||
marlin_variant_pattern = re.compile("marlin_.*")
|
marlin_variant_pattern = re.compile("marlin_.*")
|
||||||
if pioutil.is_pio_build():
|
if pioutil.is_pio_build():
|
||||||
import shutil, marlin
|
import shutil, marlin
|
||||||
@ -55,4 +56,4 @@ if pioutil.is_pio_build():
|
|||||||
variants_dir = here / 'buildroot' / 'share' / 'PlatformIO' / 'variants'
|
variants_dir = here / 'buildroot' / 'share' / 'PlatformIO' / 'variants'
|
||||||
source_dir = variants_dir / variant
|
source_dir = variants_dir / variant
|
||||||
assert source_dir.is_dir()
|
assert source_dir.is_dir()
|
||||||
board.update("build.variants_dir", str(variants_dir));
|
board.update("build.variants_dir", str(variants_dir))
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
# been extended to evaluate conditions and can determine what options are actually enabled, not just which
|
# been extended to evaluate conditions and can determine what options are actually enabled, not just which
|
||||||
# options are uncommented. That will be migrated to this script for standalone migration.
|
# options are uncommented. That will be migrated to this script for standalone migration.
|
||||||
#
|
#
|
||||||
import re,json
|
import re, json
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
def extend_dict(d:dict, k:tuple):
|
def extend_dict(d:dict, k:tuple):
|
||||||
@ -120,8 +120,6 @@ def extract_files(filekey):
|
|||||||
defgrep = re.compile(r'^(//)?\s*(#define)\s+([A-Za-z0-9_]+)\s*(.*?)\s*(//.+)?$')
|
defgrep = re.compile(r'^(//)?\s*(#define)\s+([A-Za-z0-9_]+)\s*(.*?)\s*(//.+)?$')
|
||||||
# Pattern to match a float value
|
# Pattern to match a float value
|
||||||
flt = r'[-+]?\s*(\d+\.|\d*\.\d+)([eE][-+]?\d+)?[fF]?'
|
flt = r'[-+]?\s*(\d+\.|\d*\.\d+)([eE][-+]?\d+)?[fF]?'
|
||||||
# Defines to ignore
|
|
||||||
ignore = ('CONFIGURATION_H_VERSION', 'CONFIGURATION_ADV_H_VERSION', 'CONFIG_EXAMPLES_DIR', 'CONFIG_EXPORT')
|
|
||||||
# Start with unknown state
|
# Start with unknown state
|
||||||
state = Parse.NORMAL
|
state = Parse.NORMAL
|
||||||
# Serial ID
|
# Serial ID
|
||||||
@ -138,7 +136,7 @@ def extract_files(filekey):
|
|||||||
eol_options = False # The options came from end of line, so only apply once
|
eol_options = False # The options came from end of line, so only apply once
|
||||||
join_line = False # A flag that the line should be joined with the previous one
|
join_line = False # A flag that the line should be joined with the previous one
|
||||||
line = '' # A line buffer to handle \ continuation
|
line = '' # A line buffer to handle \ continuation
|
||||||
last_added_ref = None # Reference to the last added item
|
last_added_ref = {} # Reference to the last added item
|
||||||
# Loop through the lines in the file
|
# Loop through the lines in the file
|
||||||
for the_line in fileobj.readlines():
|
for the_line in fileobj.readlines():
|
||||||
line_number += 1
|
line_number += 1
|
||||||
@ -175,7 +173,8 @@ def extract_files(filekey):
|
|||||||
comment_buff = []
|
comment_buff = []
|
||||||
if cline != '':
|
if cline != '':
|
||||||
# A (block or slash) comment was already added
|
# A (block or slash) comment was already added
|
||||||
cfield = 'notes' if 'comment' in last_added_ref else 'comment'
|
if 'comment' in last_added_ref:
|
||||||
|
cfield = 'notes'
|
||||||
last_added_ref[cfield] = cline
|
last_added_ref[cfield] = cline
|
||||||
|
|
||||||
#
|
#
|
||||||
@ -220,7 +219,6 @@ def extract_files(filekey):
|
|||||||
# Temperature sensors are done
|
# Temperature sensors are done
|
||||||
if state == Parse.GET_SENSORS:
|
if state == Parse.GET_SENSORS:
|
||||||
options_json = f'[ {options_json[:-2]} ]'
|
options_json = f'[ {options_json[:-2]} ]'
|
||||||
|
|
||||||
state = Parse.NORMAL
|
state = Parse.NORMAL
|
||||||
|
|
||||||
# Strip the leading '* ' from block comments
|
# Strip the leading '* ' from block comments
|
||||||
@ -230,7 +228,7 @@ def extract_files(filekey):
|
|||||||
if state == Parse.GET_SENSORS:
|
if state == Parse.GET_SENSORS:
|
||||||
sens = re.match(r'^(-?\d+)\s*:\s*(.+)$', cline)
|
sens = re.match(r'^(-?\d+)\s*:\s*(.+)$', cline)
|
||||||
if sens:
|
if sens:
|
||||||
s2 = sens[2].replace("'","''")
|
s2 = sens[2].replace("'", "''")
|
||||||
options_json += f"{sens[1]}:'{sens[1]} - {s2}', "
|
options_json += f"{sens[1]}:'{sens[1]} - {s2}', "
|
||||||
|
|
||||||
elif state == Parse.BLOCK_COMMENT:
|
elif state == Parse.BLOCK_COMMENT:
|
||||||
@ -255,12 +253,11 @@ def extract_files(filekey):
|
|||||||
comment_buff = []
|
comment_buff = []
|
||||||
state = Parse.BLOCK_COMMENT
|
state = Parse.BLOCK_COMMENT
|
||||||
eol_options = False
|
eol_options = False
|
||||||
|
|
||||||
elif cpos2 != -1 and (cpos2 < cpos1 or cpos1 == -1):
|
elif cpos2 != -1 and (cpos2 < cpos1 or cpos1 == -1):
|
||||||
cpos = cpos2
|
cpos = cpos2
|
||||||
|
|
||||||
# Comment after a define may be continued on the following lines
|
# Comment after a define may be continued on the following lines
|
||||||
if defmatch != None and cpos > 10:
|
if defmatch is not None and cpos > 10:
|
||||||
state = Parse.EOL_COMMENT
|
state = Parse.EOL_COMMENT
|
||||||
prev_comment = '\n'.join(comment_buff)
|
prev_comment = '\n'.join(comment_buff)
|
||||||
comment_buff = []
|
comment_buff = []
|
||||||
@ -327,10 +324,10 @@ def extract_files(filekey):
|
|||||||
conditions.append([ f'!defined({line[7:].strip()})' ])
|
conditions.append([ f'!defined({line[7:].strip()})' ])
|
||||||
|
|
||||||
# Handle a complete #define line
|
# Handle a complete #define line
|
||||||
elif defmatch != None:
|
elif defmatch is not None:
|
||||||
|
|
||||||
# Get the match groups into vars
|
# Get the match groups into vars
|
||||||
enabled, define_name, val = defmatch[1] == None, defmatch[3], defmatch[4]
|
enabled, define_name, val = defmatch[1] is None, defmatch[3], defmatch[4]
|
||||||
|
|
||||||
# Increment the serial ID
|
# Increment the serial ID
|
||||||
sid += 1
|
sid += 1
|
||||||
@ -375,7 +372,7 @@ def extract_files(filekey):
|
|||||||
|
|
||||||
# If the comment_buff is not empty, add the comment to the info
|
# If the comment_buff is not empty, add the comment to the info
|
||||||
if comment_buff:
|
if comment_buff:
|
||||||
full_comment = '\n'.join(comment_buff)
|
full_comment = '\n'.join(comment_buff).strip()
|
||||||
|
|
||||||
# An EOL comment will be added later
|
# An EOL comment will be added later
|
||||||
# The handling could go here instead of above
|
# The handling could go here instead of above
|
||||||
@ -392,6 +389,14 @@ def extract_files(filekey):
|
|||||||
if units == 's' or units == 'sec': units = 'seconds'
|
if units == 's' or units == 'sec': units = 'seconds'
|
||||||
define_info['units'] = units
|
define_info['units'] = units
|
||||||
|
|
||||||
|
if 'comment' not in define_info or define_info['comment'] == '':
|
||||||
|
if prev_comment:
|
||||||
|
define_info['comment'] = prev_comment
|
||||||
|
prev_comment = ''
|
||||||
|
|
||||||
|
if 'comment' in define_info and define_info['comment'] == '':
|
||||||
|
del define_info['comment']
|
||||||
|
|
||||||
# Set the options for the current #define
|
# Set the options for the current #define
|
||||||
if define_name == "MOTHERBOARD" and boards != '':
|
if define_name == "MOTHERBOARD" and boards != '':
|
||||||
define_info['options'] = boards
|
define_info['options'] = boards
|
||||||
|
@ -2,9 +2,7 @@
|
|||||||
#
|
#
|
||||||
# signature.py
|
# signature.py
|
||||||
#
|
#
|
||||||
import schema
|
import schema, subprocess, re, json, hashlib
|
||||||
|
|
||||||
import subprocess,re,json,hashlib
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from functools import reduce
|
from functools import reduce
|
||||||
|
@ -54,8 +54,7 @@
|
|||||||
# does not define a name for 39. This is specially handled to
|
# does not define a name for 39. This is specially handled to
|
||||||
# prevent reordering stock icons.
|
# prevent reordering stock icons.
|
||||||
|
|
||||||
import os
|
import os, struct
|
||||||
import struct
|
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
|
|
||||||
def getJpegResolution(jpegFile):
|
def getJpegResolution(jpegFile):
|
||||||
|
@ -18,9 +18,7 @@
|
|||||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
#----------------------------------------------------------------
|
#----------------------------------------------------------------
|
||||||
|
|
||||||
import os.path
|
import os.path, argparse, DWIN_ICO
|
||||||
import argparse
|
|
||||||
import DWIN_ICO
|
|
||||||
|
|
||||||
version = '2.0.7'
|
version = '2.0.7'
|
||||||
|
|
||||||
|
@ -18,9 +18,7 @@
|
|||||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
#----------------------------------------------------------------
|
#----------------------------------------------------------------
|
||||||
|
|
||||||
import os.path
|
import os.path, argparse, DWIN_ICO
|
||||||
import argparse
|
|
||||||
import DWIN_ICO
|
|
||||||
|
|
||||||
version = '2.0.7'
|
version = '2.0.7'
|
||||||
|
|
||||||
|
@ -4,8 +4,7 @@
|
|||||||
# Author: Taylor Talkington
|
# Author: Taylor Talkington
|
||||||
# License: GPL
|
# License: GPL
|
||||||
|
|
||||||
import bdflib.reader
|
import bdflib.reader, math
|
||||||
import math
|
|
||||||
|
|
||||||
def glyph_bits(size_x, size_y, font, glyph_ord):
|
def glyph_bits(size_x, size_y, font, glyph_ord):
|
||||||
asc = font[b'FONT_ASCENT']
|
asc = font[b'FONT_ASCENT']
|
||||||
|
@ -2,14 +2,9 @@
|
|||||||
# MarlinBinaryProtocol.py
|
# MarlinBinaryProtocol.py
|
||||||
# Supporting Firmware upload via USB/Serial, saving to the attached media.
|
# Supporting Firmware upload via USB/Serial, saving to the attached media.
|
||||||
#
|
#
|
||||||
import serial
|
import serial, math, time, threading, sys, datetime, random
|
||||||
import math
|
|
||||||
import time
|
|
||||||
from collections import deque
|
from collections import deque
|
||||||
import threading
|
|
||||||
import sys
|
|
||||||
import datetime
|
|
||||||
import random
|
|
||||||
try:
|
try:
|
||||||
import heatshrink2 as heatshrink
|
import heatshrink2 as heatshrink
|
||||||
heatshrink_exists = True
|
heatshrink_exists = True
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
|
||||||
from __future__ import print_function
|
from __future__ import print_function, division
|
||||||
from __future__ import division
|
|
||||||
|
|
||||||
""" Generate the stepper delay lookup table for Marlin firmware. """
|
""" Generate the stepper delay lookup table for Marlin firmware. """
|
||||||
|
|
||||||
|
@ -18,8 +18,7 @@ Options:
|
|||||||
--num-temps=... the number of temperature points to calculate (default: 36)
|
--num-temps=... the number of temperature points to calculate (default: 36)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from __future__ import print_function
|
from __future__ import print_function, division
|
||||||
from __future__ import division
|
|
||||||
|
|
||||||
from math import *
|
from math import *
|
||||||
import sys, getopt
|
import sys, getopt
|
||||||
|
@ -5,8 +5,7 @@
|
|||||||
#
|
#
|
||||||
# Usage: rle16_compress_cpp_image_data.py INPUT_FILE.cpp OUTPUT_FILE.cpp
|
# Usage: rle16_compress_cpp_image_data.py INPUT_FILE.cpp OUTPUT_FILE.cpp
|
||||||
#
|
#
|
||||||
import sys, struct
|
import sys, struct, re
|
||||||
import re
|
|
||||||
|
|
||||||
def addCompressedData(input_file, output_file):
|
def addCompressedData(input_file, output_file):
|
||||||
ofile = open(output_file, 'wt')
|
ofile = open(output_file, 'wt')
|
||||||
|
@ -6,8 +6,7 @@
|
|||||||
#
|
#
|
||||||
# Usage: rle_compress_bitmap.py INPUT_FILE OUTPUT_FILE
|
# Usage: rle_compress_bitmap.py INPUT_FILE OUTPUT_FILE
|
||||||
#
|
#
|
||||||
import sys, struct
|
import sys, struct, re
|
||||||
import re
|
|
||||||
|
|
||||||
def addCompressedData(input_file, output_file):
|
def addCompressedData(input_file, output_file):
|
||||||
input_lines = input_file.readlines()
|
input_lines = input_file.readlines()
|
||||||
|
Loading…
Reference in New Issue
Block a user