Skip to content

Commit

Permalink
Convert compiled build tools to Python
Browse files Browse the repository at this point in the history
  • Loading branch information
pmattes committed Jan 14, 2025
1 parent aee3871 commit 16b1eb3
Show file tree
Hide file tree
Showing 125 changed files with 2,732 additions and 8,129 deletions.
2 changes: 1 addition & 1 deletion Common/Test/target/tn3270_snake.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def rcv_data_cooked(self, data: bytes, mode=tn3270e_proto.data_type.d3270_data):
case aid.SF.value:
# Parse the QueryReply, assuming that's what it is
self.debug('snake', 'got SF')
if (self.dinfo.parse_query_reply(data)):
if (self.dinfo.parse_query_reply(data)[0]):
self.rows = self.dinfo.alt_rows
self.columns = self.dinfo.alt_columns
self.debug('snake', f'rows {self.rows} columns {self.columns}')
Expand Down
2 changes: 1 addition & 1 deletion Common/Win32/manifest.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
type="win32"
name="%NAME%"
version="%VERSION%"
processorArchitecture="%ARCHITECTURE%"
processorArchitecture="*"
/>
<description>%DESCRIPTION%</description>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
Expand Down
134 changes: 134 additions & 0 deletions Common/Win32/mkmanifest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
#!/usr/bin/env python3
#
# Copyright (c) 2025 Paul Mattes.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# * Neither the names of Paul Mattes nor the names of his contributors
# may be used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY PAUL MATTES "AS IS" AND ANY EXPRESS OR IMPLIED
# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
# EVENT SHALL PAUL MATTES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
# Create version.c from version.txt
# mkmanifest.py version.txt manifest.tmpl exe-name 'description' [architecture]
#
# Formerly a shell script:
#
# set -e
#
# if [ $# -lt 4 -o $# -gt 5 ]
# then echo >&2 "Usage: mkmanifest.sh version.txt manifest.tmpl exe-name 'description' [architecture]"
# exit 2
# fi
#
# . $1
#
# # Name and description are easy.
# name="$3"
# description="$4"
#
# # Version is trickier.
# # <major>.<minor>text<update> becomes <major>.<minor>.<update>.0
# version_subst=`echo $version | sed 's/^\([0-9][0-9]*\)\.\([0-9][0-9]*\)[a-z][a-z]*\([0-9][0-9]*\)$/\1.\2.\3.0/'`
#
# if [ -n "$5" ]
# then arch=$5
# else arch=x86
# fi
#
# sed -e "s/%NAME%/$name/g" \
# -e "s/%VERSION%/$version_subst/g" \
# -e "s/%ARCHITECTURE%/$arch/g" \
# -e "s/%DESCRIPTION%/$description/g" \
# $2

from datetime import datetime, timezone
import os
import re
import sys

def mkmanifest(outfile_name: str, version_txt: str, template: str, exe_name: str, description: str):

# Read in version.txt.
ver = {}
lno = 0
with open(version_txt) as infile:
while True:
line = infile.readline()
if line == '':
break
lno += 1
line = line.strip()
m = re.fullmatch('^([a-z]+)="(.*)"$', line)
if m == None:
print(f'Syntax error in version.txt at line {lno}', file = sys.stderr)
continue
ver[m.group(1)] = m.group(2)

if not 'version' in ver:
print('Missing fields(s) in version.txt', file = sys.stderr)
exit(1)
version = ver['version']

# Transform the version.
m = re.fullmatch('^([0-9][0-9]*)\\.([0-9][0-9]*)[a-z][a-z]*([0-9][0-9]*)$', version)
if m == None:
print(f'Version "{version}" does not have the right format', file = sys.stderr)
exit(1)
xversion = '.'.join([m.group(i) for i in range(1, 4)]) + '.0'

# Read in the template.
with open(template) as tf:
tc = tf.readlines()

# Open the outfile.
if outfile_name != None:
outfile = open(outfile_name, 'w', newline='\r\n')
else:
outfile = sys.stdout

# Substitute.
for line in tc:
print(line.rstrip().replace('%NAME%', exe_name).replace('%VERSION%', xversion).replace('%DESCRIPTION%', description), file=outfile)

if outfile_name != None:
outfile.close()

def usage():
'''Print a usage message and exit'''
print('Usage: mkmanifest [-o outfile] version.txt manifest.tmpl exe-name description', file=sys.stderr)
exit(1)

# Parse the command line.
args = sys.argv.copy()[1:]
outfile_name = None
while len(args) > 0 and args[0].startswith('-'):
if args[0] == '-o':
if len(args) < 2:
usage()
outfile_name = args[1]
args = args[1:]
else:
usage()
args = args[1:]
if len(args) != 4:
usage()

# Run.
mkmanifest(outfile_name, args[0], args[1], args[2], args[3])
64 changes: 0 additions & 64 deletions Common/Win32/mkmanifest.sh

This file was deleted.

Loading

0 comments on commit 16b1eb3

Please sign in to comment.