Add bugurl override, add projecturl override, add version filling for meson

This commit is contained in:
Cassowary 2023-12-09 23:27:05 -08:00
parent 1dfdcc73c0
commit 2fc6d63c90
3 changed files with 29 additions and 4 deletions

View File

@ -174,6 +174,9 @@ def heckimp(args: Sequence[str]):
if 'donateurl' in inconfig: if 'donateurl' in inconfig:
donateurl = inconfig['donateurl'] donateurl = inconfig['donateurl']
bugurl = inconfig['url']
if 'bugurl' in inconfig:
bugurl = inconfig['bugurl']
derivedconfig={ derivedconfig={
# Derived variables from config # Derived variables from config
@ -183,11 +186,14 @@ def heckimp(args: Sequence[str]):
"filename": inconfig['name'].lower(), "filename": inconfig['name'].lower(),
"ufilename": inconfig['name'].upper(), "ufilename": inconfig['name'].upper(),
"backdomain": reverse_domain(inconfig['url']), "backdomain": reverse_domain(inconfig['url']),
# URLs
"baseurl": inconfig['url'], "baseurl": inconfig['url'],
"tutorialurl": tutorialurl, "tutorialurl": tutorialurl,
"docsurl": docsurl, "docsurl": docsurl,
"contriburl": contriburl, "contriburl": contriburl,
"donateurl": donateurl, "donateurl": donateurl,
"bugurl": bugurl,
#
"copyright": inconfig['copyright'], "copyright": inconfig['copyright'],
"version": inconfig['version'], "version": inconfig['version'],
"resource_path": reverse_domain(inconfig['url']).replace('.', '/'), "resource_path": reverse_domain(inconfig['url']).replace('.', '/'),
@ -208,6 +214,13 @@ def heckimp(args: Sequence[str]):
} }
sourceroot = Path(derivedconfig["sourcetree"]) sourceroot = Path(derivedconfig["sourcetree"])
visitfiles = set()
seenfiles = set()
targetpath = Path(derivedconfig["filename"])
if targetpath.exists():
visitfiles = set(targetpath.rglob('*'))
# precompute string replacements # precompute string replacements
for r in FILENAME_REGEXP: for r in FILENAME_REGEXP:
r.replacement = r.replacement.format(**derivedconfig) r.replacement = r.replacement.format(**derivedconfig)
@ -243,6 +256,7 @@ def heckimp(args: Sequence[str]):
continue continue
# possibly rename file, # possibly rename file,
outpath = Path(apply_regexps(FILENAME_REGEXP, [], str(path))) outpath = Path(apply_regexps(FILENAME_REGEXP, [], str(path)))
seenfiles.add(outpath)
logger.info(f"processing {outpath}") logger.info(f"processing {outpath}")
# write each file to the outtreea # write each file to the outtreea
if path.is_dir(): if path.is_dir():
@ -315,6 +329,11 @@ def heckimp(args: Sequence[str]):
os.system('git add .') os.system('git add .')
os.system(f"""git commit -m "Initial checkin of {derivedconfig['symname']} from {derivedconfig["us"]}" """) os.system(f"""git commit -m "Initial checkin of {derivedconfig['symname']} from {derivedconfig["us"]}" """)
os.system(f"""git tag v{derivedconfig['version']}""") os.system(f"""git tag v{derivedconfig['version']}""")
leftovers = visitfiles - seenfiles
if leftovers:
# print them out but we need to think about filtercing them too (exclude .git and upstream-documentation)
...
print("Done.") print("Done.")
return 0 return 0

View File

@ -22,7 +22,7 @@ CONTENTS_REGEXP: List[Replacement] = [
r" * A derived work which may be trivial. However, any changes may be (C){year} by {copyright}\n *\n" r" * A derived work which may be trivial. However, any changes may be (C){year} by {copyright}\n *\n"
r" * Original copyright, applying to most contents (license remains unchanged): ") r" * Original copyright, applying to most contents (license remains unchanged): ")
), ),
R(re.compile(r"^(\W+)version: \'[0-9].*"), r"\1version: '{version}', #heckimp skip", 'meson.build'),
R( R(
re.compile(r'(.*)Spencer Kimball, Peter Mattis and the GIMP Development Team(.*)'), re.compile(r'(.*)Spencer Kimball, Peter Mattis and the GIMP Development Team(.*)'),
r"\1Based on work by Spencer Kimball, Peter Mattis and the GnuImp Development Team\2" r"\1Based on work by Spencer Kimball, Peter Mattis and the GnuImp Development Team\2"
@ -65,12 +65,14 @@ CONTENTS_REGEXP: List[Replacement] = [
R(re.compile(r"(.*)https?://docs.gimp.org/(.*)"), r'\1{docsurl}\2'), R(re.compile(r"(.*)https?://docs.gimp.org/(.*)"), r'\1{docsurl}\2'),
R(re.compile(r"(.*)https?://www.gimp.org/develop(.*)"), r'\1{contriburl}\2'), R(re.compile(r"(.*)https?://www.gimp.org/develop(.*)"), r'\1{contriburl}\2'),
R(re.compile(r"(.*)https?://www.gimp.org/donating(.*)"), r'\1{donateurl}\2'), R(re.compile(r"(.*)https?://www.gimp.org/donating(.*)"), r'\1{donateurl}\2'),
R(re.compile(r"(.*)https?://gitlab.gnome.org/GNOME/gimp/issues(.*)"), r'\1{bugurl}\2'),
# override
R(re.compile(r"project_url = 'https://gitlab.gnome.org/GNOME/gimp'"), r"project_url = '{baseurl}'"),
R(re.compile(r"project_url_issues = project_url + '/issues/new'"), r"project_url_issues = '{bugurl}'"),
# catchall urls # catchall urls
R(re.compile(r"(.*)https?://www.gimp.org(.*)"), r'\1{baseurl}\2'), R(re.compile(r"(.*)https?://www.gimp.org(.*)"), r'\1{baseurl}\2'),
R(re.compile(r"(.*[ \t\"])(www.)?gimp.org(.*)"), r'\1{baseurl}\3'), R(re.compile(r"(.*[ \t\"])(www.)?gimp.org(.*)"), r'\1{baseurl}\3'),
## general replacements ## general replacements
R(re.compile(r"(.*)gimp(.*)"), r'\1{filename}\2'), R(re.compile(r"(.*)gimp(.*)"), r'\1{filename}\2'),
R(re.compile(r"(.*)GIMP(.*)"), r'\1{ufilename}\2'), R(re.compile(r"(.*)GIMP(.*)"), r'\1{ufilename}\2'),
@ -138,6 +140,8 @@ CONTENTS_EXCEPTIONS: List[re.Pattern] = [
#re.compile(r".wiki.gimp.org.*"), #re.compile(r".wiki.gimp.org.*"),
re.compile(r".*irc.*gimp.org:6667.*"), re.compile(r".*irc.*gimp.org:6667.*"),
re.compile(r".*meetthegimp.org.*"), # wtf this domain re.compile(r".*meetthegimp.org.*"), # wtf this domain
# these are pretty consistent notes in the code referring to upstream bugs.
re.compile(r".*See[:]? https://gitlab.gnome.org/GNOME/gimp/.*")
] ]
# #

View File

@ -18,10 +18,12 @@ logger = logging.getLogger(__name__)
# regex.match, we could make a function that configures the replacement based on a dictionary, we could # regex.match, we could make a function that configures the replacement based on a dictionary, we could
# make a function that executes the replacement on a string, etc. It would probably make the below code # make a function that executes the replacement on a string, etc. It would probably make the below code
# a bit less type dependent). # a bit less type dependent).
# FIXME implement path limiting
class Replacement: class Replacement:
def __init__(self, regexp, replacement): def __init__(self, regexp, replacement, path=None):
self.regexp = regexp self.regexp = regexp
self.replacement = replacement self.replacement = replacement
self.path = path
def one_matches(relist: Sequence[Union[re.Pattern, Replacement, Sequence]], s: str) -> Union[None, re.Pattern, Replacement, Sequence]: def one_matches(relist: Sequence[Union[re.Pattern, Replacement, Sequence]], s: str) -> Union[None, re.Pattern, Replacement, Sequence]: