1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
#!/usr/bin/python2.7
########################################################################################
# This file is part of Spheres.
# Copyright (C) 2019 Jesusalva
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
########################################################################################
# This builds live/ folder for Update Server
import subprocess, os, uuid, traceback
PATH="/var/www/html/assets"
# Delete previous deployment
subprocess.call("rm --recursive %s/*" % PATH, shell=True)
# Go through every file in raw and give them a hash
for path, subdir, files in os.walk("raw/"):
for n in files:
fn=os.path.join(path, n)
# Ignored files
if fn.endswith("~"):
continue
# Copy and update resource table
print(fn)
try:
NAME=fn.replace("raw/", "").replace("/", "_")
EXT=NAME.split(".")[-1:][0]
NAME=NAME.split(".")[:-1][0]
## TODO code
if EXT in ["png", "jpg", "jpeg"]:
subprocess.call("convert %s %s/%s.webp" % (fn, PATH, NAME), shell=True)
subprocess.call("mv %s/%s.webp %s/%s" % (PATH, NAME, PATH, NAME), shell=True)
EXT="webp"
elif EXT in ["xcf", "psd"]:
continue
elif EXT in ["mp3", "ogg", "webp"]:
subprocess.call("cp %s %s/%s" % (fn, PATH, NAME), shell=True)
else:
subprocess.call("cp %s %s/%s.%s" % (fn, PATH, NAME, EXT), shell=True)
except:
traceback.print_exc()
pass
# Create blank index page to disable dir listing
subprocess.call("touch %s/index.html" % PATH, shell=True)
# TODO: zip everything and provide an all-in-one download?
fn="%s/%s.zip" % (PATH, uuid.uuid4().hex)
subprocess.call('cd %s; find . -printf "%%P\n" | zip -X -9 -@ %s' % (PATH, fn), shell=True)
# Correct permissions
subprocess.call("chown -R www-data:www-data %s/*" % PATH, shell=True)
subprocess.call("chmod --recursive o-rwx %s/*" % PATH, shell=True)
print("FILENAME: %s" % fn)
print("Register it in \"token\" value of server config to serve all-in-one downloads.")
print("(This feature might not yet have been implemented, though)")
|