Skip to content
Extraits de code Groupes Projets
Valider 2049ebf8 rédigé par Kubat's avatar Kubat
Parcourir les fichiers

Merge branch 'stpkg' into 'master'

Stpkg corrections

See merge request Tigriz/matrix-stickers!28
parents 7ad7412f cba43e51
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -171,7 +171,7 @@ file_get_height() {
echo "$HEIGHT"
}
file_get_type() { [[ "$1" =~ .*\.gif ]] && echo 'gif' || echo 'png'; }
file_get_type() { [[ "$1" == *.gif ]] && echo 'gif' || echo 'png'; }
file_get_name() { echo "$1" | cut -f1 -d'.'; }
upload_file() {
......@@ -195,7 +195,9 @@ picture_process_sticker() {
local HEIGHT=$5 # The HEIGHT!
local TYPE=$6 # The type of the file (png/gif)
local OPTS=`[ "$TYPE" = "png" ] && echo '-type TrueColor PNG32:' || echo ''`
local OPTS=`[ "$TYPE" = "png" ] && echo '-type TrueColor PNG32:' || echo ' -coalesce '`
info "File '$FILE' => '$DEST' ($TYPE) | OPTS = '$OPTS'"
convert "$FILE" -bordercolor none -border 1 "$DEST" 1>&2 && progress_dot || die "$NAME failed on border"
convert "$DEST" -trim +repage "$DEST" 1>&2 && progress_dot || die "$NAME failed on trim"
......@@ -597,7 +599,7 @@ __edit() {
local DEST=$(mktemp --suffix=".$TYPE")
picture_process_sticker "$FILE" "$DEST" "$NAME" "$WIDTH" "$HEIGHT" "$TYPE" # Transform sticker picture (see __pack)
upload_file "$TYPE" "$DEST" "$NAME" # Upload transformed file (see __pack)
local MXC=$(upload_file "$TYPE" "$DEST" "$NAME") # Upload transformed file (see __pack)
jq "del(.stickers[] | select(.body == \"$STICKER_NAME\"))" < "$TEMP" | sponge "$TEMP"
local ST_JSON=$(create_sticker_json "$PACK_NAME" "$NAME" "$WIDTH" "$HEIGHT" "$TYPE" "$MXC")
......@@ -723,15 +725,15 @@ __pack() {
echo -n "$FIRST_IN_ARRAY" >> $DEST_INDEX
# Upload the transformed file
upload_file "$TYPE" "$DEST" "$NAME"
local MXC=$(upload_file "$TYPE" "$DEST" "$NAME")
progress_dot
# Calculate the 128x128 format
local INIT_WIDTH=$WIDTH
local INIT_HEIGHT=$HEIGHT
picture_resize_preview "$DEST" "$NAME"
local WIDTH=$( identify -format "%w" "$DEST") >/dev/null
local HEIGHT=$(identify -format "%h" "$DEST") >/dev/null
local WIDTH=$( identify -format "%w" "$DEST[0]") >/dev/null
local HEIGHT=$(identify -format "%h" "$DEST[0]") >/dev/null
# Add the sticker to the index file
create_sticker_json "$PACK_NAME" "$NAME" "$WIDTH" "$HEIGHT" "$TYPE" "$MXC" >> $DEST_INDEX
......
import json
import sys
from colorama import Fore, Back, Style
# Pack is updated only if index and description are given
update = False
if len(sys.argv) <= 1 or len(sys.argv) == 3:
print("Usage : python updatePacks.py pack.json [sticker_index] [new_description]")
exit(1)
elif len(sys.argv) > 3:
update = True
# Read the pack file
with open(sys.argv[1],'r') as myfile:
stickerpack = myfile.read()
# Parse the pack
json_pack = json.loads(stickerpack)
nb_stickers = len(json_pack['stickers'])
if update == False:
# Print the number of stickers in this pack
print("There are " + str(nb_stickers) + " stickers in this pack: ")
for i in range(nb_stickers):
print("\t"+str(i+1) + ". " + json_pack['stickers'][i]['body'])
# Print how to update the description of a sticker
print("To update a sticker, replace the arguments in red:")
print(Fore.CYAN +Style.BRIGHT + "python " +Style.RESET_ALL+ "updatePacks.py " + sys.argv[1] + Fore.RED + Style.BRIGHT+" sticker_index 'new_description'")
exit(0)
# Informations
sticker_index = int(sys.argv[2])
new_body = sys.argv[3]
# Change the body of the sticker_index
if sticker_index > nb_stickers:
print("Index out of range : "+ str(sticker_index) + " > "+str(nb_stickers))
exit(1)
elif sticker_index == 0:
print("Index starts at 1")
exit(1)
else:
# Update the body of the sticker
json_pack['stickers'][sticker_index-1]['body'] = new_body
# Print the body of all the stickers
print(Fore.GREEN + 'Updated!'+ Style.RESET_ALL)
print("New sticker pack:")
for i in range(nb_stickers):
if i == sticker_index-1:
print("\t "+Fore.GREEN+str(i+1) + ". " + json_pack['stickers'][i]['body']+Style.RESET_ALL)
else:
print("\t "+str(i+1) + ". " + json_pack['stickers'][i]['body'])
# Replace the old pack.json by the updated one
out_file = open(sys.argv[1], 'w')
json.dump(json_pack, out_file, indent = 3)
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter