#!/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, json, sys, os, traceback PATH="/var/www/html/assets" # Delete previous deployment subprocess.call("rm --recursive %s/*" % PATH, shell=True) f=open("resources.json", "w") rc=[] # 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" % (fn, PATH, NAME), shell=True) EXT="webp" else: subprocess.call("cp %s %s/%s.%s" % (fn, PATH, NAME, EXT), shell=True) rc.append([NAME, EXT]) except: traceback.print_exc() pass # Save new summary json.dump(rc, f) f.close() # Create blank index page to disable dir listing subprocess.call("touch %s/index.html" % PATH, 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) # TODO: zip everything and provide an all-in-one download?