Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
gajim
gajim-plugins
Commits
d2ced8b8
Commit
d2ced8b8
authored
Apr 29, 2022
by
Philipp Hörist
Browse files
Scripts: Add build_repository.py
parent
390218a8
Changes
1
Hide whitespace changes
Inline
Side-by-side
scripts/build_repository.py
0 → 100644
View file @
d2ced8b8
from
typing
import
Any
from
typing
import
Dict
from
typing
import
Iterator
import
sys
import
json
import
logging
from
collections
import
defaultdict
from
pathlib
import
Path
from
zipfile
import
ZipFile
FORMAT
=
'%(asctime)s %(message)s'
logging
.
basicConfig
(
format
=
FORMAT
,
level
=
logging
.
DEBUG
)
log
=
logging
.
getLogger
()
REQUIRED_KEYS
:
set
[
str
]
=
{
'authors'
,
'description'
,
'homepage'
,
'config_dialog'
,
'name'
,
'platforms'
,
'requirements'
,
'short_name'
,
'version'
}
PACKAGE_INDEX
:
dict
[
str
,
Any
]
=
{
'metadata'
:
{
'repository_name'
:
'master'
,
'image_url'
:
'images.zip'
,
},
'plugins'
:
defaultdict
(
dict
)
}
def
is_manifest_valid
(
manifest
:
dict
[
str
,
Any
])
->
bool
:
manifest_keys
=
set
(
manifest
.
keys
())
return
REQUIRED_KEYS
.
issubset
(
manifest_keys
)
def
iter_releases
(
release_folder
:
Path
)
->
Iterator
[
Dict
[
str
,
Any
]]:
for
path
in
release_folder
.
rglob
(
'*.zip'
):
with
ZipFile
(
path
)
as
release_zip
:
try
:
with
release_zip
.
open
(
'manifest.json'
)
as
file
:
manifest
=
json
.
load
(
file
)
yield
manifest
except
Exception
:
log
.
error
(
'Error loading manifest'
)
log
.
exception
(
''
)
def
build_package_index
(
release_folder
:
Path
)
->
None
:
log
.
info
(
'Build package index'
)
for
manifest
in
iter_releases
(
release_folder
):
if
not
is_manifest_valid
(
manifest
):
log
.
warning
(
'Invalid manifest'
)
log
.
warning
(
manifest
)
continue
short_name
=
manifest
.
pop
(
'short_name'
)
version
=
manifest
.
pop
(
'version'
)
PACKAGE_INDEX
[
'plugins'
][
short_name
][
version
]
=
manifest
log
.
info
(
'Found manifest: %s - %s'
,
short_name
,
version
)
path
=
release_folder
/
'package_index.json'
with
path
.
open
(
'w'
)
as
f
:
json
.
dump
(
PACKAGE_INDEX
,
f
)
def
build_image_zip
(
release_folder
:
Path
)
->
None
:
log
.
info
(
'Build images.zip'
)
with
ZipFile
(
release_folder
/
'images.zip'
,
mode
=
'w'
)
as
image_zip
:
for
path
in
release_folder
.
iterdir
():
if
not
path
.
is_dir
():
continue
image
=
path
/
f
'
{
path
.
name
}
.png'
if
not
image
.
exists
():
continue
image_zip
.
write
(
image
,
arcname
=
image
.
name
)
if
__name__
==
'__main__'
:
path
=
Path
(
sys
.
argv
[
1
])
build_package_index
(
path
)
build_image_zip
(
path
)
log
.
info
(
'Finished'
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment