transport-accessibility/transport_accessibility/get_foreignkeys.awk
Johannes Randerath 3853d25c1e Added LICENSE
- Code uses AGPL
- Docs use GNU FDL
2024-07-08 22:10:53 +02:00

45 lines
1.5 KiB
Awk

# Extract foreign keys from model definitions.
#
# This file is part of transport-accessibility.
# Copyright (C) 2024 Janek Kiljanski, Johannes Randerath
#
# transport-accessibility is free software: you can redistribute it and/or modify it under the terms of the
# GNU General Public License as published by the Free Software Foundation, either version 3
# of the License, or (at your option) any later version.
#
# transport-accessibility is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
# without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with transport-accessibility.
# If not, see <https://www.gnu.org/licenses/>.
BEGIN{
classname = ""
FS = "[ |(,]"
printf "[\n"
}
{
#print "1: "$1 " 2: "$2 " 3: "$3 " 4: "$4
if ($1 == "class") {
classname = $2
printf "\t(pt_map.models." classname ", ["
}else if ($0 == "" && classname != ""){
printf "]),\n"
classname = ""
}else {
fk = index($0, "models.ForeignKey")
if (fk > 0) {
first = match($0, /\(/)+1
last = index(substr($0, first), ",")-1
printf "(pt_map.models." substr($0, first, last) ", "
first = match($0, /[a-z]/)
last = index(substr($0, first), " = ")-1
printf "\'" substr($0, first, last) "\'), "
}
}
}
END{
print "]"
}