Mercurial > sat_docs
annotate flatpak/build_manifest.py @ 162:b451da01696a
flatpak: added `content_rating` in appdata files
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 23 Aug 2019 16:42:24 +0200 |
parents | 4fe61dcd856e |
children | a213053a03be |
rev | line source |
---|---|
138
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1 #!/usr/bin/env python3 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
2 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
3 import tempfile |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
4 import subprocess |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
5 from pathlib import Path |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
6 from typing import List |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
7 from dataclasses import dataclass |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
8 import hashlib |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
9 from ftplib import FTP |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
10 from urllib.parse import urlparse |
139
d36a68e396d5
flatpak: set appdata release version for dev version:
Goffi <goffi@goffi.org>
parents:
138
diff
changeset
|
11 from textwrap import dedent |
138
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
12 import sys |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
13 import os |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
14 import json |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
15 import time |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
16 import argparse |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
17 import shutil |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
18 from packaging.version import parse as parse_version |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
19 import requests |
139
d36a68e396d5
flatpak: set appdata release version for dev version:
Goffi <goffi@goffi.org>
parents:
138
diff
changeset
|
20 from lxml import etree |
138
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
21 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
22 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
23 CACHE_LIMIT = 3600 * 24 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
24 PYTHON_DEP_OVERRIDE = { |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
25 "lxml": { |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
26 "build-commands": [ |
153
df75b62e653e
flatpak (build_manifest): some fixes needed after runtime update:
Goffi <goffi@goffi.org>
parents:
151
diff
changeset
|
27 # --optimize=1 make the build fail, to be tried again once moved to Python3 |
df75b62e653e
flatpak (build_manifest): some fixes needed after runtime update:
Goffi <goffi@goffi.org>
parents:
151
diff
changeset
|
28 # "python2 ./setup.py install --prefix=${FLATPAK_DEST} --optimize=1" |
df75b62e653e
flatpak (build_manifest): some fixes needed after runtime update:
Goffi <goffi@goffi.org>
parents:
151
diff
changeset
|
29 "python2 ./setup.py install --prefix=${FLATPAK_DEST}" |
138
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
30 ], |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
31 "build-options": { |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
32 "env": { |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
33 "XSLT_CONFIG": "pkg-config libxslt" |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
34 } |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
35 }, |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
36 }, |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
37 "dbus-python": { |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
38 "build-commands": [ |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
39 "python2 setup.py build", |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
40 "python2 setup.py install --prefix=${FLATPAK_DEST}", |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
41 ] |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
42 }, |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
43 "kivy": { |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
44 "post-install": [ |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
45 # this file is not copied normally when installing with |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
46 # `python2 setup.py install`. |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
47 # TODO: report upstream |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
48 "cp kivy/setupconfig.py /app/lib/python2.7/site-packages/Kivy-*.egg/kivy/" |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
49 ] |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
50 }, |
153
df75b62e653e
flatpak (build_manifest): some fixes needed after runtime update:
Goffi <goffi@goffi.org>
parents:
151
diff
changeset
|
51 "pillow": { |
df75b62e653e
flatpak (build_manifest): some fixes needed after runtime update:
Goffi <goffi@goffi.org>
parents:
151
diff
changeset
|
52 "build-options": { |
df75b62e653e
flatpak (build_manifest): some fixes needed after runtime update:
Goffi <goffi@goffi.org>
parents:
151
diff
changeset
|
53 "arch": { |
df75b62e653e
flatpak (build_manifest): some fixes needed after runtime update:
Goffi <goffi@goffi.org>
parents:
151
diff
changeset
|
54 "x86_64": { |
df75b62e653e
flatpak (build_manifest): some fixes needed after runtime update:
Goffi <goffi@goffi.org>
parents:
151
diff
changeset
|
55 "ldflags": "-L/usr/lib/x86_64-linux-gnu" |
df75b62e653e
flatpak (build_manifest): some fixes needed after runtime update:
Goffi <goffi@goffi.org>
parents:
151
diff
changeset
|
56 } |
df75b62e653e
flatpak (build_manifest): some fixes needed after runtime update:
Goffi <goffi@goffi.org>
parents:
151
diff
changeset
|
57 } |
df75b62e653e
flatpak (build_manifest): some fixes needed after runtime update:
Goffi <goffi@goffi.org>
parents:
151
diff
changeset
|
58 } |
df75b62e653e
flatpak (build_manifest): some fixes needed after runtime update:
Goffi <goffi@goffi.org>
parents:
151
diff
changeset
|
59 }, |
138
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
60 } |
161
4fe61dcd856e
flatpak: update build-manifest to retrieve dependencies without initial download phase:
Goffi <goffi@goffi.org>
parents:
157
diff
changeset
|
61 # FIXME: Q&D way to install older version of twisted for Flatpak |
4fe61dcd856e
flatpak: update build-manifest to retrieve dependencies without initial download phase:
Goffi <goffi@goffi.org>
parents:
157
diff
changeset
|
62 PYTHON_DEP_PREINSTALL = ['twisted<19.7.0'] |
138
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
63 PYTHON_DEP_REQUIREMENTS_UPDATE = { |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
64 # service-identity is not seen as a twisted requirement, so it's sometimes misplaced |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
65 'twisted': ['service-identity'], |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
66 } |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
67 PYTHON_SETUP_REQUIREMENTS = [ |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
68 'setuptools', # to have an up-to-date version |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
69 'setuptools_scm', |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
70 'docutils', # needed my m2r |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
71 'mistune', # needed my m2r |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
72 'm2r', # needed by automat |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
73 ] |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
74 DEFAULT_MANIFEST = { |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
75 "runtime": "org.freedesktop.Platform", |
151
6f8c849daf2a
flatpak (build_manifest): updated org.freedesktop.Platform runtime version:
Goffi <goffi@goffi.org>
parents:
150
diff
changeset
|
76 "runtime-version": "18.08", |
138
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
77 "sdk": "org.freedesktop.Sdk", |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
78 "command": "sat_wrapper", |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
79 "finish-args": [ |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
80 "--socket=session-bus", |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
81 "--share=network", |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
82 "--filesystem=home" |
153
df75b62e653e
flatpak (build_manifest): some fixes needed after runtime update:
Goffi <goffi@goffi.org>
parents:
151
diff
changeset
|
83 ], |
df75b62e653e
flatpak (build_manifest): some fixes needed after runtime update:
Goffi <goffi@goffi.org>
parents:
151
diff
changeset
|
84 "modules": [ |
161
4fe61dcd856e
flatpak: update build-manifest to retrieve dependencies without initial download phase:
Goffi <goffi@goffi.org>
parents:
157
diff
changeset
|
85 "shared-modules/python2.7/python-2.7.json", |
138
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
86 ] |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
87 } |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
88 SHOW_REQUIRES_HEADER = 'Requires: ' |
161
4fe61dcd856e
flatpak: update build-manifest to retrieve dependencies without initial download phase:
Goffi <goffi@goffi.org>
parents:
157
diff
changeset
|
89 SHOW_VERSION_HEADER = 'Version: ' |
138
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
90 SETTINGS_KEY = '_build_settings' |
139
d36a68e396d5
flatpak: set appdata release version for dev version:
Goffi <goffi@goffi.org>
parents:
138
diff
changeset
|
91 APPDATA_RELEASE_DEV_TEXT = dedent("""\ |
d36a68e396d5
flatpak: set appdata release version for dev version:
Goffi <goffi@goffi.org>
parents:
138
diff
changeset
|
92 This is a development version, used as a preview. |
d36a68e396d5
flatpak: set appdata release version for dev version:
Goffi <goffi@goffi.org>
parents:
138
diff
changeset
|
93 Please note that it is incomplete and it probably contains bugs. |
d36a68e396d5
flatpak: set appdata release version for dev version:
Goffi <goffi@goffi.org>
parents:
138
diff
changeset
|
94 """) |
d36a68e396d5
flatpak: set appdata release version for dev version:
Goffi <goffi@goffi.org>
parents:
138
diff
changeset
|
95 OVERWRITE_WARNING = "{} already exists, do you want to overwrite it (y/N)? " |
138
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
96 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
97 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
98 @dataclass |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
99 class Package: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
100 name: str |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
101 version: str |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
102 hash_: str |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
103 url: str |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
104 requirements: List[str] |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
105 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
106 def __hash__(self): |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
107 return hash(self.name) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
108 |
161
4fe61dcd856e
flatpak: update build-manifest to retrieve dependencies without initial download phase:
Goffi <goffi@goffi.org>
parents:
157
diff
changeset
|
109 def __eq__(self, other): |
4fe61dcd856e
flatpak: update build-manifest to retrieve dependencies without initial download phase:
Goffi <goffi@goffi.org>
parents:
157
diff
changeset
|
110 return self.name == other.name |
4fe61dcd856e
flatpak: update build-manifest to retrieve dependencies without initial download phase:
Goffi <goffi@goffi.org>
parents:
157
diff
changeset
|
111 |
138
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
112 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
113 def print_step(step): |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
114 print() |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
115 print("┌" + "─" * (len(step) + 2) + "┐") |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
116 print("│ {} │".format(step)) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
117 print("└" + "─" * (len(step) + 2) + "┘") |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
118 print() |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
119 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
120 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
121 def parse_args(): |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
122 parser = argparse.ArgumentParser( |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
123 description='Flatpak manifest builder for Salut à Toi') |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
124 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
125 build_group = parser.add_argument_group('building', 'options used to generate the manifest') |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
126 export_group = parser.add_argument_group('export', 'otions used to building files') |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
127 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
128 # build group |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
129 build_group.add_argument('-f', '--force', action="store_true", |
139
d36a68e396d5
flatpak: set appdata release version for dev version:
Goffi <goffi@goffi.org>
parents:
138
diff
changeset
|
130 help="force overwritting of existing manifest and appdata file") |
138
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
131 build_group.add_argument('--ignore-cache', action='append', default=[], |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
132 help='ignore the cache of this step ("all" to ignore all caches)') |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
133 build_group.add_argument( |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
134 '--deps-dir', |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
135 help="use this directory to build_group python dependencies (it won't be deleted at " |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
136 "the end, useful when you want to re-use it and avoir re-downloading)") |
140
e23e414987d7
flatpak (build_manifest): --no-binary is currently disabled as version parsing doesn't handle yet wheel packages.
Goffi <goffi@goffi.org>
parents:
139
diff
changeset
|
137 # build_group.add_argument('--no-binary', help="don't use binary packages") |
138
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
138 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
139 # export group |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
140 export_group.add_argument('-s', '--symlink', choices=['no', 'all', 'cache'], |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
141 default='no', |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
142 help='"no" to copy all files, "all" to symlink all files, "cache" to copy files ' |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
143 'and symlink only cache (default: "no")') |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
144 export_group.add_argument('-F', '--force-export', action='store_true', |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
145 help='force overwritting of existing files/symlinks when exporting (DEFAULT: ' |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
146 'existing files are skipped)') |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
147 export_group.add_argument('-e', '--export', type=Path, |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
148 help="export build files to this directory (DEFAULT: don't export files)") |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
149 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
150 # common |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
151 parser.add_argument('name', type=str, help="name of the package to build_group") |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
152 parser.add_argument('version', type=str, help="version of the package to build_group") |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
153 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
154 args = parser.parse_args() |
140
e23e414987d7
flatpak (build_manifest): --no-binary is currently disabled as version parsing doesn't handle yet wheel packages.
Goffi <goffi@goffi.org>
parents:
139
diff
changeset
|
155 # FIXME: no_binary is currently not managed because version parser doesn't handle |
e23e414987d7
flatpak (build_manifest): --no-binary is currently disabled as version parsing doesn't handle yet wheel packages.
Goffi <goffi@goffi.org>
parents:
139
diff
changeset
|
156 # wheels |
e23e414987d7
flatpak (build_manifest): --no-binary is currently disabled as version parsing doesn't handle yet wheel packages.
Goffi <goffi@goffi.org>
parents:
139
diff
changeset
|
157 args.no_binary = True |
138
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
158 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
159 if 'all' in args.ignore_cache and len(args.ignore_cache) != 1: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
160 parser.error('"all" cannot be used with step names in --ignore-cache, ' |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
161 'use it alone') |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
162 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
163 if args.export is not None and not args.export.is_dir(): |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
164 parser.error(f"{args.export} is not a directory!") |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
165 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
166 return args |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
167 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
168 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
169 ## useful methods ## |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
170 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
171 def get_cache(name): |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
172 """Retrieve cache for a step |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
173 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
174 cache will be ignored if too old, or explicitly ignored by user |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
175 @param name(str): name of the step |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
176 @return (object): cached data |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
177 """ |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
178 # name of the cache without prefix, mainly used for python_deps |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
179 shortname = name.split('__', 1)[0] |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
180 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
181 if shortname in args.ignore_cache or 'all' in args.ignore_cache: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
182 print(f"ignoring cache for {shortname}") |
154
cd411b0d1e19
flatpak (build_manifest): fixed ignore-cache when "all" is used
Goffi <goffi@goffi.org>
parents:
153
diff
changeset
|
183 if shortname in args.ignore_cache: |
cd411b0d1e19
flatpak (build_manifest): fixed ignore-cache when "all" is used
Goffi <goffi@goffi.org>
parents:
153
diff
changeset
|
184 args.ignore_cache.remove(shortname) |
138
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
185 return None |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
186 try: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
187 cache_name = cache[name] |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
188 cache_updated = cache_name['updated'] |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
189 except KeyError: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
190 return None |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
191 if time.time() - cache_updated > CACHE_LIMIT: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
192 print(f"cache for {name} is too old, we won't use it") |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
193 return None |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
194 print(f"cache found for {shortname}") |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
195 return cache_name['data'] |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
196 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
197 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
198 def set_cache(name, data): |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
199 """Update cache for a step |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
200 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
201 @param name(str): name of the step |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
202 @param data(object): data to cache |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
203 """ |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
204 cache_name = cache.setdefault(name, {}) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
205 cache_name['updated'] = time.time() |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
206 cache_name['data'] = data |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
207 with cache_path.open('w') as f: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
208 json.dump(cache, f) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
209 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
210 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
211 def get_python_package(package_name, step_name=None, step_message=None, with_pre=False, |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
212 version=None): |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
213 """Generate module for a Python package |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
214 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
215 @param package_name(str, list[str]): name of the Python package |
157
150085e39072
flatpak (build_manifest): version can be forced in setup_requirements + force cython version in cagou template
Goffi <goffi@goffi.org>
parents:
156
diff
changeset
|
216 use list of str to get several packages at once. |
150085e39072
flatpak (build_manifest): version can be forced in setup_requirements + force cython version in cagou template
Goffi <goffi@goffi.org>
parents:
156
diff
changeset
|
217 A (name, version) tuple (or any size 2 iterable) can be used to force version of a |
150085e39072
flatpak (build_manifest): version can be forced in setup_requirements + force cython version in cagou template
Goffi <goffi@goffi.org>
parents:
156
diff
changeset
|
218 package. |
150085e39072
flatpak (build_manifest): version can be forced in setup_requirements + force cython version in cagou template
Goffi <goffi@goffi.org>
parents:
156
diff
changeset
|
219 If package is a list with iterables, it will be modified in place to keep only the |
150085e39072
flatpak (build_manifest): version can be forced in setup_requirements + force cython version in cagou template
Goffi <goffi@goffi.org>
parents:
156
diff
changeset
|
220 name as string. This is because version is not needed anymore after that, but |
150085e39072
flatpak (build_manifest): version can be forced in setup_requirements + force cython version in cagou template
Goffi <goffi@goffi.org>
parents:
156
diff
changeset
|
221 name is still used to remove dependencies already installed with setup |
150085e39072
flatpak (build_manifest): version can be forced in setup_requirements + force cython version in cagou template
Goffi <goffi@goffi.org>
parents:
156
diff
changeset
|
222 requirements. |
138
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
223 @param step_name(None, str): name of the step, None to use package_name |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
224 @param step_message(None, str): message of the step (None to use default one) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
225 use empty string to disable it |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
226 @param with_pre(bool): if True retrieve also pre-releases |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
227 @param version(str, None): indicate the version of the package to download |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
228 if None, the most recent version compativle with `with_pre` will be used |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
229 """ |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
230 single = isinstance(package_name, str) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
231 if step_name is None: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
232 step_name = package_name if single else ' - '.join(package_name) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
233 if step_message != "": |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
234 print_step(step_message or f"retrieving latest version of {package_name}") |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
235 cache = get_cache(step_name) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
236 if cache is not None: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
237 return cache |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
238 package_names = [package_name] if single else package_name |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
239 data = [] |
157
150085e39072
flatpak (build_manifest): version can be forced in setup_requirements + force cython version in cagou template
Goffi <goffi@goffi.org>
parents:
156
diff
changeset
|
240 |
150085e39072
flatpak (build_manifest): version can be forced in setup_requirements + force cython version in cagou template
Goffi <goffi@goffi.org>
parents:
156
diff
changeset
|
241 for idx, name in enumerate(package_names): |
150085e39072
flatpak (build_manifest): version can be forced in setup_requirements + force cython version in cagou template
Goffi <goffi@goffi.org>
parents:
156
diff
changeset
|
242 if not isinstance(name, str): |
150085e39072
flatpak (build_manifest): version can be forced in setup_requirements + force cython version in cagou template
Goffi <goffi@goffi.org>
parents:
156
diff
changeset
|
243 if version is not None: |
150085e39072
flatpak (build_manifest): version can be forced in setup_requirements + force cython version in cagou template
Goffi <goffi@goffi.org>
parents:
156
diff
changeset
|
244 raise ValueError( |
150085e39072
flatpak (build_manifest): version can be forced in setup_requirements + force cython version in cagou template
Goffi <goffi@goffi.org>
parents:
156
diff
changeset
|
245 "forced version can't be used with packages versions (i.e. tuples)") |
150085e39072
flatpak (build_manifest): version can be forced in setup_requirements + force cython version in cagou template
Goffi <goffi@goffi.org>
parents:
156
diff
changeset
|
246 name, forced_version = name |
150085e39072
flatpak (build_manifest): version can be forced in setup_requirements + force cython version in cagou template
Goffi <goffi@goffi.org>
parents:
156
diff
changeset
|
247 package_names[idx] = name |
150085e39072
flatpak (build_manifest): version can be forced in setup_requirements + force cython version in cagou template
Goffi <goffi@goffi.org>
parents:
156
diff
changeset
|
248 else: |
150085e39072
flatpak (build_manifest): version can be forced in setup_requirements + force cython version in cagou template
Goffi <goffi@goffi.org>
parents:
156
diff
changeset
|
249 forced_version = version |
138
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
250 r = requests.get(f"https://pypi.org/pypi/{name}/json") |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
251 r.raise_for_status() |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
252 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
253 releases_data = [] |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
254 for version_raw, release_data in r.json()["releases"].items(): |
157
150085e39072
flatpak (build_manifest): version can be forced in setup_requirements + force cython version in cagou template
Goffi <goffi@goffi.org>
parents:
156
diff
changeset
|
255 if forced_version is not None and forced_version != version_raw: |
138
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
256 continue |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
257 release_version = parse_version(version_raw) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
258 if release_version.is_prerelease and not with_pre: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
259 continue |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
260 releases_data.append((release_version, release_data)) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
261 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
262 # we sort releases by version to be sure to have latests one |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
263 releases_data.sort(key=lambda d: d[0]) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
264 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
265 try: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
266 release_version, release_data = releases_data[-1] |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
267 package = next(r for r in release_data if r["packagetype"] == "sdist") |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
268 except (IndexError, StopIteration): |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
269 raise RuntimeError(f"Can't find a matching package for {name}") |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
270 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
271 print(f"{name} {release_version} will be used") |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
272 dep_data = { |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
273 "name": name, |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
274 "buildsystem": "simple", |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
275 "build-commands": [ |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
276 "python2 setup.py install --prefix=${FLATPAK_DEST}" |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
277 ], |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
278 "sources": [ |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
279 { |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
280 "type": "archive", |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
281 "url": package["url"], |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
282 "sha256": package["digests"]["sha256"], |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
283 } |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
284 ], |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
285 "ensure-writable": [ |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
286 "/lib/python2.7/site-packages/easy-install.pth", |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
287 "/lib/python2.7/site-packages/setuptools.pth", |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
288 ] |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
289 } |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
290 data.append(dep_data) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
291 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
292 set_cache(step_name, data) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
293 return data |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
294 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
295 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
296 def file_upload(filename, dest="/app/bin", src=None, replace=None, use_install=False): |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
297 """Generate manifest modules to upload a local file |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
298 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
299 @param filename(str): name of the local file to upload |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
300 Note that it will be overwritted if replace is used |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
301 @param dest(str, Path): path where the file must be installed in the container |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
302 @param src(str, None): when replace is used, name of the source file |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
303 @param replace(dict, None): mapping of text to replace |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
304 Use when file must be dynamicly adapted to the container, note that src must be |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
305 set to the name of the template file if this is used. |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
306 e.g. {'##COMMAND##', 'cagou'} will replace all '##COMMAND##' in filename |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
307 by 'cagou' |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
308 @param use_install(bool): if True, install file with `install src dest` |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
309 else, use `mv src dest` |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
310 @return (list(dict)): modules to add to the manifest |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
311 """ |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
312 assert isinstance(filename, str) and '/' not in filename |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
313 print_step(f"generating {filename} module") |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
314 # no cache for this one, to be sure to have always latest version |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
315 filename = Path(filename) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
316 if src is None: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
317 file_to_test = filename |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
318 else: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
319 src = Path(src) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
320 file_to_test = src |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
321 if not file_to_test.exists(): |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
322 raise RuntimeError( |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
323 f"{file_to_test} is missing, it is needed to build the manifest!") |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
324 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
325 if replace: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
326 if src is None: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
327 raise ValueError( |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
328 '"src" must be set to name of template file if replace is used') |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
329 print(f'doing replacement in template "{src}" to dest "{filename}"') |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
330 # there are strings to replace, we read file, do the changes and dump the |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
331 # result in <filename> |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
332 with open(src) as f: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
333 buff = f.read() |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
334 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
335 for old, new in replace.items(): |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
336 buff = buff.replace(old, new) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
337 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
338 with open(filename, 'w') as f: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
339 f.write(buff) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
340 else: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
341 if src is not None: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
342 raise ValueError('"src" must not be used if replace is not used') |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
343 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
344 with filename.open('rb') as f: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
345 hash_ = hashlib.sha256(f.read()).hexdigest() |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
346 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
347 dest = Path(dest) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
348 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
349 dep_data = { |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
350 "name": str(filename), |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
351 "buildsystem": "simple", |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
352 "build-commands": [ |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
353 ], |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
354 "sources": [ |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
355 { |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
356 "type": "file", |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
357 "path": str(filename), |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
358 "sha256": hash_, |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
359 } |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
360 ] |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
361 } |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
362 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
363 build_commands = dep_data['build-commands'] |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
364 if use_install: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
365 build_commands.append(f"install -Dv {filename} {dest}") |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
366 else: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
367 if dest.as_posix() not in ('/app', '/app/bin'): |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
368 # just in case the destination directory doesn't exist |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
369 build_commands.append(f"mkdir -p {dest.parent}") |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
370 build_commands.append(f"mv -v {filename} {dest}") |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
371 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
372 return [dep_data] |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
373 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
374 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
375 def file_from_url(url, dest=None, step_name=None, step_message=None): |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
376 """Generate manifest modules for a file either on a http(s) url or local |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
377 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
378 @param url(str): url of the file to use, or local path |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
379 if it starts with http, url will be used, else file_upload(url) will be used |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
380 @param dest(str, None): path were the file should be copied |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
381 """ |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
382 parsed = urlparse(url) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
383 if not parsed.scheme: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
384 return file_upload(url) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
385 if not parsed.scheme.startswith('http'): |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
386 raise NotImplementedError ( |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
387 f'we can\'t use the URL "{url}", the scheme "{parsed.scheme}" is not managed') |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
388 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
389 filepath = Path(parsed.path) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
390 stem = filepath.stem |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
391 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
392 if step_name is None: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
393 # we use this name to easily ignore cache (with stem) while avoiding |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
394 # conflict if we have 2 URLs with the same stem |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
395 step_name = f"{stem}__{url}" |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
396 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
397 if step_message is None: |
139
d36a68e396d5
flatpak: set appdata release version for dev version:
Goffi <goffi@goffi.org>
parents:
138
diff
changeset
|
398 step_message = f"generating module for {stem}" |
138
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
399 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
400 print_step(step_message) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
401 cache = get_cache(step_name) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
402 if cache is not None: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
403 return cache |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
404 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
405 r = requests.get(url) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
406 r.raise_for_status() |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
407 file_hash = hashlib.sha256(r.content).hexdigest() |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
408 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
409 dep_data = {"name": stem} |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
410 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
411 if dest is not None: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
412 dest = Path(dest) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
413 dep_data.update({ |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
414 'buildsystem': 'simple', |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
415 'build-commands':[ |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
416 f'mkdir -p {dest.parent}', |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
417 f'mv "{filepath.name}" "{dest}"', |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
418 ] |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
419 }) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
420 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
421 dep_data['sources'] = [ |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
422 { |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
423 "type": "file", |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
424 "url": url, |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
425 "sha256": file_hash, |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
426 } |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
427 ] |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
428 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
429 data = [dep_data] |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
430 set_cache(step_name, data) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
431 return data |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
432 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
433 |
161
4fe61dcd856e
flatpak: update build-manifest to retrieve dependencies without initial download phase:
Goffi <goffi@goffi.org>
parents:
157
diff
changeset
|
434 def get_requirements(pip, package_name, done=None, requirements=None, tree=None, indent=0): |
138
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
435 """Retrieve requirements for an installed python package |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
436 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
437 @param pip(Path): path to pip executable to use |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
438 package must be installed in the environment of this pip |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
439 @param package_name(str): name of the package to retrieve |
161
4fe61dcd856e
flatpak: update build-manifest to retrieve dependencies without initial download phase:
Goffi <goffi@goffi.org>
parents:
157
diff
changeset
|
440 @return(list[(str,str)]): list of ordered requirements (package_name, version) |
138
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
441 """ |
161
4fe61dcd856e
flatpak: update build-manifest to retrieve dependencies without initial download phase:
Goffi <goffi@goffi.org>
parents:
157
diff
changeset
|
442 print(f"found dependency: {package_name}") |
4fe61dcd856e
flatpak: update build-manifest to retrieve dependencies without initial download phase:
Goffi <goffi@goffi.org>
parents:
157
diff
changeset
|
443 if requirements is None: |
4fe61dcd856e
flatpak: update build-manifest to retrieve dependencies without initial download phase:
Goffi <goffi@goffi.org>
parents:
157
diff
changeset
|
444 assert done is None |
4fe61dcd856e
flatpak: update build-manifest to retrieve dependencies without initial download phase:
Goffi <goffi@goffi.org>
parents:
157
diff
changeset
|
445 assert tree is None |
4fe61dcd856e
flatpak: update build-manifest to retrieve dependencies without initial download phase:
Goffi <goffi@goffi.org>
parents:
157
diff
changeset
|
446 if not package_name == canonical(package_name): |
4fe61dcd856e
flatpak: update build-manifest to retrieve dependencies without initial download phase:
Goffi <goffi@goffi.org>
parents:
157
diff
changeset
|
447 raise ValueError("main package name is not canonical") |
4fe61dcd856e
flatpak: update build-manifest to retrieve dependencies without initial download phase:
Goffi <goffi@goffi.org>
parents:
157
diff
changeset
|
448 tree = [] |
4fe61dcd856e
flatpak: update build-manifest to retrieve dependencies without initial download phase:
Goffi <goffi@goffi.org>
parents:
157
diff
changeset
|
449 requirements = [] |
4fe61dcd856e
flatpak: update build-manifest to retrieve dependencies without initial download phase:
Goffi <goffi@goffi.org>
parents:
157
diff
changeset
|
450 done = [] |
4fe61dcd856e
flatpak: update build-manifest to retrieve dependencies without initial download phase:
Goffi <goffi@goffi.org>
parents:
157
diff
changeset
|
451 main = True |
4fe61dcd856e
flatpak: update build-manifest to retrieve dependencies without initial download phase:
Goffi <goffi@goffi.org>
parents:
157
diff
changeset
|
452 else: |
4fe61dcd856e
flatpak: update build-manifest to retrieve dependencies without initial download phase:
Goffi <goffi@goffi.org>
parents:
157
diff
changeset
|
453 main = False |
4fe61dcd856e
flatpak: update build-manifest to retrieve dependencies without initial download phase:
Goffi <goffi@goffi.org>
parents:
157
diff
changeset
|
454 done.append(package_name) |
138
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
455 show_cplted = subprocess.run([pip, "show", package_name], |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
456 capture_output=True, text=True) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
457 show_cplted.check_returncode() |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
458 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
459 lines = show_cplted.stdout.split('\n') |
161
4fe61dcd856e
flatpak: update build-manifest to retrieve dependencies without initial download phase:
Goffi <goffi@goffi.org>
parents:
157
diff
changeset
|
460 version_raw = next(l for l in lines if l.startswith(SHOW_VERSION_HEADER)) |
4fe61dcd856e
flatpak: update build-manifest to retrieve dependencies without initial download phase:
Goffi <goffi@goffi.org>
parents:
157
diff
changeset
|
461 version = version_raw[len(SHOW_VERSION_HEADER):] |
138
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
462 requirement_raw = next(l for l in lines if l.startswith(SHOW_REQUIRES_HEADER)) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
463 requirement_raw = requirement_raw[len(SHOW_REQUIRES_HEADER):] |
161
4fe61dcd856e
flatpak: update build-manifest to retrieve dependencies without initial download phase:
Goffi <goffi@goffi.org>
parents:
157
diff
changeset
|
464 requirements_canon = [canonical(p) for p in requirement_raw.split(',') if p.strip()] |
138
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
465 requirements_update = [ |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
466 canonical(r) for r in PYTHON_DEP_REQUIREMENTS_UPDATE.get(package_name, [])] |
161
4fe61dcd856e
flatpak: update build-manifest to retrieve dependencies without initial download phase:
Goffi <goffi@goffi.org>
parents:
157
diff
changeset
|
467 new_requirements = set(requirements_update).difference(requirements_canon) |
138
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
468 if new_requirements: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
469 print("adding extra requirements to {}: {}".format( |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
470 package_name, ', '.join(new_requirements))) |
161
4fe61dcd856e
flatpak: update build-manifest to retrieve dependencies without initial download phase:
Goffi <goffi@goffi.org>
parents:
157
diff
changeset
|
471 requirements_canon.extend(new_requirements) |
4fe61dcd856e
flatpak: update build-manifest to retrieve dependencies without initial download phase:
Goffi <goffi@goffi.org>
parents:
157
diff
changeset
|
472 tree.append(f"{' '*indent}{package_name} ({version})") |
4fe61dcd856e
flatpak: update build-manifest to retrieve dependencies without initial download phase:
Goffi <goffi@goffi.org>
parents:
157
diff
changeset
|
473 for r in requirements_canon: |
4fe61dcd856e
flatpak: update build-manifest to retrieve dependencies without initial download phase:
Goffi <goffi@goffi.org>
parents:
157
diff
changeset
|
474 if r not in done: |
4fe61dcd856e
flatpak: update build-manifest to retrieve dependencies without initial download phase:
Goffi <goffi@goffi.org>
parents:
157
diff
changeset
|
475 get_requirements(pip, r, done, requirements, tree, indent+1) |
4fe61dcd856e
flatpak: update build-manifest to retrieve dependencies without initial download phase:
Goffi <goffi@goffi.org>
parents:
157
diff
changeset
|
476 req_tuple = (package_name, version, requirements_canon) |
4fe61dcd856e
flatpak: update build-manifest to retrieve dependencies without initial download phase:
Goffi <goffi@goffi.org>
parents:
157
diff
changeset
|
477 requirements.append(req_tuple) |
4fe61dcd856e
flatpak: update build-manifest to retrieve dependencies without initial download phase:
Goffi <goffi@goffi.org>
parents:
157
diff
changeset
|
478 if main: |
4fe61dcd856e
flatpak: update build-manifest to retrieve dependencies without initial download phase:
Goffi <goffi@goffi.org>
parents:
157
diff
changeset
|
479 print("\ndependency tree:\n") |
4fe61dcd856e
flatpak: update build-manifest to retrieve dependencies without initial download phase:
Goffi <goffi@goffi.org>
parents:
157
diff
changeset
|
480 print('\n'.join(tree)) |
138
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
481 return requirements |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
482 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
483 |
139
d36a68e396d5
flatpak: set appdata release version for dev version:
Goffi <goffi@goffi.org>
parents:
138
diff
changeset
|
484 def get_hg_id_date(path): |
d36a68e396d5
flatpak: set appdata release version for dev version:
Goffi <goffi@goffi.org>
parents:
138
diff
changeset
|
485 """Get short identifier and date of current commit from given Mercurial repository |
d36a68e396d5
flatpak: set appdata release version for dev version:
Goffi <goffi@goffi.org>
parents:
138
diff
changeset
|
486 |
d36a68e396d5
flatpak: set appdata release version for dev version:
Goffi <goffi@goffi.org>
parents:
138
diff
changeset
|
487 version is retrieve with `hg id`, a "+" is appended after shortrev if it has |
d36a68e396d5
flatpak: set appdata release version for dev version:
Goffi <goffi@goffi.org>
parents:
138
diff
changeset
|
488 been modified. |
d36a68e396d5
flatpak: set appdata release version for dev version:
Goffi <goffi@goffi.org>
parents:
138
diff
changeset
|
489 @param path(str, Path): path to the repository |
d36a68e396d5
flatpak: set appdata release version for dev version:
Goffi <goffi@goffi.org>
parents:
138
diff
changeset
|
490 @return(tuple(str, date)): found revision + iso date |
d36a68e396d5
flatpak: set appdata release version for dev version:
Goffi <goffi@goffi.org>
parents:
138
diff
changeset
|
491 """ |
d36a68e396d5
flatpak: set appdata release version for dev version:
Goffi <goffi@goffi.org>
parents:
138
diff
changeset
|
492 hg_cplted = subprocess.run( |
d36a68e396d5
flatpak: set appdata release version for dev version:
Goffi <goffi@goffi.org>
parents:
138
diff
changeset
|
493 ["hg", "id", "--template", "{id|short}{dirty}\n{date|isodate}", path], |
d36a68e396d5
flatpak: set appdata release version for dev version:
Goffi <goffi@goffi.org>
parents:
138
diff
changeset
|
494 capture_output=True, text=True) |
d36a68e396d5
flatpak: set appdata release version for dev version:
Goffi <goffi@goffi.org>
parents:
138
diff
changeset
|
495 hg_cplted.check_returncode() |
d36a68e396d5
flatpak: set appdata release version for dev version:
Goffi <goffi@goffi.org>
parents:
138
diff
changeset
|
496 return hg_cplted.stdout.split('\n') |
d36a68e396d5
flatpak: set appdata release version for dev version:
Goffi <goffi@goffi.org>
parents:
138
diff
changeset
|
497 |
d36a68e396d5
flatpak: set appdata release version for dev version:
Goffi <goffi@goffi.org>
parents:
138
diff
changeset
|
498 |
138
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
499 def get_cache_dir(): |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
500 """Return path to directory to use for cache""" |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
501 return Path(f"cache_{app_id}") |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
502 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
503 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
504 def canonical(name): |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
505 """Get canonical name of a package""" |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
506 return name.lower().replace('_', '-').strip() |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
507 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
508 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
509 modules = [] |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
510 cache_path = Path.home() / Path('.cache/sat_flatpak_cache.json') |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
511 if not cache_path.exists(): |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
512 cache = {} |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
513 else: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
514 with cache_path.open() as f: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
515 cache = json.load(f) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
516 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
517 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
518 ## steps ## |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
519 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
520 def get_libxslt(): |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
521 """Generate manifest module to install libxslt (needed for lxml)""" |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
522 step_name = 'libxslt' |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
523 print_step("retrieving latest version of libxslt") |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
524 cache = get_cache(step_name) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
525 if cache is not None: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
526 return cache |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
527 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
528 ftp = FTP("xmlsoft.org") |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
529 ftp.login() |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
530 ftp.cwd("libxml2") |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
531 libxslt_archives = [l for l in ftp.nlst() if 'xslt' in l |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
532 and l.endswith('tar.gz') |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
533 and 'git' not in l |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
534 and 'rc' not in l] |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
535 latest_libxslt = libxslt_archives[-1] |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
536 print(f"latest libxslt found: {latest_libxslt}") |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
537 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
538 with tempfile.TemporaryDirectory() as tmp_dirname: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
539 tmp_dir = Path(tmp_dirname) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
540 file_path = tmp_dir / latest_libxslt |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
541 with file_path.open('wb+') as f: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
542 ftp.retrbinary('RETR ' + latest_libxslt, f.write) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
543 f.seek(0) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
544 libxslt_hash = hashlib.sha256(f.read()).hexdigest() |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
545 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
546 ftp.quit() |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
547 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
548 print(f"libxstl hash: {libxslt_hash}") |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
549 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
550 data = [{ |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
551 "name": "libxslt", |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
552 "sources": [ |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
553 { |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
554 "type": "archive", |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
555 "url": f"ftp://xmlsoft.org/libxml2/{latest_libxslt}", |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
556 "sha256": libxslt_hash, |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
557 } |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
558 ] |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
559 }] |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
560 set_cache(step_name, data) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
561 return data |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
562 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
563 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
564 def get_python_deps(): |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
565 """Generate manifest modules for python dependencies of main package""" |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
566 step_name = f'python_deps__{app_id}' |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
567 print_step("retrieving python dependencies") |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
568 cache = get_cache(step_name) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
569 if cache is not None: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
570 return cache |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
571 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
572 with tempfile.TemporaryDirectory() as tmp_dirname: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
573 if args.deps_dir is not None: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
574 # we ignore the created temporary directory is we have an other one specified |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
575 tmp_dirname = args.deps_dir |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
576 tmp_dir = Path(tmp_dirname) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
577 env_dir = tmp_dir / 'env' |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
578 pip = env_dir / 'bin' / 'pip' |
161
4fe61dcd856e
flatpak: update build-manifest to retrieve dependencies without initial download phase:
Goffi <goffi@goffi.org>
parents:
157
diff
changeset
|
579 if env_dir.exists(): |
4fe61dcd856e
flatpak: update build-manifest to retrieve dependencies without initial download phase:
Goffi <goffi@goffi.org>
parents:
157
diff
changeset
|
580 print("packages are already installed") |
138
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
581 else: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
582 print(f"working in temporary directory {tmp_dirname}") |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
583 venv_cplted = subprocess.run(["/usr/bin/env", "virtualenv2", env_dir]) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
584 venv_cplted.check_returncode() |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
585 print("\ninstalling package\n") |
161
4fe61dcd856e
flatpak: update build-manifest to retrieve dependencies without initial download phase:
Goffi <goffi@goffi.org>
parents:
157
diff
changeset
|
586 if PYTHON_DEP_PREINSTALL: |
4fe61dcd856e
flatpak: update build-manifest to retrieve dependencies without initial download phase:
Goffi <goffi@goffi.org>
parents:
157
diff
changeset
|
587 print("preinstalling packages") |
4fe61dcd856e
flatpak: update build-manifest to retrieve dependencies without initial download phase:
Goffi <goffi@goffi.org>
parents:
157
diff
changeset
|
588 for dep in PYTHON_DEP_PREINSTALL: |
4fe61dcd856e
flatpak: update build-manifest to retrieve dependencies without initial download phase:
Goffi <goffi@goffi.org>
parents:
157
diff
changeset
|
589 inst_cplted = subprocess.run([pip, "install", dep]) |
4fe61dcd856e
flatpak: update build-manifest to retrieve dependencies without initial download phase:
Goffi <goffi@goffi.org>
parents:
157
diff
changeset
|
590 inst_cplted.check_returncode() |
4fe61dcd856e
flatpak: update build-manifest to retrieve dependencies without initial download phase:
Goffi <goffi@goffi.org>
parents:
157
diff
changeset
|
591 |
138
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
592 # we install package to have a good map of requirements, pypi metadata |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
593 # are incomplete. Packages should be retrieved from pip cache |
161
4fe61dcd856e
flatpak: update build-manifest to retrieve dependencies without initial download phase:
Goffi <goffi@goffi.org>
parents:
157
diff
changeset
|
594 inst_cplted = subprocess.run( |
4fe61dcd856e
flatpak: update build-manifest to retrieve dependencies without initial download phase:
Goffi <goffi@goffi.org>
parents:
157
diff
changeset
|
595 [pip, "install", "--progress-bar", "emoji", main_package_source]) |
138
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
596 inst_cplted.check_returncode() |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
597 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
598 print_step("analyzing python dependencies") |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
599 deps_map = {} |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
600 |
161
4fe61dcd856e
flatpak: update build-manifest to retrieve dependencies without initial download phase:
Goffi <goffi@goffi.org>
parents:
157
diff
changeset
|
601 requirements = get_requirements(pip, main_package) |
4fe61dcd856e
flatpak: update build-manifest to retrieve dependencies without initial download phase:
Goffi <goffi@goffi.org>
parents:
157
diff
changeset
|
602 |
4fe61dcd856e
flatpak: update build-manifest to retrieve dependencies without initial download phase:
Goffi <goffi@goffi.org>
parents:
157
diff
changeset
|
603 |
4fe61dcd856e
flatpak: update build-manifest to retrieve dependencies without initial download phase:
Goffi <goffi@goffi.org>
parents:
157
diff
changeset
|
604 print("\nretrieveing metadata on PyPi\n") |
4fe61dcd856e
flatpak: update build-manifest to retrieve dependencies without initial download phase:
Goffi <goffi@goffi.org>
parents:
157
diff
changeset
|
605 |
4fe61dcd856e
flatpak: update build-manifest to retrieve dependencies without initial download phase:
Goffi <goffi@goffi.org>
parents:
157
diff
changeset
|
606 if not args.no_binary: |
4fe61dcd856e
flatpak: update build-manifest to retrieve dependencies without initial download phase:
Goffi <goffi@goffi.org>
parents:
157
diff
changeset
|
607 print(r"/!\ retrieving binary packages is not currently supported") |
4fe61dcd856e
flatpak: update build-manifest to retrieve dependencies without initial download phase:
Goffi <goffi@goffi.org>
parents:
157
diff
changeset
|
608 |
4fe61dcd856e
flatpak: update build-manifest to retrieve dependencies without initial download phase:
Goffi <goffi@goffi.org>
parents:
157
diff
changeset
|
609 deps = [] |
4fe61dcd856e
flatpak: update build-manifest to retrieve dependencies without initial download phase:
Goffi <goffi@goffi.org>
parents:
157
diff
changeset
|
610 for name, version, pkg_requirements in requirements: |
4fe61dcd856e
flatpak: update build-manifest to retrieve dependencies without initial download phase:
Goffi <goffi@goffi.org>
parents:
157
diff
changeset
|
611 print(f"{name}: ", end='') |
138
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
612 r = requests.get(f"https://pypi.org/pypi/{name}/{version}/json") |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
613 r.raise_for_status() |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
614 dep_json = r.json() |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
615 release_json = dep_json["releases"][version] |
161
4fe61dcd856e
flatpak: update build-manifest to retrieve dependencies without initial download phase:
Goffi <goffi@goffi.org>
parents:
157
diff
changeset
|
616 source_release = next(r for r in release_json if r['packagetype'] == 'sdist') |
4fe61dcd856e
flatpak: update build-manifest to retrieve dependencies without initial download phase:
Goffi <goffi@goffi.org>
parents:
157
diff
changeset
|
617 dep_hash = source_release['digests']['sha256'] |
4fe61dcd856e
flatpak: update build-manifest to retrieve dependencies without initial download phase:
Goffi <goffi@goffi.org>
parents:
157
diff
changeset
|
618 url = source_release['url'] |
4fe61dcd856e
flatpak: update build-manifest to retrieve dependencies without initial download phase:
Goffi <goffi@goffi.org>
parents:
157
diff
changeset
|
619 dep = Package(name=name, |
138
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
620 version=version, |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
621 hash_=dep_hash, |
161
4fe61dcd856e
flatpak: update build-manifest to retrieve dependencies without initial download phase:
Goffi <goffi@goffi.org>
parents:
157
diff
changeset
|
622 url=url, |
4fe61dcd856e
flatpak: update build-manifest to retrieve dependencies without initial download phase:
Goffi <goffi@goffi.org>
parents:
157
diff
changeset
|
623 requirements=pkg_requirements, |
138
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
624 ) |
161
4fe61dcd856e
flatpak: update build-manifest to retrieve dependencies without initial download phase:
Goffi <goffi@goffi.org>
parents:
157
diff
changeset
|
625 deps.append(dep) |
4fe61dcd856e
flatpak: update build-manifest to retrieve dependencies without initial download phase:
Goffi <goffi@goffi.org>
parents:
157
diff
changeset
|
626 deps_map[name] = dep |
4fe61dcd856e
flatpak: update build-manifest to retrieve dependencies without initial download phase:
Goffi <goffi@goffi.org>
parents:
157
diff
changeset
|
627 print(f"version: {version}, type: {source_release['packagetype']}") |
138
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
628 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
629 # we remove deps already installed with PYTHON_SETUP_REQUIREMENTS |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
630 for name in PYTHON_SETUP_REQUIREMENTS: |
161
4fe61dcd856e
flatpak: update build-manifest to retrieve dependencies without initial download phase:
Goffi <goffi@goffi.org>
parents:
157
diff
changeset
|
631 if not isinstance(name, str): |
4fe61dcd856e
flatpak: update build-manifest to retrieve dependencies without initial download phase:
Goffi <goffi@goffi.org>
parents:
157
diff
changeset
|
632 # this is a package with version in a list, first item is the name |
4fe61dcd856e
flatpak: update build-manifest to retrieve dependencies without initial download phase:
Goffi <goffi@goffi.org>
parents:
157
diff
changeset
|
633 name = name[0] |
138
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
634 package_data = deps_map.get(name) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
635 if package_data is not None: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
636 deps.remove(package_data) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
637 print(f"removed {name} which is already a setup requirement") |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
638 |
161
4fe61dcd856e
flatpak: update build-manifest to retrieve dependencies without initial download phase:
Goffi <goffi@goffi.org>
parents:
157
diff
changeset
|
639 # main package is installed at the end of the manifest |
4fe61dcd856e
flatpak: update build-manifest to retrieve dependencies without initial download phase:
Goffi <goffi@goffi.org>
parents:
157
diff
changeset
|
640 # so we remove it (it is the last package in deps) |
4fe61dcd856e
flatpak: update build-manifest to retrieve dependencies without initial download phase:
Goffi <goffi@goffi.org>
parents:
157
diff
changeset
|
641 main_pack = deps.pop() |
4fe61dcd856e
flatpak: update build-manifest to retrieve dependencies without initial download phase:
Goffi <goffi@goffi.org>
parents:
157
diff
changeset
|
642 assert main_pack.name == main_package |
138
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
643 |
161
4fe61dcd856e
flatpak: update build-manifest to retrieve dependencies without initial download phase:
Goffi <goffi@goffi.org>
parents:
157
diff
changeset
|
644 print("\nwe now generate modules for python dependencies\n") |
138
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
645 data = [] |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
646 version_force = { |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
647 canonical(n): v |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
648 for n,v in build_settings.get('python_deps_version_force', {}).items() |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
649 } |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
650 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
651 for dep in deps: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
652 version_forced = version_force.get(dep.name) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
653 if version_forced == 'pre-release': |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
654 print(f"using pre-release version for {dep.name} as requested in build " |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
655 "settings") |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
656 dep_data = get_python_package(dep.name, step_message='', with_pre=True)[0] |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
657 elif version_forced is not None: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
658 print(f"using version {version_forced} for {dep.name} as requested in " |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
659 "build settings") |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
660 dep_data = get_python_package(dep.name, step_message='', |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
661 version=version_forced)[0] |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
662 else: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
663 dep_data = { |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
664 "name": dep.name, |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
665 "buildsystem": "simple", |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
666 "build-commands": [ |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
667 "python2 setup.py install --prefix=${FLATPAK_DEST}" |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
668 ], |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
669 "sources": [ |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
670 { |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
671 "type": "archive", |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
672 "url": dep.url, |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
673 "sha256": dep.hash_, |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
674 } |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
675 ], |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
676 "ensure-writable": [ |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
677 "/lib/python2.7/site-packages/easy-install.pth", |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
678 "/lib/python2.7/site-packages/setuptools.pth", |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
679 ] |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
680 } |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
681 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
682 if dep.name in PYTHON_DEP_OVERRIDE: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
683 print(f"applying override for {dep.name}") |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
684 override = PYTHON_DEP_OVERRIDE[dep.name] |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
685 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
686 # key suffixed with "_extend" won't replace the data |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
687 for key in list(override.keys()): |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
688 if key.endswith('_extend'): |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
689 real_key = key[:-7] |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
690 extend_data = override.pop(key) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
691 if real_key == 'sources': |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
692 for item_data in extend_data: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
693 # we look for missing hashes and add them |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
694 if (item_data.get('type') in ('file', 'patch') |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
695 and 'sha256' not in item_data): |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
696 with open(item_data['path'], 'rb') as f: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
697 hash_ = hashlib.sha256(f.read()).hexdigest() |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
698 item_data['sha256'] = hash_ |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
699 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
700 dep_data.setdefault(real_key, []).extend(extend_data) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
701 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
702 dep_data.update(override) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
703 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
704 data.append(dep_data) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
705 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
706 set_cache(step_name, data) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
707 return data |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
708 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
709 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
710 def cache_from_repos(): |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
711 """Get and cache locally a repository and returns cache path""" |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
712 print_step("retrieving code from repository") |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
713 dev_repos = build_settings['dev_repos'] |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
714 repos_type = dev_repos.get('type', 'hg') |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
715 if repos_type != 'hg': |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
716 raise NotImplementedError("only Mercurial is managed so far") |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
717 url = dev_repos['url'] |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
718 dest_path = get_cache_dir() / main_package |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
719 dest_path.mkdir(parents=True, exist_ok=True) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
720 if (dest_path / '.hg').is_dir(): |
156
0a92bb60db12
flatpak (build_manifest): Mercurial repository is now updated if it is already cloned
Goffi <goffi@goffi.org>
parents:
155
diff
changeset
|
721 print("code is already in cache, updating") |
0a92bb60db12
flatpak (build_manifest): Mercurial repository is now updated if it is already cloned
Goffi <goffi@goffi.org>
parents:
155
diff
changeset
|
722 hg_cplted = subprocess.run(["hg", "pull", "-u", "--cwd", dest_path]) |
0a92bb60db12
flatpak (build_manifest): Mercurial repository is now updated if it is already cloned
Goffi <goffi@goffi.org>
parents:
155
diff
changeset
|
723 hg_cplted.check_returncode() |
138
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
724 else: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
725 try: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
726 print(f"retrieving code from repository {url} into {dest_path}") |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
727 hg_cplted = subprocess.run(["hg", "clone", url, dest_path]) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
728 hg_cplted.check_returncode() |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
729 except Exception as e: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
730 shutil.rmtree(dest_path) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
731 raise e |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
732 return dest_path |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
733 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
734 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
735 def get_repos_module(): |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
736 """Generate manifest module for the repository""" |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
737 dep_data = { |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
738 "name": main_package, |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
739 "buildsystem": "simple", |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
740 "build-commands": [ |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
741 "python2 setup.py install --prefix=${FLATPAK_DEST}" |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
742 ], |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
743 "sources": [ |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
744 { |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
745 "type": "dir", |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
746 "path": str(main_package_source) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
747 } |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
748 ], |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
749 "ensure-writable": [ |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
750 "/lib/python2.7/site-packages/easy-install.pth", |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
751 "/lib/python2.7/site-packages/setuptools.pth", |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
752 ] |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
753 } |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
754 return [dep_data] |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
755 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
756 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
757 def get_sat_media(): |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
758 """Generate module for last version of sat_media available on the FTP""" |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
759 step_name = 'sat_media' |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
760 print_step("retrieving latest version of sat_media") |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
761 cache = get_cache(step_name) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
762 if cache is not None: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
763 return cache |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
764 url = "https://ftp.goffi.org/sat_media/sat_media.tar.bz2" |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
765 r = requests.get(url) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
766 r.raise_for_status() |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
767 hash_ = hashlib.sha256(r.content).hexdigest() |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
768 dep_data = { |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
769 "name": "sat-media", |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
770 "buildsystem": "simple", |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
771 "build-commands": [ |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
772 "cp -vr . ${FLATPAK_DEST}/share/sat-media" |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
773 ], |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
774 "sources": [ |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
775 { |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
776 "type": "archive", |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
777 "url": url, |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
778 "sha256": hash_, |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
779 } |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
780 ], |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
781 } |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
782 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
783 data = [dep_data] |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
784 set_cache(step_name, data) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
785 return data |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
786 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
787 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
788 def get_icon(): |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
789 icon = build_settings.get('icon') |
145
9201caf7b2a8
flatpak (build_manifest): don't crash if icon is not specified
Goffi <goffi@goffi.org>
parents:
140
diff
changeset
|
790 if icon is None: |
9201caf7b2a8
flatpak (build_manifest): don't crash if icon is not specified
Goffi <goffi@goffi.org>
parents:
140
diff
changeset
|
791 return [] |
9201caf7b2a8
flatpak (build_manifest): don't crash if icon is not specified
Goffi <goffi@goffi.org>
parents:
140
diff
changeset
|
792 else: |
138
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
793 if isinstance(icon, str): |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
794 icon = {'url': icon} |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
795 icon_path = Path(urlparse(icon['url']).path) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
796 suffix = icon_path.suffix[1:] |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
797 if suffix not in ('svg', 'png'): |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
798 raise ValueError("invalid icon, you must use a SVG or PNG image!") |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
799 if 'size' not in icon: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
800 if suffix == 'svg': |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
801 icon['size'] = 'scalable' |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
802 else: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
803 raise ValueError('icon size is not specified, please add a "size" key') |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
804 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
805 dest_path = f"/app/share/icons/hicolor/{icon['size']}/apps/{app_id}.{suffix}" |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
806 |
145
9201caf7b2a8
flatpak (build_manifest): don't crash if icon is not specified
Goffi <goffi@goffi.org>
parents:
140
diff
changeset
|
807 data = file_from_url( |
138
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
808 url = icon['url'], |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
809 dest = dest_path, |
150
10adfa3f9552
flatpak (build_manifest): icon names depends of app_id, so set cache to be dependant of app_id
Goffi <goffi@goffi.org>
parents:
146
diff
changeset
|
810 step_name = f"icon__{app_id}", |
138
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
811 step_message = "retrieving application icon", |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
812 ) |
145
9201caf7b2a8
flatpak (build_manifest): don't crash if icon is not specified
Goffi <goffi@goffi.org>
parents:
140
diff
changeset
|
813 data[0]['name'] = 'icon' |
9201caf7b2a8
flatpak (build_manifest): don't crash if icon is not specified
Goffi <goffi@goffi.org>
parents:
140
diff
changeset
|
814 return data |
138
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
815 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
816 |
139
d36a68e396d5
flatpak: set appdata release version for dev version:
Goffi <goffi@goffi.org>
parents:
138
diff
changeset
|
817 def generate_appdata_from_template(template_file): |
d36a68e396d5
flatpak: set appdata release version for dev version:
Goffi <goffi@goffi.org>
parents:
138
diff
changeset
|
818 appdata_file = Path(f"{app_id}.appdata.xml") |
d36a68e396d5
flatpak: set appdata release version for dev version:
Goffi <goffi@goffi.org>
parents:
138
diff
changeset
|
819 if appdata_file.exists() and not args.force: |
d36a68e396d5
flatpak: set appdata release version for dev version:
Goffi <goffi@goffi.org>
parents:
138
diff
changeset
|
820 confirm = input(OVERWRITE_WARNING.format(appdata_file)) |
d36a68e396d5
flatpak: set appdata release version for dev version:
Goffi <goffi@goffi.org>
parents:
138
diff
changeset
|
821 if confirm != 'y': |
d36a68e396d5
flatpak: set appdata release version for dev version:
Goffi <goffi@goffi.org>
parents:
138
diff
changeset
|
822 print("manifest building cancelled") |
d36a68e396d5
flatpak: set appdata release version for dev version:
Goffi <goffi@goffi.org>
parents:
138
diff
changeset
|
823 sys.exit(0) |
d36a68e396d5
flatpak: set appdata release version for dev version:
Goffi <goffi@goffi.org>
parents:
138
diff
changeset
|
824 parser = etree.XMLParser(remove_blank_text=True) |
d36a68e396d5
flatpak: set appdata release version for dev version:
Goffi <goffi@goffi.org>
parents:
138
diff
changeset
|
825 tree = etree.parse(template_file, parser) |
d36a68e396d5
flatpak: set appdata release version for dev version:
Goffi <goffi@goffi.org>
parents:
138
diff
changeset
|
826 root = tree.getroot() |
d36a68e396d5
flatpak: set appdata release version for dev version:
Goffi <goffi@goffi.org>
parents:
138
diff
changeset
|
827 if args.version == 'dev': |
140
e23e414987d7
flatpak (build_manifest): --no-binary is currently disabled as version parsing doesn't handle yet wheel packages.
Goffi <goffi@goffi.org>
parents:
139
diff
changeset
|
828 print(f"addind release data for dev version ({dev_version_rev})") |
139
d36a68e396d5
flatpak: set appdata release version for dev version:
Goffi <goffi@goffi.org>
parents:
138
diff
changeset
|
829 releases_elt = root.find('releases') |
d36a68e396d5
flatpak: set appdata release version for dev version:
Goffi <goffi@goffi.org>
parents:
138
diff
changeset
|
830 if releases_elt is None: |
d36a68e396d5
flatpak: set appdata release version for dev version:
Goffi <goffi@goffi.org>
parents:
138
diff
changeset
|
831 raise ValueError( |
d36a68e396d5
flatpak: set appdata release version for dev version:
Goffi <goffi@goffi.org>
parents:
138
diff
changeset
|
832 "<releases/> element is missing in appdata template, please add it") |
161
4fe61dcd856e
flatpak: update build-manifest to retrieve dependencies without initial download phase:
Goffi <goffi@goffi.org>
parents:
157
diff
changeset
|
833 release_elt = etree.Element( |
139
d36a68e396d5
flatpak: set appdata release version for dev version:
Goffi <goffi@goffi.org>
parents:
138
diff
changeset
|
834 "release", |
d36a68e396d5
flatpak: set appdata release version for dev version:
Goffi <goffi@goffi.org>
parents:
138
diff
changeset
|
835 {'type': 'development', |
d36a68e396d5
flatpak: set appdata release version for dev version:
Goffi <goffi@goffi.org>
parents:
138
diff
changeset
|
836 'version': dev_version_rev, |
d36a68e396d5
flatpak: set appdata release version for dev version:
Goffi <goffi@goffi.org>
parents:
138
diff
changeset
|
837 'date': dev_version_date}, |
d36a68e396d5
flatpak: set appdata release version for dev version:
Goffi <goffi@goffi.org>
parents:
138
diff
changeset
|
838 ) |
161
4fe61dcd856e
flatpak: update build-manifest to retrieve dependencies without initial download phase:
Goffi <goffi@goffi.org>
parents:
157
diff
changeset
|
839 releases_elt.insert(0, release_elt) |
139
d36a68e396d5
flatpak: set appdata release version for dev version:
Goffi <goffi@goffi.org>
parents:
138
diff
changeset
|
840 description_elt = etree.SubElement(release_elt, 'description') |
d36a68e396d5
flatpak: set appdata release version for dev version:
Goffi <goffi@goffi.org>
parents:
138
diff
changeset
|
841 text_lines = APPDATA_RELEASE_DEV_TEXT.strip().split('\n') |
d36a68e396d5
flatpak: set appdata release version for dev version:
Goffi <goffi@goffi.org>
parents:
138
diff
changeset
|
842 for text in text_lines: |
d36a68e396d5
flatpak: set appdata release version for dev version:
Goffi <goffi@goffi.org>
parents:
138
diff
changeset
|
843 etree.SubElement(description_elt, 'p').text = text |
d36a68e396d5
flatpak: set appdata release version for dev version:
Goffi <goffi@goffi.org>
parents:
138
diff
changeset
|
844 |
d36a68e396d5
flatpak: set appdata release version for dev version:
Goffi <goffi@goffi.org>
parents:
138
diff
changeset
|
845 with open(appdata_file, "wb") as f: |
d36a68e396d5
flatpak: set appdata release version for dev version:
Goffi <goffi@goffi.org>
parents:
138
diff
changeset
|
846 f.write(etree.tostring(root, encoding="utf-8", xml_declaration=True, |
d36a68e396d5
flatpak: set appdata release version for dev version:
Goffi <goffi@goffi.org>
parents:
138
diff
changeset
|
847 pretty_print=True)) |
d36a68e396d5
flatpak: set appdata release version for dev version:
Goffi <goffi@goffi.org>
parents:
138
diff
changeset
|
848 |
d36a68e396d5
flatpak: set appdata release version for dev version:
Goffi <goffi@goffi.org>
parents:
138
diff
changeset
|
849 return appdata_file.as_posix() |
d36a68e396d5
flatpak: set appdata release version for dev version:
Goffi <goffi@goffi.org>
parents:
138
diff
changeset
|
850 |
d36a68e396d5
flatpak: set appdata release version for dev version:
Goffi <goffi@goffi.org>
parents:
138
diff
changeset
|
851 |
138
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
852 def get_app_metadata(): |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
853 desktop_file = build_settings.get('desktop_file') |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
854 appdata_file = build_settings.get('appdata_file') |
139
d36a68e396d5
flatpak: set appdata release version for dev version:
Goffi <goffi@goffi.org>
parents:
138
diff
changeset
|
855 if desktop_file is None and appdata_file is None: |
138
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
856 return |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
857 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
858 print_step("retrieving application metadata") |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
859 # we don't use cache here to be sure to have always up-to-date files |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
860 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
861 data = [] |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
862 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
863 if desktop_file is not None: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
864 print("generating module for desktop metadata") |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
865 data.extend(file_upload( |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
866 filename = desktop_file, |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
867 dest=f"/app/share/applications/{app_id}.desktop", |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
868 )) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
869 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
870 if appdata_file is not None: |
139
d36a68e396d5
flatpak: set appdata release version for dev version:
Goffi <goffi@goffi.org>
parents:
138
diff
changeset
|
871 if appdata_file.startswith('_tpl_'): |
d36a68e396d5
flatpak: set appdata release version for dev version:
Goffi <goffi@goffi.org>
parents:
138
diff
changeset
|
872 print("found appdata template, we now use it to generate the file") |
d36a68e396d5
flatpak: set appdata release version for dev version:
Goffi <goffi@goffi.org>
parents:
138
diff
changeset
|
873 appdata_file = generate_appdata_from_template(appdata_file) |
138
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
874 print("generating module for appdata metadata") |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
875 data.extend(file_upload( |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
876 filename = appdata_file, |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
877 dest=f"/app/share/metainfo/{app_id}.appdata.xml", |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
878 )) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
879 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
880 return data |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
881 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
882 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
883 ## main_script ## |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
884 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
885 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
886 if __name__ == '__main__': |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
887 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
888 args = parse_args() |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
889 title = args.name.title() |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
890 app_id = f"org.salutatoi.{title}" |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
891 package_file = Path(f"{app_id}.json") |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
892 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
893 print(f"generating manifest for {app_id} ({args.version})") |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
894 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
895 if package_file.exists() and not args.force: |
139
d36a68e396d5
flatpak: set appdata release version for dev version:
Goffi <goffi@goffi.org>
parents:
138
diff
changeset
|
896 confirm = input(OVERWRITE_WARNING.format(package_file)) |
138
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
897 if confirm != 'y': |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
898 print("manifest building cancelled") |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
899 sys.exit(0) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
900 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
901 tpl_file = Path(f"_tpl_{package_file}") |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
902 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
903 if not tpl_file.exists(): |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
904 raise RuntimeError(f"Can't find template {tpl_file}, it is mandatory to build" |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
905 "the manifest!") |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
906 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
907 with tpl_file.open() as f: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
908 template = json.load(f) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
909 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
910 build_settings = template.pop(SETTINGS_KEY, {}) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
911 if "setup_requirements" in build_settings: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
912 PYTHON_SETUP_REQUIREMENTS.extend(build_settings["setup_requirements"]) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
913 main_package = canonical(build_settings.get('package', args.name)) |
139
d36a68e396d5
flatpak: set appdata release version for dev version:
Goffi <goffi@goffi.org>
parents:
138
diff
changeset
|
914 if args.version == 'dev': |
d36a68e396d5
flatpak: set appdata release version for dev version:
Goffi <goffi@goffi.org>
parents:
138
diff
changeset
|
915 if 'dev_repos' not in build_settings: |
d36a68e396d5
flatpak: set appdata release version for dev version:
Goffi <goffi@goffi.org>
parents:
138
diff
changeset
|
916 raise NotImplementedError( |
d36a68e396d5
flatpak: set appdata release version for dev version:
Goffi <goffi@goffi.org>
parents:
138
diff
changeset
|
917 "dev version can currently only be handled with a dev repostiory " |
d36a68e396d5
flatpak: set appdata release version for dev version:
Goffi <goffi@goffi.org>
parents:
138
diff
changeset
|
918 "(dev_repos)") |
138
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
919 dev_repos = build_settings['dev_repos'] |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
920 main_package_source = cache_from_repos() |
139
d36a68e396d5
flatpak: set appdata release version for dev version:
Goffi <goffi@goffi.org>
parents:
138
diff
changeset
|
921 dev_version_rev, dev_version_date = get_hg_id_date(main_package_source) |
138
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
922 else: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
923 main_package_source = main_package |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
924 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
925 manifest = {} |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
926 manifest['app-id'] = app_id |
161
4fe61dcd856e
flatpak: update build-manifest to retrieve dependencies without initial download phase:
Goffi <goffi@goffi.org>
parents:
157
diff
changeset
|
927 if args.version == 'dev': |
4fe61dcd856e
flatpak: update build-manifest to retrieve dependencies without initial download phase:
Goffi <goffi@goffi.org>
parents:
157
diff
changeset
|
928 manifest['default-branch'] = args.version |
138
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
929 # we update DEFAULT_MANIFEST only now to have "app-id" and "default-branch" on the top |
153
df75b62e653e
flatpak (build_manifest): some fixes needed after runtime update:
Goffi <goffi@goffi.org>
parents:
151
diff
changeset
|
930 # of the manifest, also we don't want modules to be set now |
df75b62e653e
flatpak (build_manifest): some fixes needed after runtime update:
Goffi <goffi@goffi.org>
parents:
151
diff
changeset
|
931 default_modules = DEFAULT_MANIFEST.pop('modules', []) |
138
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
932 manifest.update(DEFAULT_MANIFEST) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
933 manifest.update(template) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
934 |
161
4fe61dcd856e
flatpak: update build-manifest to retrieve dependencies without initial download phase:
Goffi <goffi@goffi.org>
parents:
157
diff
changeset
|
935 # modules.extend(get_libxslt()) |
138
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
936 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
937 # setup requirements |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
938 modules.extend(get_python_package( |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
939 PYTHON_SETUP_REQUIREMENTS, |
146
64c02902b86a
flatpak (build_manifest): fixed setup_requirements step cache by making dependent of app_id
Goffi <goffi@goffi.org>
parents:
145
diff
changeset
|
940 step_name=f"setup_requirements__{app_id}", |
138
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
941 step_message="generating modules for setup requirements") |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
942 ) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
943 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
944 # python dependencies |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
945 modules.extend(get_python_deps()) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
946 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
947 # at this point we add things specified in the template |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
948 modules.extend(manifest.get('modules', [])) |
153
df75b62e653e
flatpak (build_manifest): some fixes needed after runtime update:
Goffi <goffi@goffi.org>
parents:
151
diff
changeset
|
949 modules = default_modules + modules |
138
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
950 manifest['modules'] = modules |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
951 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
952 # sat common things |
161
4fe61dcd856e
flatpak: update build-manifest to retrieve dependencies without initial download phase:
Goffi <goffi@goffi.org>
parents:
157
diff
changeset
|
953 existing_modules = {d['name'] for d in modules if not isinstance(d, str)} |
138
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
954 if "sat_templates" not in existing_modules: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
955 modules.extend(get_python_package("sat_templates", with_pre=True)) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
956 modules.extend(get_sat_media()) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
957 modules.extend(file_upload('sat.conf', '/app')) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
958 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
959 # wrapper to launch the backend if needed |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
960 wrapped_command = build_settings.get('wrapped_command') |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
961 if wrapped_command: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
962 modules.extend(file_upload('sat_wrapper', src='sat_wrapper.py', |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
963 replace={'##COMMAND##': wrapped_command}, |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
964 use_install=True)) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
965 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
966 # icon |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
967 modules.extend(get_icon()) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
968 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
969 # desktop file and appdata file |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
970 modules.extend(get_app_metadata()) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
971 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
972 # now the app itself |
139
d36a68e396d5
flatpak: set appdata release version for dev version:
Goffi <goffi@goffi.org>
parents:
138
diff
changeset
|
973 if args.version == 'dev': |
138
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
974 # mercurial is needed for dev version to install but also to |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
975 # retrieve revision used |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
976 modules.extend(get_python_package("mercurial")) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
977 modules.extend(get_repos_module()) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
978 else: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
979 modules.extend(get_python_package(main_package, version=args.version)) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
980 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
981 print_step("writing manifest") |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
982 with package_file.open('w') as f: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
983 json.dump(manifest, f, indent=4) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
984 |
154
cd411b0d1e19
flatpak (build_manifest): fixed ignore-cache when "all" is used
Goffi <goffi@goffi.org>
parents:
153
diff
changeset
|
985 if args.ignore_cache and args.ignore_cache != ['all']: |
138
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
986 print("/!\\ those --ignore-cache arguments don't correspond to any step: {}". |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
987 format(', '.join(args.ignore_cache))) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
988 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
989 print(f"manifest generated successfully at {package_file}") |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
990 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
991 if args.export is not None: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
992 print_step("exporting building files") |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
993 print(f"exporting to {args.export}\n") |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
994 to_export = [ |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
995 ("package file", package_file), |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
996 ] |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
997 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
998 for m in modules: |
161
4fe61dcd856e
flatpak: update build-manifest to retrieve dependencies without initial download phase:
Goffi <goffi@goffi.org>
parents:
157
diff
changeset
|
999 if isinstance(m, str): |
4fe61dcd856e
flatpak: update build-manifest to retrieve dependencies without initial download phase:
Goffi <goffi@goffi.org>
parents:
157
diff
changeset
|
1000 continue |
138
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1001 for s in m.get('sources', []): |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1002 s_type = s.get('type') |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1003 if s_type in ('path', 'file'): |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1004 try: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1005 path = s['path'] |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1006 except KeyError: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1007 if 'url' in s: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1008 continue |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1009 else: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1010 raise ValueError(f"path missing for module source:\n{s}") |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1011 to_export.append((s_type, Path(path))) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1012 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1013 for label, path in to_export: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1014 print(f"exporting {label}: {path}") |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1015 dest = args.export / path |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1016 if dest.exists(): |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1017 if args.force_export: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1018 print(f" replacing existing {dest}") |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1019 if path.is_dir(): |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1020 shutil.rmtree(dest) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1021 else: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1022 dest.unlink() |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1023 else: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1024 print(" it already exists, skipping") |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1025 continue |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1026 if args.symlink == 'all': |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1027 os.symlink(path, dest) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1028 else: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1029 if path.is_dir(): |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1030 shutil.copytree(path, dest) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1031 else: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1032 shutil.copyfile(path, dest) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1033 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1034 if args.version == 'dev': |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1035 print("exporting cache") |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1036 dest = args.export / get_cache_dir() |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1037 if args.force_export and os.path.lexists(dest): |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1038 print(f" replacing existing {dest}") |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1039 if dest.is_symlink(): |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1040 dest.unlink() |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1041 else: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1042 shutil.rmtree(dest) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1043 |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1044 if dest.exists(): |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1045 print(" it already exists, skipping") |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1046 else: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1047 if args.symlink in ('all', 'cache'): |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1048 os.symlink(get_cache_dir().resolve(), dest) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1049 else: |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1050 shutil.copytree(get_cache_dir(), dest) |
274af514a5cf
flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1051 |
161
4fe61dcd856e
flatpak: update build-manifest to retrieve dependencies without initial download phase:
Goffi <goffi@goffi.org>
parents:
157
diff
changeset
|
1052 print("\nexport completed") |