209 lines
9.6 KiB
Python
209 lines
9.6 KiB
Python
import re
|
|
|
|
from typing import List, Union
|
|
|
|
from .regexptools import Replacement
|
|
R = Replacement
|
|
|
|
"""
|
|
This module contains all of the specially crafted regexps for the GnuImp source code.
|
|
"""
|
|
|
|
#
|
|
# These regexps are applied to all files, and are the heart of our replacements.
|
|
#
|
|
CONTENTS_REGEXP: List[Replacement] = [
|
|
## Hyperspecific stuff that needs to override later stuff.
|
|
# Copyright notice update with maximal adherence.
|
|
R(
|
|
re.compile(r"/\* GIMP - The GNU Image Manipulation Program(.*)"),
|
|
(r"/* {longname} - {expandedname}\n"
|
|
r" * a rebranding of The GNU Image Manipulation Program (created with {us})\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(re.compile(r"^(\W+)version: \'[0-9].*"), r"\1version: '{version}', #heckimp skip", 'meson.build'),
|
|
R(
|
|
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"
|
|
),
|
|
|
|
# Stuff that just doesn't munge right
|
|
R(
|
|
re.compile(r"#define GIMP\(obj\) \(G_TYPE_CHECK_INSTANCE_CAST \(\(obj\), GIMP_TYPE_GIMP, Gimp\)\)"),
|
|
r"#define {ufilename}(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), {ufilename}_TYPE_{ufilename}, {symname}))"
|
|
),
|
|
R(re.compile(r"typedef struct _Gimp Gimp;"),
|
|
r"typedef struct _{symname} {symname};"),
|
|
|
|
R(
|
|
re.compile(r'(.*)G_DEFINE_TYPE \(Gimp, gimp, GIMP_TYPE_OBJECT\)(.*)'),
|
|
r'\1G_DEFINE_TYPE ({symname}, {filename}, {ufilename}_TYPE_OBJECT)\2'
|
|
),
|
|
R(re.compile(r"(.*[\t ])_Gimp(.*)"), r"\1_{symname}\2"),
|
|
R(re.compile(r"(.*)mapGimp(.*)"), r'\1map{symname}\2'),
|
|
|
|
## general backdomain for eg. app names and such
|
|
R(re.compile(r"(.*)org.gimp(.*)"), r'\1{backdomain}\2'),
|
|
|
|
|
|
## canvas shadow crappe (we should constrain this but it's really specific)
|
|
# this one just whipes out all of the embdedded SVGs
|
|
R(re.compile(r"""^[ \t]*"M [0-9.]+.* z( )*";"""), ""),
|
|
# this one puts an empty path for eyes_path
|
|
R(re.compile(r"static const gchar eyes_path\[\] =.*"), r'static const gchar eyes_path[] = "M z"; // #heckimp skip'),
|
|
R(re.compile(r"static const gchar wilber_path\[\] =.*"), r'static const gchar mascot_path[] = "{shadow}";'),
|
|
|
|
|
|
## Resource paths
|
|
R(re.compile(r"(.*)/org/gimp/(.*)"), r'\1{resource_path}\2'),
|
|
|
|
## URLs and things
|
|
# we also need to make sure we're directing people to the original docs, but also making sure they don't bother
|
|
# their bug tracker, and also allow the user to replace the various kinds of urls (docs, subpaths like bugs, etc)
|
|
R(re.compile(r"(.*)https?://www.gimp.org/tutorials(.*)"), r'\1{tutorialurl}\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/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
|
|
R(re.compile(r"(.*)https?://www.gimp.org(.*)"), r'\1{baseurl}\2'),
|
|
R(re.compile(r"(.*[ \t\"])(www.)?gimp.org(.*)"), r'\1{baseurl}\3'),
|
|
|
|
## general replacements
|
|
R(re.compile(r"(.*)gimp(.*)"), r'\1{filename}\2'),
|
|
R(re.compile(r"(.*)GIMP(.*)"), r'\1{ufilename}\2'),
|
|
R(re.compile(r"(.*)The GNU Image Manipulation Program(.*)"), r"\1{expandedname}\2"),
|
|
R(re.compile(r"(.*)GNU Image Manipulation Program(.*)"), r"\1{expandedname}\2"),
|
|
|
|
## symbol names
|
|
# various symbols and other things (fixme why don't these match ...something=somethingGimp...)
|
|
R(re.compile(r"(.*[ \t([{][/_%#*&$@:=+-]?)Gimp([:A-Za-z0-9._ ].*)"), r'\1{symname}\2'),
|
|
R(re.compile(r"^Gimp([A-Za-z0-9._ -].*)"), r'{symname}\1'),
|
|
R(re.compile(r"(.*[ \t([{][/_%#*&$@:=+-]?[A-Za-z][A-Za-z0-9]+)Gimp([:A-Za-z0-9._ [-].*)"), r'\1{symname}\2'),
|
|
R(re.compile(r"(.*=[ ]*[A-Za-z]*)Gimp(.*)"), r'\1{symname}\2'),
|
|
# some meson stuff
|
|
R(re.compile(r"(.*)LibGimp(.*)"), r'\1Lib{symname}\2'),
|
|
# documentation?
|
|
R(re.compile(r"(.*[#_/.])Gimp(.*)"), r'\1{symname}\2'),
|
|
R(re.compile(r"(.*)Gimp-tips(.*)"), r'\1{symname}-tips\2'),
|
|
# Strings and strinng like symbols
|
|
R(re.compile(r"""(.*['"`][A-Za-z0-9]*)Gimp([A-Za-z0-9.-]*.*)"""), r'\1{symname}\2'),
|
|
R(re.compile(r"""(.*)Gimp([A-Za-z0-9.-]*['"`].*)"""), r'\1{symname}\2'),
|
|
|
|
# special symbol converts (kind of hyperspecific, but we can worry about it later)
|
|
R(re.compile(r"(.*)import Gimp(.*)"), r'\1import {symname}\2'),
|
|
R(re.compile(r"(.*)gi.repository.Gimp(.*)"), r'\1gi.repository.{symname}\2'),
|
|
R(re.compile(r"(.*)Gimp-Python(.*)"), r'\1{symname}-Python\2'),
|
|
R(re.compile(r"(.*)Gimp-Print(.*)"), r'\1{symname}-Print\2'),
|
|
R(re.compile(r"(.*)Gimp@Type(.*)"), r'\1{symname}@Type\2'),
|
|
|
|
|
|
# Stuff in the pdb perl scripts (the above symbol convert should work but w/e)
|
|
R(re.compile(r"(.*s/)Gimp(/.*)"), r'\1{symname}\2'),
|
|
R(re.compile(r"(.*[$%&])Gimp(::.*)"), r'\1{symname}\2'),
|
|
|
|
# Mascot stuff
|
|
R(re.compile(r"(.*[_-])wilber(.*)"), r"\1mascot\2"),
|
|
R(re.compile(r"(.*)wilber([_-].*)"), r"\1mascot\2"),
|
|
R(re.compile(r"(.*[_-])WILBER(.*)"), r"\1MASCOT\2"),
|
|
|
|
# Chop out the wilber brush
|
|
R(re.compile(r"^[ \t]*'Wilber.gih',[ \t]*$"), ''),
|
|
]
|
|
|
|
#
|
|
# These regexps cause the replacement engine to skip the line once they match. This allows us to selectively skip some
|
|
# lines in the source code, and also cause a line to become skipped after some replacements.
|
|
#
|
|
CONTENTS_EXCEPTIONS: List[re.Pattern] = [
|
|
# skips generated by heckimp
|
|
re.compile(r".*#heckimp skip.*"),
|
|
# email addresses should not be replaced.
|
|
re.compile(r"(.*)@gimp\.org(.*)"),
|
|
# don't replace the expansion of GnuImp in the updated copyright notice
|
|
re.compile(r".*a rebranding of The GNU Image.*"),
|
|
# we want to preserve our copyright notice without it getting munged (its subtly different from the original)
|
|
re.compile(r".*Spencer Kimball, Peter Mattis and the GIMP Development Team, .*"),
|
|
|
|
# keep our xcfs compatible
|
|
re.compile(r'.*"gimp xcf.*'),
|
|
|
|
# Lets leave all of the weird urls alone for now until we let the user override them explicitly (or we rewrite
|
|
# the places they show up with our own versions of the strings) # FIXME the way it does skips breaks some
|
|
# replacements so we should fix this elsewise somehow.
|
|
#re.compile(r".*docs.gimp.org.*"),
|
|
#re.compile(r".*developer.gimp.org.*"),
|
|
#re.compile(r".wiki.gimp.org.*"),
|
|
re.compile(r".*irc.*gimp.org:6667.*"),
|
|
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/.*")
|
|
]
|
|
|
|
#
|
|
# This is the core filename renaming regexps.
|
|
#
|
|
FILENAME_REGEXP: List[Replacement] = [
|
|
# We'll stick all this historical cruft in its own directory.
|
|
R(re.compile(r"^gimp/README"), r'{filename}/upstream-documentation/README.upstream'),
|
|
R(re.compile(r"^gimp/(README.*)"), r'{filename}/upstream-documentation/\1'),
|
|
R(re.compile(r"^gimp/(Change[Ll]og.*)"), r'{filename}/upstream-documentation/\1'),
|
|
R(re.compile(r"^gimp/(NEWS.*)"), r'{filename}/upstream-documentation/\1'),
|
|
R(re.compile(r"^gimp/MAINTAINERS"), r'{filename}/upstream-documentation/MAINTAINERS.upstream'),
|
|
|
|
# other filename replacements
|
|
R(re.compile(r"(.*)org.gimp(.*)"), r'\1{backdomain}\2'),
|
|
R(re.compile(r"(.*)gimp(.*)"), r'\1{filename}\2'),
|
|
R(re.compile(r"(.*)GIMP(.*)"), r'\1{ufilename}\2'),
|
|
R(re.compile(r"(.*-)wilber(.*)"), r'\1mascot\2'),
|
|
]
|
|
|
|
#
|
|
# If a file matches one of these, it is skipped entirely (not copied or processed)
|
|
#
|
|
FILENAME_EXCEPTIONS: List[re.Pattern] = [
|
|
# We just leave the git out of it.
|
|
# If the fork should have a git repository it should probably not be connected to orignal.
|
|
re.compile(r"^gimp/\.git/.*"),
|
|
# re.compile(r"^gimp.icons.Legacy.*") # it'd be cool to chop this out but we'd have to patch icons/meson.build
|
|
|
|
# just chop out all the random Wilber images (including the brush)
|
|
re.compile(r".*Wilber*"),
|
|
]
|
|
|
|
#
|
|
# If a file matches one of these we skip processing but do copy it. We may have separate processes that also deal with
|
|
# these. FIXME we should proxbably process LICENSE, and copy NEWS and CHANGELOG etc to a subdirectory so they don't
|
|
# confuse the fork.
|
|
#
|
|
SKIP_PROCESSING: List[re.Pattern] = [
|
|
re.compile(r"^gimp/LICENSE"),
|
|
re.compile(r"^gimp/Change[Ll]og.*"),
|
|
re.compile(r"^gimp/NEWS.*"),
|
|
re.compile(r"^gimp/authors.*"),
|
|
re.compile(r"^gimp/AUTHORS"),
|
|
re.compile(r"^gimp/MAINTAINERS"),
|
|
]
|
|
|
|
#
|
|
# regexp that print extra debug info when a line matches them
|
|
#
|
|
DEBUG_REGEXP: List[re.Pattern] = [
|
|
# re.compile(r"^[ \t]+static const GimpEnum.*"),
|
|
]
|
|
|
|
# Regexes to match various specific files for special processing
|
|
SPLASH_REGEXP = re.compile(r".*gimp-splash.png")
|
|
ICON_REGEXP = re.compile(r".*desktop.([0-9]{2,3})x[0-9]{2,3}.gimp.png")
|
|
SCALABLE_REGEXP = re.compile(r".*desktop.scalable.gimp.svg")
|
|
LOGO_REGEXP = re.compile(r".*data.images.gimp-(devel-)?logo.png")
|
|
MASCOT_SCALABLE_REGEXP = re.compile(r"icons.(Symbolic|Color).scalable.gimp-wilber.*")
|
|
MASCOT_REGEXP = re.compile(r"icons.(Symbolic|Color|Lecgacy).([0-9]{2,3}).gimp-wilber.*")
|
|
|
|
|
|
MAKE_DIRECTORIES = ['{filename}/upstream-documentation']
|