Skip to content

Commit 51ad6e8

Browse files
author
Continuous integration
committed
Upgrade to master
1 parent 85d4293 commit 51ad6e8

8 files changed

Lines changed: 46 additions & 141 deletions

File tree

CONST_create_template/build

Lines changed: 12 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,11 @@ from typing import TYPE_CHECKING, Any, List, Optional
1515

1616
import yaml
1717

18-
CompletedProcess = (
19-
subprocess.CompletedProcess[str] if TYPE_CHECKING else subprocess.CompletedProcess
20-
)
18+
CompletedProcess = subprocess.CompletedProcess[str] if TYPE_CHECKING else subprocess.CompletedProcess
2119

2220

2321
def run(
24-
args: argparse.Namespace,
25-
command: List[str],
26-
exit_on_error: bool = True,
27-
**kwargs: Any,
22+
args: argparse.Namespace, command: List[str], exit_on_error: bool = True, **kwargs: Any
2823
) -> Optional[CompletedProcess]:
2924
if args.verbose or args.dry_run:
3025
print(shlex.join(command))
@@ -41,25 +36,15 @@ def run(
4136

4237
def main() -> None:
4338
parser = argparse.ArgumentParser(description="Build the project")
39+
parser.add_argument("--verbose", action="store_true", help="Display the Docker build commands")
40+
parser.add_argument("--no-cache", action="store_true", help="Disable docker cache on build")
4441
parser.add_argument(
45-
"--verbose", action="store_true", help="Display the Docker build commands"
46-
)
47-
parser.add_argument(
48-
"--no-cache", action="store_true", help="Disable docker cache on build"
49-
)
50-
parser.add_argument(
51-
"--dry-run",
52-
action="store_true",
53-
help="Display the docker build commands without executing them",
42+
"--dry-run", action="store_true", help="Display the docker build commands without executing them"
5443
)
5544
parser.add_argument("--service", help="Build only the specified service")
5645
parser.add_argument("--env", action="store_true", help="Build only the .env file")
57-
parser.add_argument(
58-
"--simple", action="store_true", help="Force simple application mode"
59-
)
60-
parser.add_argument(
61-
"--not-simple", action="store_true", help="Force not simple application mode"
62-
)
46+
parser.add_argument("--simple", action="store_true", help="Force simple application mode")
47+
parser.add_argument("--not-simple", action="store_true", help="Force not simple application mode")
6348
parser.add_argument("--upgrade", help="Start upgrading the project to version")
6449
parser.add_argument(
6550
"--reload",
@@ -75,12 +60,9 @@ def main() -> None:
7560
help="Do not pull external or base images for faster rebuild during development.",
7661
)
7762
parser.add_argument(
78-
"--debug",
79-
help="Path to c2cgeoportal source folder to be able to debug the upgrade procedure",
80-
)
81-
parser.add_argument(
82-
"--stack-trace", action="store_true", help="Display the stack trace on error"
63+
"--debug", help="Path to c2cgeoportal source folder to be able to debug the upgrade procedure"
8364
)
65+
parser.add_argument("--stack-trace", action="store_true", help="Display the stack trace on error")
8466
parser.add_argument("env_files", nargs="*", help="The environment config")
8567
args = parser.parse_args()
8668

@@ -142,11 +124,7 @@ def main() -> None:
142124
if args.not_simple:
143125
simple = False
144126

145-
git_hash = (
146-
run(args, ["git", "rev-parse", "HEAD"], stdout=subprocess.PIPE)
147-
.stdout.decode()
148-
.strip()
149-
)
127+
git_hash = run(args, ["git", "rev-parse", "HEAD"], stdout=subprocess.PIPE).stdout.decode().strip()
150128

151129
dest.write(f"SIMPLE={str(simple).upper()}\n")
152130
dest.write(f"GIT_HASH={git_hash}\n")
@@ -165,9 +143,7 @@ def main() -> None:
165143
if not args.no_pull:
166144
# Pull all the images
167145
if not args.service:
168-
run(
169-
args, [*docker_compose_command, "pull", "--ignore-buildable"]
170-
) # nosec
146+
run(args, [*docker_compose_command, "pull", "--ignore-buildable"]) # nosec
171147
docker_compose_build_cmd.append("--pull")
172148

173149
if args.service:
@@ -205,16 +181,7 @@ def main() -> None:
205181
if args.reload is not None:
206182
run(args, [*docker_compose_command, "rm", "--force", "-v", "config"])
207183
for service in services:
208-
run(
209-
args,
210-
[
211-
*docker_compose_command,
212-
"up",
213-
"--detach",
214-
"--force-recreate",
215-
service,
216-
],
217-
)
184+
run(args, [*docker_compose_command, "up", "--detach", "--force-recreate", service])
218185

219186

220187
if __name__ == "__main__":

CONST_create_template/ci/docker-compose-check

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,11 @@ def _main() -> None:
1111

1212
services = [
1313
s.strip()
14-
for s in subprocess.run(
15-
["docker", "compose", "ps"], check=True, stdout=subprocess.PIPE
16-
)
14+
for s in subprocess.run(["docker", "compose", "ps"], check=True, stdout=subprocess.PIPE)
1715
.stdout.decode("utf-8")
1816
.splitlines()
1917
]
20-
errors_statuses = [
21-
s for s in services if " Exit " in s and not s.endswith(" Exit 0")
22-
]
18+
errors_statuses = [s for s in services if " Exit " in s and not s.endswith(" Exit 0")]
2319
if errors_statuses:
2420
print("\n".join(errors_statuses))
2521
sys.exit(1)

CONST_create_template/scripts/db-backup

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,9 @@ import sys
3737
def main() -> None:
3838
"""Backup the database."""
3939
parser = argparse.ArgumentParser(description="Backup the database.")
40+
parser.add_argument("--verbose", action="store_true", help="Print the command that is executed.")
4041
parser.add_argument(
41-
"--verbose", action="store_true", help="Print the command that is executed."
42-
)
43-
parser.add_argument(
44-
"--dry-run",
45-
action="store_true",
46-
help="Only print the command that would be executed.",
42+
"--dry-run", action="store_true", help="Only print the command that would be executed."
4743
)
4844
parser.add_argument(
4945
"--env",
@@ -83,16 +79,8 @@ def main() -> None:
8379
command2 = ["--env=PGPASSWORD={}".format(env["PGPASSWORD"])]
8480
command2_annon = ["--env=PGPASSWORD=***"]
8581
command3 = [
86-
*(
87-
["--env=PGSSLMODE={}".format(env["PGSSLMODE"])]
88-
if "PGSSLMODE" in env
89-
else []
90-
),
91-
*(
92-
["--env=PGOPTIONS={}".format(env["PGOPTIONS"])]
93-
if "PGOPTIONS" in env
94-
else []
95-
),
82+
*(["--env=PGSSLMODE={}".format(env["PGSSLMODE"])] if "PGSSLMODE" in env else []),
83+
*(["--env=PGOPTIONS={}".format(env["PGOPTIONS"])] if "PGOPTIONS" in env else []),
9684
"camptocamp/postgres:{}".format(env["POSTGRES_TAG"]),
9785
"pg_dump",
9886
"--format=c",
@@ -113,11 +101,7 @@ def main() -> None:
113101
print(shlex.join([*command1, *command2_annon, *command3]))
114102
if args.dry_run:
115103
sys.exit(0)
116-
sys.exit(
117-
subprocess.run(
118-
[*command1, *command2, *command3], stdout=file_out
119-
).returncode
120-
)
104+
sys.exit(subprocess.run([*command1, *command2, *command3], stdout=file_out).returncode)
121105
else:
122106
command = [
123107
"docker",
@@ -131,9 +115,7 @@ def main() -> None:
131115
*args.arg,
132116
]
133117
if args.dry_run or args.verbose:
134-
subprocess.run(
135-
["docker", "compose", "exec", "tools", "pg_dump", "--version"]
136-
)
118+
subprocess.run(["docker", "compose", "exec", "tools", "pg_dump", "--version"])
137119
print(shlex.join(command))
138120
if args.dry_run:
139121
sys.exit(0)

CONST_create_template/scripts/db-restore

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,9 @@ import sys
3636
def main() -> None:
3737
"""Restore the database backup."""
3838
parser = argparse.ArgumentParser(description="Restore the database backup.")
39+
parser.add_argument("--verbose", action="store_true", help="Print the command that is executed.")
3940
parser.add_argument(
40-
"--verbose", action="store_true", help="Print the command that is executed."
41-
)
42-
parser.add_argument(
43-
"--dry-run",
44-
action="store_true",
45-
help="Only print the command that would be executed.",
41+
"--dry-run", action="store_true", help="Only print the command that would be executed."
4642
)
4743
parser.add_argument(
4844
"--env",
@@ -90,16 +86,8 @@ def main() -> None:
9086
]
9187
command2_annon = ["--env=PGPASSWORD=***"]
9288
command3 = [
93-
*(
94-
["--env=PGSSLMODE={}".format(env["PGSSLMODE"])]
95-
if "PGSSLMODE" in env
96-
else []
97-
),
98-
*(
99-
["--env=PGOPTIONS={}".format(env["PGOPTIONS"])]
100-
if "PGOPTIONS" in env
101-
else []
102-
),
89+
*(["--env=PGSSLMODE={}".format(env["PGSSLMODE"])] if "PGSSLMODE" in env else []),
90+
*(["--env=PGOPTIONS={}".format(env["PGOPTIONS"])] if "PGOPTIONS" in env else []),
10391
"camptocamp/postgres:{}".format(env["POSTGRES_TAG"]),
10492
"pg_restore",
10593
"--dbname={}".format(env["PGDATABASE"]),
@@ -119,11 +107,7 @@ def main() -> None:
119107
print(shlex.join([*command1, *command2_annon, *command3]))
120108
if args.dry_run:
121109
sys.exit(0)
122-
sys.exit(
123-
subprocess.run(
124-
[*command1, *command2, *command3], stdin=file_in
125-
).returncode
126-
)
110+
sys.exit(subprocess.run([*command1, *command2, *command3], stdin=file_in).returncode)
127111
else:
128112
command = [
129113
"docker",
@@ -137,9 +121,7 @@ def main() -> None:
137121
'pg_restore --dbname="$PGDATABASE" ' + " ".join(args.arg),
138122
]
139123
if args.verbose or args.dry_run:
140-
subprocess.run(
141-
["docker", "compose", "exec", "tools", "pg_restore", "--version"]
142-
)
124+
subprocess.run(["docker", "compose", "exec", "tools", "pg_restore", "--version"])
143125
print(shlex.join(command))
144126
if args.dry_run:
145127
sys.exit(0)

CONST_create_template/scripts/qgis-project-download

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,20 @@ Example usage:
2424
formatter_class=argparse.RawTextHelpFormatter,
2525
)
2626
parser.add_argument("schema", default="qgis", help="Source PostgreSQL schema name")
27-
parser.add_argument(
28-
"project", default="project.qgz", help="Source QGIS project name"
29-
)
30-
parser.add_argument(
31-
"filename", default="qgisserver/project.qgz", help="Destination file name"
32-
)
27+
parser.add_argument("project", default="project.qgz", help="Source QGIS project name")
28+
parser.add_argument("filename", default="qgisserver/project.qgz", help="Destination file name")
3329
args = parser.parse_args()
3430

3531
# Connect to a DB, e.g., the test DB on your localhost, and get a cursor
3632
with psycopg2.connect(f"dbname={os.environ['PGDATABASE']}") as connection:
3733
with connection.cursor() as cursor:
38-
query = sql.SQL("""
34+
query = sql.SQL(
35+
"""
3936
SELECT content
4037
FROM {}.qgis_projects
4138
WHERE name = %(name)s;
42-
""").format(sql.Identifier(args.schema))
39+
"""
40+
).format(sql.Identifier(args.schema))
4341

4442
cursor.execute(query, {"name": args.project})
4543
rows = cursor.fetchall()
@@ -49,9 +47,7 @@ Example usage:
4947
with path.open("wb") as f:
5048
f.write(data)
5149

52-
print(
53-
f"Project {args.project} from schema {args.schema} downloaded as {args.filename}"
54-
)
50+
print(f"Project {args.project} from schema {args.schema} downloaded as {args.filename}")
5551

5652

5753
if __name__ == "__main__":

CONST_create_template/scripts/qgis-project-upload

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,9 @@ Example usage:
2323
""",
2424
formatter_class=argparse.RawTextHelpFormatter,
2525
)
26-
parser.add_argument(
27-
"filename", default="qgisserver/project.qgz", help="Source file name"
28-
)
29-
parser.add_argument(
30-
"schema", default="qgis", help="Destination PostgreSQL schema name"
31-
)
32-
parser.add_argument(
33-
"project", default="project.qgz", help="Destination QGIS project name"
34-
)
26+
parser.add_argument("filename", default="qgisserver/project.qgz", help="Source file name")
27+
parser.add_argument("schema", default="qgis", help="Destination PostgreSQL schema name")
28+
parser.add_argument("project", default="project.qgz", help="Destination QGIS project name")
3529
args = parser.parse_args()
3630

3731
# Connect to a DB, e.g., the test DB on your localhost, and get a cursor
@@ -41,11 +35,13 @@ Example usage:
4135
with path.open("rb") as f:
4236
data = f.read()
4337

44-
query = sql.SQL("""
38+
query = sql.SQL(
39+
"""
4540
UPDATE {}.qgis_projects
4641
SET content = %(content)s
4742
WHERE name = %(name)s;
48-
""").format(sql.Identifier(args.schema))
43+
"""
44+
).format(sql.Identifier(args.schema))
4945

5046
cursor.execute(
5147
query,
@@ -55,9 +51,7 @@ Example usage:
5551
},
5652
)
5753

58-
print(
59-
f"Project {args.filename} uploaded in schema {args.schema} with name {args.project}"
60-
)
54+
print(f"Project {args.filename} uploaded in schema {args.schema} with name {args.project}")
6155

6256

6357
if __name__ == "__main__":

CONST_create_template/tests/test_app.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,7 @@
1111
("https://front/themes", {}, 120),
1212
("https://front/static-geomapfish/0/locales/fr.json", {}, 2),
1313
("https://front/dynamic.json", {"interface": "desktop"}, 10),
14-
(
15-
"https://front/dynamic.json",
16-
{"interface": "desktop", "query": "", "path": "/"},
17-
10,
18-
),
14+
("https://front/dynamic.json", {"interface": "desktop", "query": "", "path": "/"}, 10),
1915
("https://front/c2c/health_check", {}, 2),
2016
("https://front/c2c/health_check", {"max_level": "1"}, 2),
2117
("https://front/c2c/health_check", {"checker": "check_collector"}, 2),
@@ -67,9 +63,7 @@
6763
def test_url(url: str, params: dict[str, str], timeout: int) -> None:
6864
"""Tests that some URL didn't return an error."""
6965
for _ in range(6):
70-
response = requests.get(
71-
url, params=params, verify=False, timeout=timeout
72-
) # nosec
66+
response = requests.get(url, params=params, verify=False, timeout=timeout) # nosec
7367
if response.status_code == 503:
7468
time.sleep(1)
7569
continue

CONST_create_template/tests/test_testapp.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@ def test_po(test_number: int) -> None:
1212
"""Tests that the generated pot files are identical between the command line and the view."""
1313
del test_number
1414

15-
response = requests.get(
16-
"https://front/locale.pot", verify=False, timeout=30
17-
) # nosec
15+
response = requests.get("https://front/locale.pot", verify=False, timeout=30) # nosec
1816
assert response.status_code == 200, response.text
1917
response_keys = {e.msgid for e in polib.pofile(response.text)}
2018

@@ -44,11 +42,7 @@ def test_desktop_alt(url: str) -> None:
4442

4543
def test_enum() -> None:
4644
"""Test the enumerations view."""
47-
response = requests.get(
48-
"https://front/layers/test/values/type", verify=False, timeout=30
49-
) # nosec
45+
response = requests.get("https://front/layers/test/values/type", verify=False, timeout=30) # nosec
5046
assert response.status_code == 200, response.text
5147

52-
assert response.json() == {
53-
"items": [{"value": "car"}, {"value": "train"}]
54-
}, response.text
48+
assert response.json() == {"items": [{"value": "car"}, {"value": "train"}]}, response.text

0 commit comments

Comments
 (0)