From 3d22ddc7e67a06d0bdf2994b1ef018bc46e92f34 Mon Sep 17 00:00:00 2001 From: Alexis Hildebrandt Date: Mon, 4 Dec 2023 12:23:56 +0100 Subject: Migrate Python scripts to Python 3 --- tools/average | 6 +++--- tools/genuuid | 29 ++++++++++++++++------------- 2 files changed, 19 insertions(+), 16 deletions(-) (limited to 'tools') diff --git a/tools/average b/tools/average index 0e95c1c5..4c1e4b43 100755 --- a/tools/average +++ b/tools/average @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/env python3 import getopt import time @@ -18,9 +18,9 @@ length = 0.0 i = 0 while i < count: begin = time.time() - cmd = '"' + string.join(args, '" "') + '"'; + cmd = '"' + '" "'.join(args) + '"'; os.system(cmd) length += time.time() - begin i += 1 -print >> sys.stderr, length / count +print(length / count, file=sys.stderr) diff --git a/tools/genuuid b/tools/genuuid index 53fb7a0a..0ad5bd92 100755 --- a/tools/genuuid +++ b/tools/genuuid @@ -1,24 +1,27 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 import re import sys def scan_path(path): bug = uuid = None - with open(path, 'r') as fd: - for line in fd: - match = re.match('\*', line) - if match: - bug = uuid = None + try: + with open(path, 'r') as fd: + for line in fd: + match = re.match('\*', line) + if match: + bug = uuid = None - match = re.search('\[\[bug:([0-9]+)\]\[#[0-9]+\]\]', line) - if match: - bug = match.group(1) - elif bug: - match = re.search(':ID:\s+(.+?)\s*$', line) + match = re.search('\[\[bug:([0-9]+)\]\[#[0-9]+\]\]', line) if match: - uuid = match.group(1) - print "UPDATE bugs SET cf_uuid='%s' WHERE bug_id=%s;" % (uuid, bug) + bug = match.group(1) + elif bug: + match = re.search(':ID:\s+(.+?)\s*$', line) + if match: + uuid = match.group(1) + print(f"UPDATE bugs SET cf_uuid='{uuid}' WHERE bug_id={bug};") + except FileNotFoundError: + print(f'{path}: No such file or directory') scan_path('/Users/johnw/src/ledger/plan/TODO') scan_path('/Users/johnw/src/ledger/plan/TODO-3.0') -- cgit v1.2.3