annotate misc/augment_plist.py @ 115:ce7e2a955814

Script to augment an existing PLIST with entries for byte-compiled files
author Franz Glasner <hg@dom66.de>
date Wed, 10 Jan 2024 18:49:36 +0100
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
115
ce7e2a955814 Script to augment an existing PLIST with entries for byte-compiled files
Franz Glasner <hg@dom66.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
ce7e2a955814 Script to augment an existing PLIST with entries for byte-compiled files
Franz Glasner <hg@dom66.de>
parents:
diff changeset
2 r"""Augment the current pkg-plist with entries for byte-compiled files.
ce7e2a955814 Script to augment an existing PLIST with entries for byte-compiled files
Franz Glasner <hg@dom66.de>
parents:
diff changeset
3
ce7e2a955814 Script to augment an existing PLIST with entries for byte-compiled files
Franz Glasner <hg@dom66.de>
parents:
diff changeset
4 The result is written to stdout.
ce7e2a955814 Script to augment an existing PLIST with entries for byte-compiled files
Franz Glasner <hg@dom66.de>
parents:
diff changeset
5
ce7e2a955814 Script to augment an existing PLIST with entries for byte-compiled files
Franz Glasner <hg@dom66.de>
parents:
diff changeset
6 Usage: augment_plist.py INPUT
ce7e2a955814 Script to augment an existing PLIST with entries for byte-compiled files
Franz Glasner <hg@dom66.de>
parents:
diff changeset
7
ce7e2a955814 Script to augment an existing PLIST with entries for byte-compiled files
Franz Glasner <hg@dom66.de>
parents:
diff changeset
8 Python
ce7e2a955814 Script to augment an existing PLIST with entries for byte-compiled files
Franz Glasner <hg@dom66.de>
parents:
diff changeset
9
ce7e2a955814 Script to augment an existing PLIST with entries for byte-compiled files
Franz Glasner <hg@dom66.de>
parents:
diff changeset
10 """
ce7e2a955814 Script to augment an existing PLIST with entries for byte-compiled files
Franz Glasner <hg@dom66.de>
parents:
diff changeset
11
ce7e2a955814 Script to augment an existing PLIST with entries for byte-compiled files
Franz Glasner <hg@dom66.de>
parents:
diff changeset
12 from __future__ import print_function, absolute_import
ce7e2a955814 Script to augment an existing PLIST with entries for byte-compiled files
Franz Glasner <hg@dom66.de>
parents:
diff changeset
13
ce7e2a955814 Script to augment an existing PLIST with entries for byte-compiled files
Franz Glasner <hg@dom66.de>
parents:
diff changeset
14 import io
ce7e2a955814 Script to augment an existing PLIST with entries for byte-compiled files
Franz Glasner <hg@dom66.de>
parents:
diff changeset
15 import os
ce7e2a955814 Script to augment an existing PLIST with entries for byte-compiled files
Franz Glasner <hg@dom66.de>
parents:
diff changeset
16 import re
ce7e2a955814 Script to augment an existing PLIST with entries for byte-compiled files
Franz Glasner <hg@dom66.de>
parents:
diff changeset
17 import sys
ce7e2a955814 Script to augment an existing PLIST with entries for byte-compiled files
Franz Glasner <hg@dom66.de>
parents:
diff changeset
18
ce7e2a955814 Script to augment an existing PLIST with entries for byte-compiled files
Franz Glasner <hg@dom66.de>
parents:
diff changeset
19
ce7e2a955814 Script to augment an existing PLIST with entries for byte-compiled files
Franz Glasner <hg@dom66.de>
parents:
diff changeset
20 def main():
ce7e2a955814 Script to augment an existing PLIST with entries for byte-compiled files
Franz Glasner <hg@dom66.de>
parents:
diff changeset
21
ce7e2a955814 Script to augment an existing PLIST with entries for byte-compiled files
Franz Glasner <hg@dom66.de>
parents:
diff changeset
22 infile = sys.argv[1]
ce7e2a955814 Script to augment an existing PLIST with entries for byte-compiled files
Franz Glasner <hg@dom66.de>
parents:
diff changeset
23 outlines = []
ce7e2a955814 Script to augment an existing PLIST with entries for byte-compiled files
Franz Glasner <hg@dom66.de>
parents:
diff changeset
24
ce7e2a955814 Script to augment an existing PLIST with entries for byte-compiled files
Franz Glasner <hg@dom66.de>
parents:
diff changeset
25 for line_orig in io.open(infile, encoding="us-ascii"):
ce7e2a955814 Script to augment an existing PLIST with entries for byte-compiled files
Franz Glasner <hg@dom66.de>
parents:
diff changeset
26 outlines.append(line_orig)
ce7e2a955814 Script to augment an existing PLIST with entries for byte-compiled files
Franz Glasner <hg@dom66.de>
parents:
diff changeset
27 line = line_orig.rstrip()
ce7e2a955814 Script to augment an existing PLIST with entries for byte-compiled files
Franz Glasner <hg@dom66.de>
parents:
diff changeset
28 if not line:
ce7e2a955814 Script to augment an existing PLIST with entries for byte-compiled files
Franz Glasner <hg@dom66.de>
parents:
diff changeset
29 continue
ce7e2a955814 Script to augment an existing PLIST with entries for byte-compiled files
Franz Glasner <hg@dom66.de>
parents:
diff changeset
30 #
ce7e2a955814 Script to augment an existing PLIST with entries for byte-compiled files
Franz Glasner <hg@dom66.de>
parents:
diff changeset
31 # NOTE: Sync with the "compileall" installation step in the Makefile
ce7e2a955814 Script to augment an existing PLIST with entries for byte-compiled files
Franz Glasner <hg@dom66.de>
parents:
diff changeset
32 #
ce7e2a955814 Script to augment an existing PLIST with entries for byte-compiled files
Franz Glasner <hg@dom66.de>
parents:
diff changeset
33 if re.search("/tests?/", line):
ce7e2a955814 Script to augment an existing PLIST with entries for byte-compiled files
Franz Glasner <hg@dom66.de>
parents:
diff changeset
34 continue
ce7e2a955814 Script to augment an existing PLIST with entries for byte-compiled files
Franz Glasner <hg@dom66.de>
parents:
diff changeset
35
ce7e2a955814 Script to augment an existing PLIST with entries for byte-compiled files
Franz Glasner <hg@dom66.de>
parents:
diff changeset
36 if line.endswith(".py"):
ce7e2a955814 Script to augment an existing PLIST with entries for byte-compiled files
Franz Glasner <hg@dom66.de>
parents:
diff changeset
37 directory, filename = os.path.split(line)
ce7e2a955814 Script to augment an existing PLIST with entries for byte-compiled files
Franz Glasner <hg@dom66.de>
parents:
diff changeset
38 base, ext = os.path.splitext(filename)
ce7e2a955814 Script to augment an existing PLIST with entries for byte-compiled files
Franz Glasner <hg@dom66.de>
parents:
diff changeset
39 for opt in ("", ".opt-1", ".opt-2"):
ce7e2a955814 Script to augment an existing PLIST with entries for byte-compiled files
Franz Glasner <hg@dom66.de>
parents:
diff changeset
40 outlines.append(
ce7e2a955814 Script to augment an existing PLIST with entries for byte-compiled files
Franz Glasner <hg@dom66.de>
parents:
diff changeset
41 "%%BYTECOMPILE%%{directory}/__pycache__/{base}%%PYPY_BCTAG%%{opt}.pyc\n"
ce7e2a955814 Script to augment an existing PLIST with entries for byte-compiled files
Franz Glasner <hg@dom66.de>
parents:
diff changeset
42 .format(directory=directory, base=base, opt=opt))
ce7e2a955814 Script to augment an existing PLIST with entries for byte-compiled files
Franz Glasner <hg@dom66.de>
parents:
diff changeset
43 for line in outlines:
ce7e2a955814 Script to augment an existing PLIST with entries for byte-compiled files
Franz Glasner <hg@dom66.de>
parents:
diff changeset
44 sys.stdout.write(line)
ce7e2a955814 Script to augment an existing PLIST with entries for byte-compiled files
Franz Glasner <hg@dom66.de>
parents:
diff changeset
45
ce7e2a955814 Script to augment an existing PLIST with entries for byte-compiled files
Franz Glasner <hg@dom66.de>
parents:
diff changeset
46
ce7e2a955814 Script to augment an existing PLIST with entries for byte-compiled files
Franz Glasner <hg@dom66.de>
parents:
diff changeset
47 if __name__ == "__main__":
ce7e2a955814 Script to augment an existing PLIST with entries for byte-compiled files
Franz Glasner <hg@dom66.de>
parents:
diff changeset
48 main()