summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorAlexis Hildebrandt <afh@surryhill.net>2023-12-04 12:23:56 +0100
committerAlexis Hildebrandt <afh@surryhill.net>2023-12-04 12:23:56 +0100
commit3d22ddc7e67a06d0bdf2994b1ef018bc46e92f34 (patch)
tree287e867ef25bf2ecbaa9364f257aefdfb23ef97f /tools
parent8bbd3fed06087243861a6d6ec9c58dd8858ab34c (diff)
downloadfork-ledger-3d22ddc7e67a06d0bdf2994b1ef018bc46e92f34.tar.gz
fork-ledger-3d22ddc7e67a06d0bdf2994b1ef018bc46e92f34.tar.bz2
fork-ledger-3d22ddc7e67a06d0bdf2994b1ef018bc46e92f34.zip
Migrate Python scripts to Python 3
Diffstat (limited to 'tools')
-rwxr-xr-xtools/average6
-rwxr-xr-xtools/genuuid29
2 files changed, 19 insertions, 16 deletions
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')