Skip to content
GitLab
Explorer
Connexion
Navigation principale
Rechercher ou aller à…
Projet
stickerpicker
Gestion
Activité
Membres
Labels
Programmation
Tickets
Tableaux des tickets
Jalons
Wiki
Wiki externe
Code
Requêtes de fusion
Dépôt
Branches
Validations
Étiquettes
Graphe du dépôt
Comparer les révisions
Extraits de code
Compilation
Pipelines
Jobs
Planifications de pipeline
Artéfacts
Déploiement
Releases
Registre de paquets
Registre de conteneurs
Registre de modèles
Opération
Environnements
Modules Terraform
Surveillance
Incidents
Analyse
Données d'analyse des chaînes de valeur
Analyse des contributeurs
Données d'analyse CI/CD
Données d'analyse du dépôt
Expériences du modèle
Aide
Aide
Support
Documentation de GitLab
Comparer les forfaits GitLab
Forum de la communauté GitLab
Contribuer à GitLab
Donner votre avis
Raccourcis clavier
?
Extraits de code
Groupes
Projets
Afficher davantage de fils d'Ariane
salixor
stickerpicker
Validations
99719acc
Valider
99719acc
rédigé
13 sept. 2020
par
Tulir Asokan
Parcourir les fichiers
Options
Téléchargements
Correctifs
Plain Diff
Add option to copy sticker-pack'ed pack to web/packs/
parent
87281d9a
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
Modifications
1
Afficher les modifications d'espaces
En ligne
Côte à côte
Affichage de
1 fichier modifié
sticker/pack.py
+63
-42
63 ajouts, 42 suppressions
sticker/pack.py
avec
63 ajouts
et
42 suppressions
sticker/pack.py
+
63
−
42
Voir le fichier @
99719acc
...
@@ -3,6 +3,7 @@
...
@@ -3,6 +3,7 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
from
typing
import
Dict
,
Optional
from
hashlib
import
sha256
from
hashlib
import
sha256
import
argparse
import
argparse
import
os.path
import
os.path
...
@@ -23,42 +24,24 @@ def convert_name(name: str) -> str:
...
@@ -23,42 +24,24 @@ def convert_name(name: str) -> str:
return
""
.
join
(
filter
(
lambda
char
:
char
in
allowed_chars
,
name
.
translate
(
name_translate
)))
return
""
.
join
(
filter
(
lambda
char
:
char
in
allowed_chars
,
name
.
translate
(
name_translate
)))
async
def
main
(
args
:
argparse
.
Namespace
)
->
None
:
async
def
upload_sticker
(
file
:
str
,
directory
:
str
,
old_stickers
:
Dict
[
str
,
matrix
.
StickerInfo
]
await
matrix
.
load_config
(
args
.
config
)
)
->
Optional
[
matrix
.
StickerInfo
]:
dirname
=
os
.
path
.
basename
(
os
.
path
.
abspath
(
args
.
path
))
meta_path
=
os
.
path
.
join
(
args
.
path
,
"
pack.json
"
)
try
:
with
open
(
meta_path
)
as
pack_file
:
pack
=
json
.
load
(
pack_file
)
print
(
f
"
Loaded existing pack meta from
{
meta_path
}
"
)
except
FileNotFoundError
:
pack
=
{
"
title
"
:
args
.
title
or
dirname
,
"
id
"
:
args
.
id
or
convert_name
(
dirname
),
"
stickers
"
:
[],
}
old_stickers
=
{}
else
:
old_stickers
=
{
sticker
[
"
id
"
]:
sticker
for
sticker
in
pack
[
"
stickers
"
]}
pack
[
"
stickers
"
]
=
[]
for
file
in
sorted
(
os
.
listdir
(
args
.
path
)):
if
file
.
startswith
(
"
.
"
):
if
file
.
startswith
(
"
.
"
):
continu
e
return
Non
e
path
=
os
.
path
.
join
(
args
.
path
,
file
)
path
=
os
.
path
.
join
(
directory
,
file
)
if
not
os
.
path
.
isfile
(
path
):
if
not
os
.
path
.
isfile
(
path
):
continu
e
return
Non
e
mime
=
magic
.
from_file
(
path
,
mime
=
True
)
mime
=
magic
.
from_file
(
path
,
mime
=
True
)
if
not
mime
.
startswith
(
"
image/
"
):
if
not
mime
.
startswith
(
"
image/
"
):
continu
e
return
Non
e
print
(
f
"
Processing
{
file
}
"
,
end
=
""
,
flush
=
True
)
try
:
try
:
with
open
(
path
,
"
rb
"
)
as
image_file
:
with
open
(
path
,
"
rb
"
)
as
image_file
:
image_data
=
image_file
.
read
()
image_data
=
image_file
.
read
()
except
Exception
as
e
:
except
Exception
as
e
:
print
(
f
"
Failed to read
{
file
}
:
{
e
}
"
)
print
(
f
"
... failed to read file:
{
e
}
"
)
continue
return
None
print
(
f
"
Processing
{
file
}
"
,
end
=
""
,
flush
=
True
)
name
=
os
.
path
.
splitext
(
file
)[
0
]
name
=
os
.
path
.
splitext
(
file
)[
0
]
# If the name starts with "number-", remove the prefix
# If the name starts with "number-", remove the prefix
...
@@ -69,10 +52,10 @@ async def main(args: argparse.Namespace) -> None:
...
@@ -69,10 +52,10 @@ async def main(args: argparse.Namespace) -> None:
sticker_id
=
f
"
sha256:
{
sha256
(
image_data
).
hexdigest
()
}
"
sticker_id
=
f
"
sha256:
{
sha256
(
image_data
).
hexdigest
()
}
"
print
(
"
.
"
,
end
=
""
,
flush
=
True
)
print
(
"
.
"
,
end
=
""
,
flush
=
True
)
if
sticker_id
in
old_stickers
:
if
sticker_id
in
old_stickers
:
pack
[
"
stickers
"
].
append
(
{
sticker
=
{
**
old_stickers
[
sticker_id
],
**
old_stickers
[
sticker_id
],
"
body
"
:
name
,
"
body
"
:
name
,
})
}
print
(
f
"
.. using existing upload
"
)
print
(
f
"
.. using existing upload
"
)
else
:
else
:
image_data
,
width
,
height
=
util
.
convert_image
(
image_data
)
image_data
,
width
,
height
=
util
.
convert_image
(
image_data
)
...
@@ -81,19 +64,57 @@ async def main(args: argparse.Namespace) -> None:
...
@@ -81,19 +64,57 @@ async def main(args: argparse.Namespace) -> None:
print
(
"
.
"
,
end
=
""
,
flush
=
True
)
print
(
"
.
"
,
end
=
""
,
flush
=
True
)
sticker
=
util
.
make_sticker
(
mxc
,
width
,
height
,
len
(
image_data
),
name
)
sticker
=
util
.
make_sticker
(
mxc
,
width
,
height
,
len
(
image_data
),
name
)
sticker
[
"
id
"
]
=
sticker_id
sticker
[
"
id
"
]
=
sticker_id
pack
[
"
stickers
"
].
append
(
sticker
)
print
(
"
uploaded
"
,
flush
=
True
)
print
(
"
uploaded
"
,
flush
=
True
)
return
sticker
async
def
main
(
args
:
argparse
.
Namespace
)
->
None
:
await
matrix
.
load_config
(
args
.
config
)
dirname
=
os
.
path
.
basename
(
os
.
path
.
abspath
(
args
.
path
))
meta_path
=
os
.
path
.
join
(
args
.
path
,
"
pack.json
"
)
try
:
with
open
(
meta_path
)
as
pack_file
:
pack
=
json
.
load
(
pack_file
)
print
(
f
"
Loaded existing pack meta from
{
meta_path
}
"
)
except
FileNotFoundError
:
pack
=
{
"
title
"
:
args
.
title
or
dirname
,
"
id
"
:
args
.
id
or
convert_name
(
dirname
),
"
stickers
"
:
[],
}
old_stickers
=
{}
else
:
old_stickers
=
{
sticker
[
"
id
"
]:
sticker
for
sticker
in
pack
[
"
stickers
"
]}
pack
[
"
stickers
"
]
=
[]
for
file
in
sorted
(
os
.
listdir
(
args
.
path
)):
sticker
=
await
upload_sticker
(
file
,
args
.
path
,
old_stickers
=
old_stickers
)
if
sticker
:
pack
[
"
stickers
"
].
append
(
sticker
)
with
open
(
meta_path
,
"
w
"
)
as
pack_file
:
with
open
(
meta_path
,
"
w
"
)
as
pack_file
:
json
.
dump
(
pack
,
pack_file
)
json
.
dump
(
pack
,
pack_file
)
print
(
f
"
Wrote pack to
{
meta_path
}
"
)
print
(
f
"
Wrote pack to
{
meta_path
}
"
)
if
args
.
add_to_index
:
picker_file_name
=
f
"
{
pack
[
'
id
'
]
}
.json
"
picker_pack_path
=
os
.
path
.
join
(
args
.
add_to_index
,
picker_file_name
)
with
open
(
picker_pack_path
,
"
w
"
)
as
pack_file
:
json
.
dump
(
pack
,
pack_file
)
print
(
f
"
Copied pack to
{
picker_pack_path
}
"
)
util
.
add_to_index
(
picker_file_name
,
args
.
add_to_index
)
parser
=
argparse
.
ArgumentParser
()
parser
=
argparse
.
ArgumentParser
()
parser
.
add_argument
(
"
--config
"
,
parser
.
add_argument
(
"
--config
"
,
help
=
"
Path to JSON file with Matrix homeserver and access_token
"
,
help
=
"
Path to JSON file with Matrix homeserver and access_token
"
,
type
=
str
,
default
=
"
config.json
"
)
type
=
str
,
default
=
"
config.json
"
,
metavar
=
"
file
"
)
parser
.
add_argument
(
"
--title
"
,
help
=
"
Override the sticker pack displayname
"
,
type
=
str
)
parser
.
add_argument
(
"
--title
"
,
help
=
"
Override the sticker pack displayname
"
,
type
=
str
,
parser
.
add_argument
(
"
--id
"
,
help
=
"
Override the sticker pack ID
"
,
type
=
str
)
metavar
=
"
title
"
)
parser
.
add_argument
(
"
--id
"
,
help
=
"
Override the sticker pack ID
"
,
type
=
str
,
metavar
=
"
id
"
)
parser
.
add_argument
(
"
--add-to-index
"
,
help
=
"
Sticker picker pack directory (usually
'
web/packs/
'
)
"
,
type
=
str
,
metavar
=
"
path
"
)
parser
.
add_argument
(
"
path
"
,
help
=
"
Path to the sticker pack directory
"
,
type
=
str
)
parser
.
add_argument
(
"
path
"
,
help
=
"
Path to the sticker pack directory
"
,
type
=
str
)
...
...
Ce diff est replié.
Cliquez pour l'agrandir.
Aperçu
0%
Chargement en cours
Veuillez réessayer
ou
joindre un nouveau fichier
.
Annuler
You are about to add
0
people
to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Enregistrer le commentaire
Annuler
Veuillez vous
inscrire
ou vous
se connecter
pour commenter