def render_zip(container, path, file, lang, categories=False): with app.app.app_context(): with force_locale(lang): directory = tempfile.mkdtemp() count = len(container.graphs) if isinstance( container, Collation) else container.graphs.count() for nr, graph in enumerate(container.graphs): png_name = graph.name_without_accents + ".png" if categories: category_dir = os.path.join(directory, graph.category_without_accents) if not os.path.exists(category_dir): os.makedirs(category_dir) png_path = os.path.join(category_dir, png_name) else: png_path = os.path.join(directory, png_name) render_chart_png(graph, png_path) file.progress = round((nr + 1) / count * 100) db_session.add(file) db_session.commit() util.zipdir(directory, path) file.ready = True db_session.add(file) db_session.commit()
def download(): global log if 'id' in request.args and request.args['id']: item = dicts_to_items( var.music_db.query_music(Condition().and_equal( 'id', request.args['id'])))[0] requested_file = item.uri() log.info('web: Download of file %s requested from %s:' % (requested_file, request.remote_addr)) try: return send_file(requested_file, as_attachment=True) except Exception as e: log.exception(e) abort(404) else: condition = build_library_query_condition(request.args) items = dicts_to_items(var.music_db.query_music(condition)) zipfile = util.zipdir([item.uri() for item in items]) try: return send_file(zipfile, as_attachment=True) except Exception as e: log.exception(e) abort(404) return abort(400)
def download(): if 'file' in request.args: requested_file = request.args['file'] if '../' not in requested_file: folder_path = var.music_folder files = util.get_recursive_filelist_sorted(var.music_folder) if requested_file in files: filepath = os.path.join(folder_path, requested_file) try: return send_file(filepath, as_attachment=True) except Exception as e: self.log.exception(e) self.Error(400) elif 'directory' in request.args: requested_dir = request.args['directory'] folder_path = var.music_folder requested_dir_fullpath = os.path.abspath( os.path.join(folder_path, requested_dir)) + '/' if requested_dir_fullpath.startswith(folder_path): if os.path.samefile(requested_dir_fullpath, folder_path): prefix = 'all' else: prefix = secure_filename( os.path.relpath(requested_dir_fullpath, folder_path)) zipfile = util.zipdir(requested_dir_fullpath, prefix) try: return send_file(zipfile, as_attachment=True) except Exception as e: self.log.exception(e) self.Error(400) return redirect("./", code=400)
def pack_xpi(config_obj, deploy=False, check_history=False): id = config_obj['id'] name = config_obj['name'] branch = config_obj['branch'] base_dir = config_obj['basedir'] signkey = config_obj['signkey'] _repo_path = _get_repo_path(name) if not os.path.exists(_repo_path): error('Repo does not exist: %s' % _repo_path) raise Exception('Repo does not exists.') commit_hash = check_output('git log -1 --pretty=format:%H', cwd=_repo_path) # check packing history, if the version of the branch have been handled, skip it. # Config obj contain branch deploy history if not os.path.exists(PACK_LOG_DIR): os.makedirs(PACK_LOG_DIR) _pack_his_file = os.path.join(PACK_LOG_DIR, name) _pack_history = ConfigObj(_pack_his_file) if check_history is True: if _pack_history.has_key(branch) and _pack_history[branch] == commit_hash: log((Fore.BLUE + 'the branch %s of %s has been handled, skip it.' + Fore.RESET) % (branch,name)) return _base_dir = os.path.join(_repo_path, base_dir) log('Extension base dir: %s' % _base_dir) # Check if install.rdf exists _install_rdf_file = os.path.join(_base_dir, 'install.rdf') if not os.path.exists(_install_rdf_file): error('Install.rdf does not exists: %s' % _install_rdf_file) raise Exception('Install.rdf does not exists.') # zip files into an XPI file _xpi_dir = os.path.join(OUT_DIR, id, branch) if not os.path.exists(_xpi_dir): log('Create dir for XPI file ...') os.makedirs(_xpi_dir) _xpi_file = os.path.join(_xpi_dir, DEF_XPI_NAME) log('Zip dir into XPI file: %s' % _xpi_file) zipdir(_base_dir, _xpi_file, ['.git', '.gitignore', 'application.ini', 'documents', 'README']) # record deploy history _pack_history[branch] = commit_hash _pack_history.write()
def zip(self, zips): import os from util import zipdir outs = {} for z in zips: if os.path.isdir(z): out = z+'.zip' print "zip {} to {}".format(z, out) zipdir(z, out) outs[z] = out elif os.path.isfile(z): print "zip file" pass else: raise Exception("Can't zip: '{}' ".format(z)) return outs
def zip(self, zips): import os from util import zipdir outs = {} for z in zips: if os.path.isdir(z): out = z + '.zip' print "zip {} to {}".format(z, out) zipdir(z, out) outs[z] = out elif os.path.isfile(z): print "zip file" pass else: raise Exception("Can't zip: '{}' ".format(z)) return outs
def buildWinDesktop(artifacts, version, rebuild): # msbuild vars projectPath = os.path.abspath("..") projectFile = projectPath + os.sep + "solutions" + os.sep + "windowsDesktop_vc120" + os.sep + "brainCloud_winDesktop.sln" if rebuild: targets = "Rebuild" else: targets = "Build" print() print("Building windows api project") print() sys.stdout.flush() switches = [] switches.append("/p:Platform=Win32") # build release version of lib config = "Release" vstudio.buildProject(projectFile, targets, config, in_switches=switches) # build debug version of lib config = "Debug" vstudio.buildProject(projectFile, targets, config, in_switches=switches) switches = [] switches.append("/p:Platform=x64") # build release version of lib config = "Release" vstudio.buildProject(projectFile, targets, config, in_switches=switches) # build debug version of lib config = "Debug" vstudio.buildProject(projectFile, targets, config, in_switches=switches) print() print("Zipping library") rootPath = os.path.abspath("..") binPath = projectPath + os.sep + "solutions" + os.sep + "windowsDesktop_vc120" + os.sep + "bin" # zip up build directly from source files with zipfile.ZipFile("artifacts" + os.sep + "brainCloudClient_WindowsDesktop_" + version + ".zip", "w", compression=zipfile.ZIP_DEFLATED) as myzip: for fname in glob.iglob(binPath + os.sep + "Win32" + os.sep + "Release" + os.sep + "*.*"): myzip.write( fname, "lib" + os.sep + "win32" + os.sep + "release" + os.sep + os.path.basename(fname)) for fname in glob.iglob(binPath + os.sep + "Win32" + os.sep + "Debug" + os.sep + "*.*"): myzip.write( fname, "lib" + os.sep + "win32" + os.sep + "debug" + os.sep + os.path.basename(fname)) for fname in glob.iglob(binPath + os.sep + "x64" + os.sep + "Release" + os.sep + "*.*"): myzip.write( fname, "lib" + os.sep + "x64" + os.sep + "release" + os.sep + os.path.basename(fname)) for fname in glob.iglob(binPath + os.sep + "x64" + os.sep + "Debug" + os.sep + "*.*"): myzip.write( fname, "lib" + os.sep + "x64" + os.sep + "debug" + os.sep + os.path.basename(fname)) util.zipdir(rootPath + os.sep + "include" + os.sep, myzip, "include") util.zipdir(rootPath + os.sep + "lib" + os.sep + "jsoncpp-1.0.0", myzip, "thirdparty" + os.sep + "jsoncpp-1.0.0") util.zipdir( rootPath + os.sep + "lib" + os.sep + "win32" + os.sep + "cpprestsdk-static" + os.sep + "Release" + os.sep + "include", myzip, "thirdparty" + os.sep + "casablanca" + os.sep + "include") myzip.write("artifacts" + os.sep + "README.TXT", "README.TXT") return
def buildWinUwp(artifacts, version, rebuild): # msbuild vars projectPath = os.path.abspath("..") projectFile = projectPath + os.sep + "solutions" + os.sep + "windowsUniversal_vc140" + os.sep + "brainCloud_uwp.sln" if rebuild: targets = "brainCloud:Rebuild" else: targets = "brainCloud" print() print("Building windows universal project") print() sys.stdout.flush() # first restore nuget packages cwd = projectPath + os.sep + "solutions" + os.sep + "windowsUniversal_vc140" cmd = [] cmd.append("nuget") cmd.append("restore") print("Restoring nuget packages...") subprocess.check_call(cmd, cwd=cwd) # now build it switches = [] switches.append("/p:Platform=x86") # build release version of lib config = "Release" vstudio.buildProject(projectFile, targets, config, in_switches=switches) # build debug version of lib config = "Debug" vstudio.buildProject(projectFile, targets, config, in_switches=switches) switches = [] switches.append("/p:Platform=x64") # build release version of lib config = "Release" vstudio.buildProject(projectFile, targets, config, in_switches=switches) # build debug version of lib config = "Debug" vstudio.buildProject(projectFile, targets, config, in_switches=switches) switches = [] switches.append("/p:Platform=ARM") # build release version of lib config = "Release" vstudio.buildProject(projectFile, targets, config, in_switches=switches) # build debug version of lib config = "Debug" vstudio.buildProject(projectFile, targets, config, in_switches=switches) print() print("Zipping library") rootPath = os.path.abspath("..") binPath = projectPath + os.sep + "solutions" + os.sep + "windowsUniversal_vc140" + os.sep + "brainCloud" + os.sep + "Output" # zip up build directly from source files with zipfile.ZipFile("artifacts" + os.sep + "brainCloudClient_WindowsUniversal_" + version + ".zip", "w", compression=zipfile.ZIP_DEFLATED) as myzip: for fname in glob.iglob(binPath + os.sep + "ARM" + os.sep + "Release" + os.sep + "*.*"): myzip.write( fname, "lib" + os.sep + "ARM" + os.sep + "release" + os.sep + os.path.basename(fname)) for fname in glob.iglob(binPath + os.sep + "ARM" + os.sep + "Debug" + os.sep + "*.*"): myzip.write( fname, "lib" + os.sep + "ARM" + os.sep + "debug" + os.sep + os.path.basename(fname)) for fname in glob.iglob(binPath + os.sep + "Win32" + os.sep + "Release" + os.sep + "*.*"): myzip.write( fname, "lib" + os.sep + "win32" + os.sep + "release" + os.sep + os.path.basename(fname)) for fname in glob.iglob(binPath + os.sep + "Win32" + os.sep + "Debug" + os.sep + "*.*"): myzip.write( fname, "lib" + os.sep + "win32" + os.sep + "debug" + os.sep + os.path.basename(fname)) for fname in glob.iglob(binPath + os.sep + "x64" + os.sep + "Release" + os.sep + "*.*"): myzip.write( fname, "lib" + os.sep + "x64" + os.sep + "release" + os.sep + os.path.basename(fname)) for fname in glob.iglob(binPath + os.sep + "x64" + os.sep + "Debug" + os.sep + "*.*"): myzip.write( fname, "lib" + os.sep + "x64" + os.sep + "debug" + os.sep + os.path.basename(fname)) util.zipdir(rootPath + os.sep + "include" + os.sep, myzip, "include") util.zipdir(rootPath + os.sep + "lib" + os.sep + "jsoncpp-1.0.0", myzip, "thirdparty" + os.sep + "jsoncpp-1.0.0") myzip.write("artifacts" + os.sep + "README.TXT", "README.TXT") return
def test(): with zipfile.ZipFile("x.zip", "w", compression=zipfile.ZIP_DEFLATED) as myzip: util.zipdir("tmp", myzip, "thirdparty" + os.sep + "casablanca", ["tmp/ignore"], ["*.meta"]) return
def buildWinStore(artifacts, version, rebuild): print() print("Building windows store project") print() sys.stdout.flush() projectPath = os.path.abspath("..") projectFile = projectPath + os.sep + "solutions" + os.sep + "windowsStore_vc120" + os.sep + "brainCloud_winstore.sln" # winstore if rebuild: targets = "brainCloud_winstore:Rebuild" else: targets = "brainCloud_winstore" configs = [] configs.append("Debug") configs.append("Release") platforms = [] platforms.append("Win32") platforms.append("ARM") platforms.append("x64") for platform in platforms: for config in configs: print() print("BUILDING FOR PLATFORM: " + platform + " CONFIG: " + config) switches = [] switches.append("/p:Platform=" + platform) vstudio.buildProject(projectFile, targets, config, in_switches=switches) # winphone 8.1 if rebuild: targets = "brainCloud_wp:Rebuild" else: targets = "brainCloud_wp" configs = [] configs.append("Debug") configs.append("Release") platforms = [] platforms.append("Win32") platforms.append("ARM") for platform in platforms: for config in configs: print() print("BUILDING FOR PLATFORM: " + platform + " CONFIG: " + config) switches = [] switches.append("/p:Platform=" + platform) vstudio.buildProject(projectFile, targets, config, in_switches=switches) # winphone 8.0 if rebuild: targets = "brainCloud_wp8:Rebuild" else: targets = "brainCloud_wp8" configs = [] configs.append("Debug") configs.append("Release") platforms = [] platforms.append("Win32") platforms.append("ARM") for platform in platforms: for config in configs: print() print("BUILDING FOR PLATFORM: " + platform + " CONFIG: " + config) switches = [] switches.append("/p:Platform=" + platform) vstudio.buildProject(projectFile, targets, config, in_switches=switches) print() print("Zipping library files") rootPath = os.path.abspath("..") binPath = projectPath + os.sep + "solutions" + os.sep + "windowsStore_vc120" + os.sep + "bin" # zip up build directly from source files with zipfile.ZipFile("artifacts" + os.sep + "brainCloudClient_WindowsStore_" + version + ".zip", "w", compression=zipfile.ZIP_DEFLATED) as myzip: util.zipdir(rootPath + os.sep + "include" + os.sep, myzip, "include") util.zipdir(binPath, myzip, "lib") util.zipdir(rootPath + os.sep + "lib" + os.sep + "jsoncpp-1.0.0", myzip, "thirdparty" + os.sep + "jsoncpp-1.0.0") util.zipdir( rootPath + os.sep + "lib" + os.sep + "win32" + os.sep + "cpprestsdk-static" + os.sep + "Release" + os.sep + "include", myzip, "thirdparty" + os.sep + "casablanca" + os.sep + "include") myzip.write("artifacts" + os.sep + "README.TXT", "README.TXT") return
def buildWinDesktop(artifacts, version, rebuild): # msbuild vars projectPath = os.path.abspath("..") projectFile = projectPath + os.sep + "solutions" + os.sep + "windowsDesktop_vc120" + os.sep + "brainCloud_winDesktop.sln" if rebuild: targets = "Rebuild" else: targets = "Build" print() print("Building windows api project") print() sys.stdout.flush() switches = [] switches.append("/p:Platform=Win32") # build release version of lib config = "Release" vstudio.buildProject(projectFile, targets, config, in_switches=switches) # build debug version of lib config = "Debug" vstudio.buildProject(projectFile, targets, config, in_switches=switches) switches = [] switches.append("/p:Platform=x64") # build release version of lib config = "Release" vstudio.buildProject(projectFile, targets, config, in_switches=switches) # build debug version of lib config = "Debug" vstudio.buildProject(projectFile, targets, config, in_switches=switches) print() print("Zipping library") rootPath = os.path.abspath("..") binPath = projectPath + os.sep + "solutions" + os.sep + "windowsDesktop_vc120" + os.sep + "bin" # zip up build directly from source files with zipfile.ZipFile("artifacts" + os.sep + "brainCloudClient_WindowsDesktop_" + version + ".zip", "w", compression=zipfile.ZIP_DEFLATED) as myzip: for fname in glob.iglob(binPath + os.sep + "Win32" + os.sep + "Release" + os.sep + "*.*"): myzip.write(fname, "lib" + os.sep + "win32" + os.sep + "release" + os.sep + os.path.basename(fname)) for fname in glob.iglob(binPath + os.sep + "Win32" + os.sep + "Debug" + os.sep + "*.*"): myzip.write(fname, "lib" + os.sep + "win32" + os.sep + "debug" + os.sep + os.path.basename(fname)) for fname in glob.iglob(binPath + os.sep + "x64" + os.sep + "Release" + os.sep + "*.*"): myzip.write(fname, "lib" + os.sep + "x64" + os.sep + "release" + os.sep + os.path.basename(fname)) for fname in glob.iglob(binPath + os.sep + "x64" + os.sep + "Debug" + os.sep + "*.*"): myzip.write(fname, "lib" + os.sep + "x64" + os.sep + "debug" + os.sep + os.path.basename(fname)) util.zipdir(rootPath + os.sep + "include" + os.sep, myzip, "include") util.zipdir(rootPath + os.sep + "lib" + os.sep + "jsoncpp-1.0.0", myzip, "thirdparty" + os.sep + "jsoncpp-1.0.0") util.zipdir(rootPath + os.sep + "lib" + os.sep + "win32" + os.sep + "cpprestsdk-static" + os.sep + "Release" + os.sep + "include", myzip, "thirdparty" + os.sep + "casablanca" + os.sep + "include") myzip.write("artifacts" + os.sep + "README.TXT", "README.TXT") return
def buildWinUwp(artifacts, version, rebuild): # msbuild vars projectPath = os.path.abspath("..") projectFile = projectPath + os.sep + "solutions" + os.sep + "windowsUniversal_vc140" + os.sep + "brainCloud_uwp.sln" if rebuild: targets = "brainCloud:Rebuild" else: targets = "brainCloud" print() print("Building windows universal project") print() sys.stdout.flush() # first restore nuget packages cwd = projectPath + os.sep + "solutions" + os.sep + "windowsUniversal_vc140" cmd = [] cmd.append("nuget") cmd.append("restore") print("Restoring nuget packages...") subprocess.check_call(cmd, cwd=cwd) # now build it switches = [] switches.append("/p:Platform=x86") # build release version of lib config = "Release" vstudio.buildProject(projectFile, targets, config, in_switches=switches) # build debug version of lib config = "Debug" vstudio.buildProject(projectFile, targets, config, in_switches=switches) switches = [] switches.append("/p:Platform=x64") # build release version of lib config = "Release" vstudio.buildProject(projectFile, targets, config, in_switches=switches) # build debug version of lib config = "Debug" vstudio.buildProject(projectFile, targets, config, in_switches=switches) switches = [] switches.append("/p:Platform=ARM") # build release version of lib config = "Release" vstudio.buildProject(projectFile, targets, config, in_switches=switches) # build debug version of lib config = "Debug" vstudio.buildProject(projectFile, targets, config, in_switches=switches) print() print("Zipping library") rootPath = os.path.abspath("..") binPath = projectPath + os.sep + "solutions" + os.sep + "windowsUniversal_vc140" + os.sep + "brainCloud" + os.sep + "Output" # zip up build directly from source files with zipfile.ZipFile("artifacts" + os.sep + "brainCloudClient_WindowsUniversal_" + version + ".zip", "w", compression=zipfile.ZIP_DEFLATED) as myzip: for fname in glob.iglob(binPath + os.sep + "ARM" + os.sep + "Release" + os.sep + "*.*"): myzip.write(fname, "lib" + os.sep + "ARM" + os.sep + "release" + os.sep + os.path.basename(fname)) for fname in glob.iglob(binPath + os.sep + "ARM" + os.sep + "Debug" + os.sep + "*.*"): myzip.write(fname, "lib" + os.sep + "ARM" + os.sep + "debug" + os.sep + os.path.basename(fname)) for fname in glob.iglob(binPath + os.sep + "Win32" + os.sep + "Release" + os.sep + "*.*"): myzip.write(fname, "lib" + os.sep + "win32" + os.sep + "release" + os.sep + os.path.basename(fname)) for fname in glob.iglob(binPath + os.sep + "Win32" + os.sep + "Debug" + os.sep + "*.*"): myzip.write(fname, "lib" + os.sep + "win32" + os.sep + "debug" + os.sep + os.path.basename(fname)) for fname in glob.iglob(binPath + os.sep + "x64" + os.sep + "Release" + os.sep + "*.*"): myzip.write(fname, "lib" + os.sep + "x64" + os.sep + "release" + os.sep + os.path.basename(fname)) for fname in glob.iglob(binPath + os.sep + "x64" + os.sep + "Debug" + os.sep + "*.*"): myzip.write(fname, "lib" + os.sep + "x64" + os.sep + "debug" + os.sep + os.path.basename(fname)) util.zipdir(rootPath + os.sep + "include" + os.sep, myzip, "include") util.zipdir(rootPath + os.sep + "lib" + os.sep + "jsoncpp-1.0.0", myzip, "thirdparty" + os.sep + "jsoncpp-1.0.0") myzip.write("artifacts" + os.sep + "README.TXT", "README.TXT") return
def buildWinStore(artifacts, version, rebuild): print() print("Building windows store project") print() sys.stdout.flush() projectPath = os.path.abspath("..") projectFile = projectPath + os.sep + "solutions" + os.sep + "windowsStore_vc120" + os.sep + "brainCloud_winstore.sln" # winstore if rebuild: targets = "brainCloud_winstore:Rebuild" else: targets = "brainCloud_winstore" configs = [] configs.append("Debug") configs.append("Release") platforms = [] platforms.append("Win32") platforms.append("ARM") platforms.append("x64") for platform in platforms: for config in configs: print() print("BUILDING FOR PLATFORM: " + platform + " CONFIG: " + config) switches = [] switches.append("/p:Platform=" + platform) vstudio.buildProject(projectFile, targets, config, in_switches=switches) # winphone 8.1 if rebuild: targets = "brainCloud_wp:Rebuild" else: targets = "brainCloud_wp" configs = [] configs.append("Debug") configs.append("Release") platforms = [] platforms.append("Win32") platforms.append("ARM") for platform in platforms: for config in configs: print() print("BUILDING FOR PLATFORM: " + platform + " CONFIG: " + config) switches = [] switches.append("/p:Platform=" + platform) vstudio.buildProject(projectFile, targets, config, in_switches=switches) # winphone 8.0 if rebuild: targets = "brainCloud_wp8:Rebuild" else: targets = "brainCloud_wp8" configs = [] configs.append("Debug") configs.append("Release") platforms = [] platforms.append("Win32") platforms.append("ARM") for platform in platforms: for config in configs: print() print("BUILDING FOR PLATFORM: " + platform + " CONFIG: " + config) switches = [] switches.append("/p:Platform=" + platform) vstudio.buildProject(projectFile, targets, config, in_switches=switches) print() print("Zipping library files") rootPath = os.path.abspath("..") binPath = projectPath + os.sep + "solutions" + os.sep + "windowsStore_vc120" + os.sep + "bin" # zip up build directly from source files with zipfile.ZipFile("artifacts" + os.sep + "brainCloudClient_WindowsStore_" + version + ".zip", "w", compression=zipfile.ZIP_DEFLATED) as myzip: util.zipdir(rootPath + os.sep + "include" + os.sep, myzip, "include") util.zipdir(binPath, myzip, "lib") util.zipdir(rootPath + os.sep + "lib" + os.sep + "jsoncpp-1.0.0", myzip, "thirdparty" + os.sep + "jsoncpp-1.0.0") util.zipdir(rootPath + os.sep + "lib" + os.sep + "win32" + os.sep + "cpprestsdk-static" + os.sep + "Release" + os.sep + "include", myzip, "thirdparty" + os.sep + "casablanca" + os.sep + "include") myzip.write("artifacts" + os.sep + "README.TXT", "README.TXT") return