def get(self, _id): debug.info("get " + self.name + ": " + str(_id)) for elem in self.bdd: if 'id' in elem.keys() \ and elem["id"] == _id: return elem return None
def show_log(self, pkg_name): debug.debug("------------------------------------------------------------------------") debug.info("logcat of android board") debug.debug("------------------------------------------------------------------------") debug.info("cmd: " + self.path_sdk + "/platform-tools/adb shell logcat ") cmdLine = self.path_sdk + "/platform-tools/adb shell logcat " multiprocess.run_command_no_lock_out(cmdLine)
def version(): color = debug.get_color_set() import pkg_resources debug.info("version: 0.0.0") foldername = os.path.dirname(__file__) debug.info("source folder is: " + foldername) exit(0)
async def streaming(_response): debug.info("streaming " + str(_response)) total_size = 0 temporary_file = os.path.join(_app.config['REST_TMP_DATA'], str(tmp_value) + ".tmp") if not os.path.exists(_app.config['REST_TMP_DATA']): os.makedirs(_app.config['REST_TMP_DATA']) if not os.path.exists(_app.config['REST_MEDIA_DATA']): os.makedirs(_app.config['REST_MEDIA_DATA']) file_stream = open(temporary_file, "wb") sha1 = hashlib.sha512() while True: body = await _request.stream.read() if body is None: debug.warning("empty body") break total_size += len(body) debug.verbose("body " + str(len(body)) + "/" + str(total_size)) file_stream.write(body) sha1.update(body) file_stream.close() print("SHA512: " + str(sha1.hexdigest())) destination_filename = os.path.join(_app.config['REST_MEDIA_DATA'], str(sha1.hexdigest())) if os.path.isfile(destination_filename) == True: answer_data = { "size": total_size, "sha512": str(sha1.hexdigest()), 'filename': _request.headers["filename"], 'mime-type': _request.headers["mime-type"], "already_exist": True, } await _response.write( json.dumps(answer_data, sort_keys=True, indent=4)) return # move the file shutil.move(temporary_file, destination_filename) # collect media info ... media_info = MediaInfo.parse(destination_filename) data_metafile = { "sha512": str(sha1.hexdigest()), "size": total_size, 'filename': _request.headers["filename"], 'mime-type': _request.headers["mime-type"], 'media-info': json.loads(media_info.to_json()) } tools.file_write_data( destination_filename + ".meta", json.dumps(data_metafile, sort_keys=True, indent=4)) answer_data = { "size": total_size, "sha512": str(sha1.hexdigest()), 'filename': _request.headers["filename"], 'mime-type': _request.headers["mime-type"], "already_exist": True, } await _response.write( json.dumps(answer_data, sort_keys=True, indent=4))
def delete(self, _id): debug.info("delete " + self.name + ": " + str(_id)) id_in_bdd = self.get_table_index(_id) if id_in_bdd == None: return False del self.bdd[id_in_bdd] self.mark_to_store() return True
def create_directory_of_file(file): debug.info("Create directory of path: '" + file + "'") path = os.path.dirname(file) debug.info("Create directory: '" + path + "'") try: os.stat(path) except: os.makedirs(path)
def un_install_package(self, pkg_name): debug.debug("------------------------------------------------------------------------") debug.info("Un-Install package '" + pkg_name + "'") debug.debug("------------------------------------------------------------------------") pkg_name_application_name = pkg_name if self.config["mode"] == "debug": pkg_name_application_name += "debug" cmdLine = self.path_sdk + "/platform-tools/adb uninstall " + pkg_name_application_name Rmultiprocess.run_command(cmdLine)
def put(self, _id, _value): debug.info("put " + self.name + ": " + str(_id)) id_in_bdd = self.get_table_index(_id) if id_in_bdd == None: return False _value["id"] = _id self.bdd[id_in_bdd] = _value self.mark_to_store() return True
def post(self, _value): debug.info("post " + self.name) _value["id"] = self.last_id self.last_id += 1 if self.check_with_model(_value) == False: raise ServerError("Corelation with BDD error", status_code=404) self.bdd.append(_value) self.mark_to_store() return _value
def install_package(self, pkg_name): debug.debug("------------------------------------------------------------------------") debug.info("Install package '" + pkg_name + "'") debug.debug("------------------------------------------------------------------------") pkg_name_application_name = pkg_name if self.config["mode"] == "debug": pkg_name_application_name += "debug" cmdLine = self.path_sdk + "/platform-tools/adb install -r " \ + self.get_staging_path(pkg_name) + "/" + pkg_name_application_name + ".apk " multiprocess.run_command(cmdLine)
def run(self, pkg_name, option_list, binary_name = None): debug.debug("------------------------------------------------------------------------") debug.info("-- Run package '" + pkg_name + "' + option: " + str(option_list)) debug.debug("------------------------------------------------------------------------") appl_path = os.path.join(self.get_staging_path(pkg_name), pkg_name + ".app", pkg_name + ".html") cmd = "firefox " + appl_path + " " for elem in option_list: cmd += elem + " " multiprocess.run_command_no_lock_out(cmd) debug.debug("------------------------------------------------------------------------") debug.info("-- Run package '" + pkg_name + "' Finished") debug.debug("------------------------------------------------------------------------")
def show_video(elem_video_id, indent): indent_data = "" while indent > 0: indent_data += "\t" indent -= 1 result_video = requests.get("http://127.0.0.1:15080/video/" + str(elem_video_id) + "") if result_video.status_code == 200: video = result_video.json() debug.info(indent_data + "- " + str(video["generated_name"])) else: debug.warning(indent_data + "get video id: " + str(elem_video_id) + " !!!!!! " + str(result_video.status_code) + "")
def run_command_no_lock_out(cmd_line): # prepare command line: args = shlex.split(cmd_line) debug.info("cmd = " + str(args)) try: # create the subprocess p = subprocess.Popen(args) except subprocess.CalledProcessError as e: debug.error("subprocess.CalledProcessError : " + str(args)) return #except: # debug.error("Exception on : " + str(args)) # launch the subprocess: p.communicate()
def run(self, pkg_name, option_list, binary_name = None): if binary_name == None: binary_name = pkg_name; debug.debug("------------------------------------------------------------------------") debug.info("-- Run package '" + pkg_name + "' executable: '" + binary_name + "' + option: " + str(option_list)) debug.debug("------------------------------------------------------------------------") appl_path = os.path.join(self.get_staging_path(pkg_name), pkg_name + ".app", "bin", binary_name) cmd = appl_path + " " for elem in option_list: cmd += elem + " " multiprocess.run_command_no_lock_out(cmd) debug.debug("------------------------------------------------------------------------") debug.info("-- Run package '" + pkg_name + "' Finished") debug.debug("------------------------------------------------------------------------")
def un_install_package(self, pkg_name): debug.debug("------------------------------------------------------------------------") debug.info("-- Un-Install package '" + pkg_name + "'") debug.debug("------------------------------------------------------------------------") # this is temporary ... Will call: if False: os.system("lutin-pkg -r " + pkg_name) else: #Copy directly from staging path: target_path = os.path.join(os.path.expanduser("~"), ".local", "application", pkg_name + ".app") target_bin_link = os.path.join(os.path.expanduser("~"), ".local", "application", pkg_name) # remove output path: tools.remove_path_and_sub_path(target_path) # remove executable link version: tools.remove_file(target_bin_link)
def display(self): if len(self.arg) == 0: debug.info("option : " + self.option) elif len(self.option) == 0: debug.info("element : " + self.arg) else: debug.info("option : " + self.option + ":" + self.arg)
def install_package(self, pkg_name): debug.debug("------------------------------------------------------------------------") debug.info("-- Install package '" + pkg_name + "'") debug.debug("------------------------------------------------------------------------") # this is temporary ... Will call: if False: os.system("lutin-pkg -i " + os.path.join(self.get_final_path(), + pkg_name + ".app.gpkg")) else: #Copy directly from staging path: appl_path = os.path.join(self.get_staging_path(pkg_name), pkg_name + ".app") target_path = os.path.join(os.path.expanduser("~"), ".local", "application", pkg_name + ".app") target_bin_path = os.path.join(os.path.expanduser("~"), ".local", "application", pkg_name + ".app", "bin", pkg_name) target_bin_link = os.path.join(os.path.expanduser("~"), ".local", "application", pkg_name) # remove output path: tools.remove_path_and_sub_path(target_path) # remove executable link version: tools.remove_file(target_bin_link) # copy result: tools.copy_anything(appl_path, target_path, recursive=True) # create synbolic link: debug.info("kkk " + "ln -s " + target_bin_path + " " + target_bin_link) os.symlink(target_bin_path, target_bin_link)
def make_package(self, pkg_name, pkg_properties, base_pkg_path, heritage_list): debug.debug("make_package [START]") #The package generated depend of the type of the element: end_point_module_name = heritage_list.list_heritage[-1].name module = self.get_module(end_point_module_name) if module == None: debug.error("can not create package ... "); if module.get_type() == 'PREBUILD': #nothing to do ... return elif module.get_type() == 'LIBRARY' \ or module.get_type() == 'LIBRARY_DYNAMIC' \ or module.get_type() == 'LIBRARY_STATIC': debug.info("Can not create package for library"); return elif module.get_type() == 'BINARY' \ or module.get_type() == 'BINARY_STAND_ALONE': self.make_package_binary(pkg_name, pkg_properties, base_pkg_path, heritage_list, static = True) elif module.get_type() == 'BINARY_SHARED': self.make_package_binary(pkg_name, pkg_properties, base_pkg_path, heritage_list, static = False) elif module.get_type() == 'PACKAGE': self.make_package_binary(pkg_name, pkg_properties, base_pkg_path, heritage_list, static = False) debug.debug("make_package [STOP]") return
def install_video_path(_path, _basic_key={}): debug.info("Parse : '" + _path + "'") list_sub_path = [ fff for fff in os.listdir(_path) if os.path.isdir(os.path.join(_path, fff)) ] for it_path in list_sub_path: basic_key_tmp = copy.deepcopy(_basic_key) debug.info("Add Sub path: '" + it_path + "'") if len(basic_key_tmp) == 0: debug.info("find A '" + it_path + "' " + str(len(basic_key_tmp))) if it_path == "documentary": basic_key_tmp["type"] = 0 elif it_path == "film": basic_key_tmp["type"] = 1 elif it_path == "film-annimation": basic_key_tmp["type"] = 2 elif it_path == "film-short": basic_key_tmp["type"] = 3 elif it_path == "tv-show": basic_key_tmp["type"] = 4 elif it_path == "tv-show-annimation": basic_key_tmp["type"] = 5 elif it_path == "theater": basic_key_tmp["type"] = 6 elif it_path == "one-man": basic_key_tmp["type"] = 7 elif it_path == "concert": basic_key_tmp["type"] = 8 elif it_path == "opera": basic_key_tmp["type"] = 9 else: debug.info("find B '" + it_path + "' " + str(len(basic_key_tmp))) if it_path == "saison_01": basic_key_tmp["saison"] = 1 elif it_path == "saison_02": basic_key_tmp["saison"] = 2 elif it_path == "saison_03": basic_key_tmp["saison"] = 3 elif it_path == "saison_04": basic_key_tmp["saison"] = 4 elif it_path == "saison_05": basic_key_tmp["saison"] = 5 elif it_path == "saison_06": basic_key_tmp["saison"] = 6 elif it_path == "saison_07": basic_key_tmp["saison"] = 7 elif it_path == "saison_08": basic_key_tmp["saison"] = 8 elif it_path == "saison_09": basic_key_tmp["saison"] = 9 elif it_path == "saison_10": basic_key_tmp["saison"] = 10 elif it_path == "saison_11": basic_key_tmp["saison"] = 11 elif it_path == "saison_12": basic_key_tmp["saison"] = 12 elif it_path == "saison_13": basic_key_tmp["saison"] = 13 elif it_path == "saison_14": basic_key_tmp["saison"] = 14 elif it_path == "saison_15": basic_key_tmp["saison"] = 15 elif it_path == "saison_16": basic_key_tmp["saison"] = 16 elif it_path == "saison_17": basic_key_tmp["saison"] = 17 elif it_path == "saison_18": basic_key_tmp["saison"] = 18 elif it_path == "saison_19": basic_key_tmp["saison"] = 19 elif it_path == "saison_20": basic_key_tmp["saison"] = 20 elif it_path == "saison_21": basic_key_tmp["saison"] = 21 elif it_path == "saison_22": basic_key_tmp["saison"] = 22 elif it_path == "saison_23": basic_key_tmp["saison"] = 23 elif it_path == "saison_24": basic_key_tmp["saison"] = 24 elif it_path == "saison_25": basic_key_tmp["saison"] = 25 elif it_path == "saison_26": basic_key_tmp["saison"] = 26 elif it_path == "saison_27": basic_key_tmp["saison"] = 27 elif it_path == "saison_28": basic_key_tmp["saison"] = 28 elif it_path == "saison_29": basic_key_tmp["saison"] = 29 else: basic_key_tmp["series-name"] = it_path debug.info("add a path " + os.path.join(_path, it_path) + " with keys " + str(basic_key_tmp)) install_video_path(os.path.join(_path, it_path), basic_key_tmp) # Add files : list_sub_file = [ fff for fff in os.listdir(_path) if os.path.isfile(os.path.join(_path, fff)) ] for it_file in list_sub_file: basic_key_tmp = copy.deepcopy(_basic_key) push_video_file(os.path.join(_path, it_file), basic_key_tmp)
def un_install_package(self, pkg_name): debug.debug("------------------------------------------------------------------------") debug.info("-- Un-Install package '" + pkg_name + "'") debug.debug("------------------------------------------------------------------------") debug.error("action not implemented ...")
def gets_where(self, select, filter=None): debug.info("gets " + self.name) tmp_list = self.get_sub_list(self.bdd, select) return self.filter_object_values(tmp_list, filter)
def gets(self, filter=None): debug.info("gets " + self.name) if filter == None: return self.bdd return self.filter_object_values(self.bdd, filter)
def display(): global __system_list for elementName in __system_list: debug.info("SYSTEM: Integrate system: '" + elementName +"'") for data in __system_list[elementName]: debug.info("SYSTEM: '" + data["name"] +"' in " + data["path"])
def make_package_binary(self, pkg_name, pkg_properties, base_pkg_path, heritage_list, static): debug.debug("------------------------------------------------------------------------") debug.info("Generate package '" + pkg_name + "' v" + tools.version_to_string(pkg_properties["VERSION"])) debug.debug("------------------------------------------------------------------------") #output path target_outpath = self.get_staging_path(pkg_name) tools.create_directory_of_file(target_outpath) ## Create share datas: self.make_package_binary_data(target_outpath, pkg_name, base_pkg_path, heritage_list, static) ## copy binary files # in Android Package we have no binary element, only shared object ... (and java start file) ## Create libraries (special case of Android...) copy_list={} target_outpath_lib = os.path.join(target_outpath, self.pkg_path_lib) tools.create_directory_of_file(target_outpath_lib) # copy application lib: (needed to lunch ...) file_src = self.get_build_file_dynamic(pkg_name) if os.path.isfile(file_src): debug.debug(" need copy: " + file_src + " to " + target_outpath_lib) tools.copy_file(file_src, os.path.join(target_outpath_lib, os.path.basename(file_src)), in_list=copy_list) # copy other if needed: if static == False: #copy all shared libsh... debug.verbose("libs for " + str(pkg_name) + ":") for heritage in heritage_list.list_heritage: debug.debug("sub elements: " + str(heritage.name)) file_src = self.get_build_file_dynamic(heritage.name) debug.verbose(" has directory: " + file_src) if os.path.isfile(file_src): debug.debug(" need copy: " + file_src + " to " + target_outpath_lib) #copy all data: # TODO : We can have a problem when writing over library files ... tools.copy_file(file_src, os.path.join(target_outpath_lib, os.path.basename(file_src)), in_list=copy_list) #real copy files tools.copy_list(copy_list) if self.pkg_path_lib != "": # remove unneded files (NOT folder ...) tools.clean_directory(target_outpath_lib, copy_list) ## Create generic files: self.make_package_generic_files(target_outpath, pkg_properties, pkg_name, base_pkg_path, heritage_list, static) ## create specific android project (local) pkg_name_application_name = pkg_name if self.config["mode"] == "debug": pkg_name_application_name += "debug" #debug.info("ploppppp: " + str(pkg_properties)) # FINAL_path_JAVA_PROJECT self.path_java_project = os.path.join(target_outpath, "src") if pkg_properties["COMPAGNY_TYPE"] != "": self.path_java_project = os.path.join(self.path_java_project, pkg_properties["COMPAGNY_TYPE"]) if pkg_properties["COMPAGNY_NAME2"] != "": self.path_java_project = os.path.join(self.path_java_project, pkg_properties["COMPAGNY_NAME2"]) self.path_java_project = os.path.join(self.path_java_project, pkg_name_application_name) #FINAL_FILE_ABSTRACTION self.file_final_abstraction = os.path.join(self.path_java_project, pkg_name_application_name + ".java") compleatePackageName = "" if pkg_properties["COMPAGNY_TYPE"] != "": compleatePackageName += pkg_properties["COMPAGNY_TYPE"] + "." if pkg_properties["COMPAGNY_NAME2"] != "": compleatePackageName += pkg_properties["COMPAGNY_NAME2"] + "." compleatePackageName += pkg_name_application_name if "ADMOD_ID" in pkg_properties: pkg_properties["RIGHT"].append("INTERNET") pkg_properties["RIGHT"].append("ACCESS_NETWORK_STATE") debug.print_element("pkg", "absractionFile", "<==", "dynamic file") # Create path : tools.create_directory_of_file(self.file_final_abstraction) # Create file : # java ==> done by ewol wrapper ... (and compiled in the normal compilation system ==> must be find in the dependency list of jar ... tools.create_directory_of_file(target_outpath + "/res/drawable/icon.png"); if "ICON" in pkg_properties.keys() \ and pkg_properties["ICON"] != "": image.resize(pkg_properties["ICON"], target_outpath + "/res/drawable/icon.png", 256, 256) else: # to be sure that we have all time a resource ... tmpFile = open(target_outpath + "/res/drawable/plop.txt", 'w') tmpFile.write('plop\n') tmpFile.flush() tmpFile.close() if pkg_properties["ANDROID_MANIFEST"]!="": debug.print_element("pkg", "AndroidManifest.xml", "<==", pkg_properties["ANDROID_MANIFEST"]) tools.copy_file(pkg_properties["ANDROID_MANIFEST"], target_outpath + "/AndroidManifest.xml", force=True) else: debug.error("missing parameter 'ANDROID_MANIFEST' in the properties ... ") #add properties on wallpaper : # myModule.add_pkg("ANDROID_WALLPAPER_PROPERTIES", ["list", key, title, summary, [["key","value display"],["key2","value display 2"]]) # myModule.add_pkg("ANDROID_WALLPAPER_PROPERTIES", ["list", "testpattern", "Select test pattern", "Choose which test pattern to display", [["key","value display"],["key2","value display 2"]]]) # myModule.add_pkg("ANDROID_WALLPAPER_PROPERTIES", ["bool", key, title, summary, ["enable string", "disable String"]) # myModule.add_pkg("ANDROID_WALLPAPER_PROPERTIES", ["bool", "movement", "Motion", "Apply movement to test pattern", ["Moving test pattern", "Still test pattern"] #copy needed resources : for res_source, res_dest in pkg_properties["ANDROID_RESOURCES"]: if res_source == "": continue tools.copy_file(res_source , target_outpath + "/res/" + res_dest + "/" + os.path.basename(res_source), force=True) # Doc : # http://asantoso.wordpress.com/2009/09/15/how-to-build-android-application-package-apk-from-the-command-line-using-the-sdk-tools-continuously-integrated-using-cruisecontrol/ debug.print_element("pkg", "R.java", "<==", "Resources files") tools.create_directory_of_file(target_outpath + "/src/noFile") android_tool_path = self.path_sdk + "/build-tools/" # find android tool version dirnames = tools.get_list_sub_path(android_tool_path) if len(dirnames) == 0: debug.warning("This does not comport directory: '" + android_tool_path + "'") debug.error("An error occured when getting the tools for android") elif len(dirnames) > 1: dirnames = sorted(dirnames, reverse=True) debug.debug("sort tools directory: '" + str(dirnames) + "' ==> select : " + str(dirnames[0])) android_tool_path += dirnames[0] + "/" # this is to create resource file for android ... (we did not use aset in jar with ewol ... adModResoucepath = "" if "ADMOD_ID" in pkg_properties: adModResoucepath = " -S " + self.path_sdk + "/extras/google/google_play_services/libproject/google-play-services_lib/res/ " cmdLine = android_tool_path + "aapt p -f " \ + "-M " + target_outpath + "/AndroidManifest.xml " \ + "-F " + target_outpath + "/resources.res " \ + "-I " + self.path_sdk + "/platforms/android-" + str(self.board_id) + "/android.jar "\ + "-S " + target_outpath + "/res/ " \ + adModResoucepath \ + "-J " + target_outpath + "/src/ " multiprocess.run_command(cmdLine) tools.create_directory_of_file(target_outpath + "/build/classes/noFile") debug.print_element("pkg", "*.class", "<==", "*.java") #generate android java files: filesString="" """ old : if "ADMOD_ID" in pkg_properties: # TODO : check this I do not think it is really usefull ... ==> write for IDE only ... filesString += self.path_sdk + "/extras/google/google_play_services/libproject/google-play-services_lib/src/android/UnusedStub.java " if len(pkg_properties["ANDROID_WALLPAPER_PROPERTIES"])!=0: filesString += self.path_java_project + pkg_name_application_name + "Settings.java " adModJarFile = "" if "ADMOD_ID" in pkg_properties: adModJarFile = ":" + self.path_sdk + "/extras/google/google_play_services/libproject/google-play-services_lib/libs/google-play-services.jar" cmdLine = "javac " \ + "-d " + self.get_staging_path(pkg_name) + "/build/classes " \ + "-classpath " + self.path_sdk + "/platforms/android-" + str(self.board_id) + "/android.jar" \ + adModJarFile + " " \ + filesString \ + self.file_final_abstraction + " " \ + self.get_staging_path(pkg_name) + "/src/R.java " multiprocess.run_command(cmdLine) """ debug.verbose("heritage .so=" + str(tools.filter_extention(heritage_list.src['dynamic'], ["so"]))) debug.verbose("heritage .jar=" + str(tools.filter_extention(heritage_list.src['src'], ["jar"]))) class_extern = "" upper_jar = tools.filter_extention(heritage_list.src['src'], ["jar"]) #debug.warning("ploppppp = " + str(upper_jar)) for elem in upper_jar: if len(class_extern) > 0: class_extern += ":" class_extern += elem # create enpoint element : cmdLine = "javac " \ + "-d " + target_outpath + "/build/classes " \ + "-classpath " + class_extern + " " \ + target_outpath + "/src/R.java " multiprocess.run_command(cmdLine) debug.print_element("pkg", ".dex", "<==", "*.class") cmdLine = android_tool_path + "dx " \ + "--dex --no-strict " \ + "--output=" + target_outpath + "/build/" + pkg_name_application_name + ".dex " \ + target_outpath + "/build/classes/ " if "ADMOD_ID" in pkg_properties: cmdLine += self.path_sdk + "/extras/google/google_play_services/libproject/google-play-services_lib/libs/google-play-services.jar " # add element to dexification: for elem in upper_jar: # remove android sdk: if elem[-len("android.jar"):] != "android.jar": cmdLine += elem + " " multiprocess.run_command(cmdLine) debug.print_element("pkg", ".apk", "<==", ".dex, assets, .so, res") #builderDebug="-agentlib:jdwp=transport=dt_socket,server=y,address=8050,suspend=y " builderDebug="" # note : set -u not signed application... #+ ":" + self.path_sdk + "/extras/google/google_play_services/libproject/google-play-services_lib/libs/google-play-services.jar " cmdLine = "java -Xmx128M " \ + " -classpath " + self.path_sdk + "/tools/lib/sdklib.jar " \ + builderDebug \ + " com.android.sdklib.build.ApkBuilderMain " \ + target_outpath + "/build/" + pkg_name_application_name + "-unalligned.apk " \ + " -u " \ + " -z " + target_outpath + "/resources.res " \ + " -f " + target_outpath + "/build/" + pkg_name_application_name + ".dex " \ + " -rf " + target_outpath + "/data " multiprocess.run_command(cmdLine) # doc : # http://developer.android.com/tools/publishing/app-signing.html # Create a key for signing your application: # keytool -genkeypair -v -keystore AndroidKey.jks -storepass Pass__AndroidDebugKey -alias alias__AndroidDebugKey -keypass PassKey__AndroidDebugKey -keyalg RSA -validity 36500 if self.config["mode"] == "debug": debug.print_element("pkg", ".apk(signed debug)", "<==", ".apk (not signed)") # verbose mode : #debugOption = "-verbose -certs " debugOption = "" cmdLine = "jarsigner " \ + debugOption \ + "-keystore " + tools.get_current_path(__file__) + "/AndroidDebugKey.jks " \ + " -sigalg SHA1withRSA -digestalg SHA1 " \ + " -storepass Pass__AndroidDebugKey " \ + " -keypass PassKey__AndroidDebugKey " \ + target_outpath + "/build/" + pkg_name_application_name + "-unalligned.apk " \ + " alias__AndroidDebugKey" multiprocess.run_command(cmdLine) tmpFile = open("tmpPass.boo", 'w') tmpFile.write("\n") tmpFile.flush() tmpFile.close() else: print("On release mode we need the file : and key an pasword to sign the application ...") debug.print_element("pkg", ".apk(signed debug)", "<==", ".apk (not signed)") cmdLine = "jarsigner " \ + " -keystore " + pkg_properties["ANDROID_SIGN"] + " " \ + " -sigalg SHA1withRSA -digestalg SHA1 " \ + target_outpath + "/build/" + pkg_name_application_name + "-unalligned.apk " \ + " " + pkg_name_application_name multiprocess.run_command(cmdLine) cmdLine = "jarsigner " \ + " -verify -verbose -certs " \ + " -sigalg SHA1withRSA -digestalg SHA1 " \ + target_outpath + "/build/" + pkg_name_application_name + "-unalligned.apk " multiprocess.run_command(cmdLine) debug.print_element("pkg", ".apk(aligned)", "<==", ".apk (not aligned)") tools.remove_file(target_outpath + "/" + pkg_name_application_name + ".apk") # verbose mode : -v cmdLine = android_tool_path + "zipalign 4 " \ + target_outpath + "/build/" + pkg_name_application_name + "-unalligned.apk " \ + target_outpath + "/" + pkg_name_application_name + ".apk " multiprocess.run_command(cmdLine) # copy file in the final stage : tools.copy_file(target_outpath + "/" + pkg_name_application_name + ".apk", self.get_final_path() + "/" + pkg_name_application_name + ".apk", force=True)
def __init__(self, config, sub_name=[]): #processor type selection (auto/arm/ppc/x86) if config["arch"] == "auto": config["arch"] = "arm" #bus size selection (auto/32/64) if config["bus-size"] == "auto": config["bus-size"] = "32" self.type_arch = "" target.Target.__init__(self, ["Android"] + sub_name, config, self.type_arch) if config["bus-size"] == "32": self.type_arch="armv7" else: self.type_arch="arm64" self.path_ndk = os.getenv('PROJECT_NDK', "AUTO") self.path_sdk = os.getenv('PROJECT_SDK', "AUTO") # auto search NDK if self.path_ndk == "AUTO": for path in os.listdir("."): if os.path.isdir(path)==True: if path=="android": self.path_ndk = path + "/ndk" if self.path_ndk == "AUTO": self.path_ndk = tools.get_run_path() + "/../android/ndk" # auto search SDK if self.path_sdk == "AUTO": for path in os.listdir("."): if os.path.isdir(path)==True: if path=="android": self.path_sdk = path + "/sdk" if self.path_sdk == "AUTO": self.path_sdk = tools.get_run_path() + "/../android/sdk" if not os.path.isdir(self.path_ndk): debug.error("NDK path not set !!! set env : PROJECT_NDK on the NDK path") if not os.path.isdir(self.path_sdk): debug.error("SDK path not set !!! set env : PROJECT_SDK on the SDK path") tmpOsVal = "64" gccVersion = "4.9" # TODO : Remove this or set it better ... self.compilator_version = gccVersion if host.BUS_SIZE==64: tmpOsVal = "_64" if self.config["compilator"] == "clang": self.set_cross_base(self.path_ndk + "/toolchains/llvm-3.6/prebuilt/linux-x86" + tmpOsVal + "/bin/") # Patch for LLVM AR tool self.ar = self.cross + "llvm-ar" else: basepathArm = self.path_ndk + "/toolchains/arm-linux-androideabi-" + gccVersion + "/prebuilt/linux-x86" + tmpOsVal + "/bin/" basepathMips = self.path_ndk + "/toolchains/mipsel-linux-android-" + gccVersion + "/prebuilt/linux-x86" + tmpOsVal + "/bin/" basepathX86 = self.path_ndk + "/toolchains/x86-" + gccVersion + "/prebuilt/linux-x86" + tmpOsVal + "/bin/" self.set_cross_base(basepathArm + "arm-linux-androideabi-") if not os.path.isdir(basepathArm): debug.error("Gcc Arm path does not exist !!!") if not os.path.isdir(basepathMips): debug.info("Gcc Mips path does not exist !!!") if not os.path.isdir(basepathX86): debug.info("Gcc x86 path does not exist !!!") # TODO : Set it back in the package only ... #self.path_bin="mustNotCreateBinary" #self.path_lib="data/lib/armeabi" #self.path_data="data/assets" #self.path_doc="doc" #self.suffix_package='.pkg' self.pkg_path_data = "data/assets" self.pkg_path_bin = "mustNotCreateBinary" self.pkg_path_lib = "data/lib/armeabi" self.pkg_path_license = "license" # If the env variable is not define, find the newest version of the BOARD_ID (Note: 0: autofind) self.board_id = int(os.getenv('PROJECT_NDK_BOARD_ID', "0")) if self.board_id != 0: # check if element existed : if not os.path.isdir(self.path_sdk +"/platforms/android-" + str(self.board_id)): debug.error("Specify PROJECT_NDK_BOARD_ID env variable and the BOARD_ID does not exit ... : " + str(self.board_id) + "==> auto-search") self.board_id = 0 if self.board_id == 0: debug.debug("Auto-search BOARD-ID") for iii in reversed(range(0, 50)): debug.debug("try: " + os.path.join(self.path_sdk, "platforms", "android-" + str(iii))) if os.path.isdir(os.path.join(self.path_sdk, "platforms", "android-" + str(iii))): debug.debug("Find BOARD-ID : " + str(iii)) self.board_id = iii break; if self.board_id == 0: debug.error("Can not find BOARD-ID ==> update your android SDK") self.add_flag("c", "-D__ANDROID_BOARD_ID__=" + str(self.board_id)) if self.type_arch == "armv5" or self.type_arch == "armv7": self.global_include_cc.append("-I" + os.path.join(self.path_ndk, "platforms", "android-" + str(self.board_id), "arch-arm", "usr", "include")) elif self.type_arch == "mips": self.global_include_cc.append("-I" + os.path.join(self.path_ndk, "platforms", "android-" + str(self.board_id), "arch-mips", "usr", "include")) elif self.type_arch == "x86": self.global_include_cc.append("-I" + os.path.join(self.path_ndk, "platforms", "android-" + str(self.board_id), "arch-x86", "usr", "include")) self.global_include_cc.append("-I" + os.path.join(self.path_ndk, "sources", "android", "support", "include")) if self.config["compilator"] == "clang": self.global_include_cc.append("-gcc-toolchain " + os.path.join(self.path_ndk, "sources", "android", "support", "include")) if self.type_arch == "armv5": pass elif self.type_arch == "armv7": # The only one tested ... ==> but we have link error ... self.add_flag("c", [ "-target armv7-none-linux-androideabi", "-march=armv7-a", "-mfpu=vfpv3-d16", "-mhard-float" ]) self.add_flag("link", [ "-target armv7-none-linux-androideabi", "-Wl,--fix-cortex-a8", "-Wl,--no-warn-mismatch", "-lm_hard" ]) elif self.type_arch == "mips": pass elif self.type_arch == "x86": pass else: if self.type_arch == "armv5": pass elif self.type_arch == "armv7": pass elif self.type_arch == "mips": pass elif self.type_arch == "x86": pass self.sysroot = "--sysroot=" + os.path.join(self.path_ndk, "platforms", "android-" + str(self.board_id), "arch-arm") if True: self._mode_arm = "thumb" else: self._mode_arm = "arm" self.add_flag("c", [ "-D__ARM_ARCH_5__", "-D__ARM_ARCH_5T__", "-D__ARM_ARCH_5E__", "-D__ARM_ARCH_5TE__" ]) if self.config["compilator"] != "clang": if self.type_arch == "armv5": # ----------------------- # -- arm V5 : # ----------------------- self.add_flag("c", [ "-march=armv5te", "-msoft-float" ]) else: # ----------------------- # -- arm V7 (Neon) : # ----------------------- self.add_flag("c", [ "-m"+self._mode_arm, "-mfpu=neon", "-march=armv7-a", "-mtune=cortex-a8", "-mfloat-abi=softfp", "-mvectorize-with-neon-quad", "-D__ARM_ARCH_7__", "-D__ARM_NEON__" ]) self.add_flag("link", [ "-mfpu=neon", "-mfloat-abi=softfp", "-Wl,--fix-cortex-a8", ]) """ self.add_flag("link-lib", [ "dl" ]) self.add_flag("link", [ "-rdynamic" ]) """ # the -mthumb must be set for all the android produc, some ot the not work coretly without this one ... (all android code is generated with this flags) #self.add_flag("c", "-mthumb") # ----------------------- # -- Common flags : # ----------------------- self.add_flag("c", "-fpic") if self.config["compilator"] != "clang": self.add_flag("c", [ "-ffunction-sections", "-funwind-tables", "-fstack-protector", "-Wno-psabi", #"-mtune=xscale", "-fomit-frame-pointer", "-fno-strict-aliasing" ]) self.add_flag("c++", [ "-frtti", "-fexceptions", "-Wa,--noexecstack" ])
def build(self, name, optionnal=False, actions=[], package_name=None): if len(name.split("?")) != 1\ or len(name.split("@")) != 1: debug.error("need update") if actions == "": actions = ["build"] if actions == []: actions = ["build"] if type(actions) == str: actions = [actions] if name == "gcov": debug.info("gcov all") debug.error("must set the gcov parsing on a specific library or binary ==> not supported now for all") if name == "dump": debug.info("dump all") self.load_all() for mod in self.module_list: mod.display() return if name[:10] == "dependency": if len(name) > 10: rules = name.split(":")[1] else: rules = "LBDPK" # L for library # B for binary # D for Data # P for prebuild # K for package debug.print_element("dot", "", "---", "dependency.dot") self.load_all() tmp_file = open("dependency.dot", 'w') tmp_file.write('digraph G {\n') tmp_file.write(' rankdir=\"LR\";\n') for mod in self.module_list: mod.dependency_generate(self, tmp_file, 1, rules) # TODO : do it better ==> system library hook (do a oad of all avillable system library) tmp_file.write(' node [\n'); tmp_file.write(' shape=square;\n'); tmp_file.write(' style=filled;\n'); tmp_file.write(' color=gray;\n'); tmp_file.write(' ];\n'); # TODO : End hook for mod in self.module_list: mod.dependency_generate(self, tmp_file, 2, rules) tmp_file.write('}\n') tmp_file.flush() tmp_file.close() debug.print_element("dot", "", "---", "dependency.dot") return if name == "all": debug.info("build all") self.load_all() for mod in self.module_list: if self._name == "Android": if mod.get_type() == "PACKAGE": mod.build(self, package_name) else: if mod.get_type() == "BINARY" \ or mod.get_type() == "PACKAGE": mod.build(self, package_name) elif name == "clean": debug.info("clean all") self.load_all() for mod in self.module_list: mod.clean(self) else: module_name = name action_list = actions for action_name in action_list: debug.verbose("requested : " + module_name + "?" + action_name + " [START]") ret = None; if action_name == "install": try: self.install_package(module_name) except AttributeError: debug.error("target have no 'install_package' instruction") elif action_name == "uninstall": try: self.un_install_package(module_name) except AttributeError: debug.error("target have no 'un_install_package' instruction") elif action_name[:3] == "run": """ if mod.get_type() != "BINARY" \ and mod.get_type() != "PACKAGE": debug.error("Can not run other than 'BINARY' ... pakage='" + mod.get_type() + "' for module='" + module_name + "'") """ bin_name = None if len(action_name) > 3: if action_name[3] == '%': bin_name = "" for elem in action_name[4:]: if elem == ":": break; bin_name += elem # we have option: action_name2 = action_name.replace("\:", "1234COLUMN4321") option_list = action_name2.split(":") if len(option_list) == 0: if bin_name != None: debug.warning("action 'run' wrong options options ... : '" + action_name + "' might be separate with ':'") option_list = [] else: option_list_tmp = option_list[1:] option_list = [] for elem in option_list_tmp: option_list.append(elem.replace("1234COLUMN4321", ":")) else: option_list = [] #try: self.run(module_name, option_list, bin_name) #except AttributeError: # debug.error("target have no 'run' instruction") elif action_name == "log": try: self.show_log(module_name) except AttributeError: debug.error("target have no 'show_log' instruction") else: present = self.load_if_needed(module_name, optionnal=optionnal) if present == False \ and optionnal == True: ret = [heritage.HeritageList(), False] else: for mod in self.module_list: debug.verbose("compare " + mod.get_name() + " == " + module_name) if mod.get_name() == module_name: if action_name[:4] == "dump": debug.info("dump module '" + module_name + "'") if len(action_name) > 4: debug.warning("action 'dump' does not support options ... : '" + action_name + "'") ret = mod.display() break elif action_name[:5] == "clean": debug.info("clean module '" + module_name + "'") if len(action_name) > 5: debug.warning("action 'clean' does not support options ... : '" + action_name + "'") ret = mod.clean(self) break elif action_name[:4] == "gcov": debug.debug("gcov on module '" + module_name + "'") if len(action_name) > 4: # we have option: option_list = action_name.split(":") if len(option_list) == 0: debug.warning("action 'gcov' wrong options options ... : '" + action_name + "' might be separate with ':'") option_list = [] else: option_list = option_list[1:] else: option_list = [] if "output" in option_list: ret = mod.gcov(self, generate_output=True) else: ret = mod.gcov(self, generate_output=False) break elif action_name[:5] == "build": if len(action_name) > 5: debug.warning("action 'build' does not support options ... : '" + action_name + "'") debug.debug("build module '" + module_name + "'") if optionnal == True: ret = [mod.build(self, package_name), True] else: ret = mod.build(self, package_name) break if optionnal == True \ and ret == None: ret = [heritage.HeritageList(), False] break if ret == None: debug.error("not know module name : '" + module_name + "' to '" + action_name + "' it") debug.verbose("requested : " + module_name + "?" + action_name + " [STOP]") if len(action_list) == 1: return ret
def make_package_binary(self, pkg_name, pkg_properties, base_pkg_path, heritage_list, static): # http://alp.developpez.com/tutoriels/debian/creer-paquet/ debianpkg_name = re.sub("_", "-", pkg_name) debug.debug("------------------------------------------------------------------------") debug.info("Generate generic '" + pkg_name + "' v" + tools.version_to_string(pkg_properties["VERSION"])) debug.debug("------------------------------------------------------------------------") #output path target_outpath = os.path.join(self.get_staging_path(pkg_name), pkg_name + ".app") tools.create_directory_of_file(target_outpath) ## Create share datas: ret_share = self.make_package_binary_data(target_outpath, pkg_name, base_pkg_path, heritage_list, static) ## copy binary files: ret_bin = self.make_package_binary_bin(target_outpath, pkg_name, base_pkg_path, heritage_list, static) ## Create libraries: ret_lib = self.make_package_binary_lib(target_outpath, pkg_name, base_pkg_path, heritage_list, static) ## Create generic files: ret_file = self.make_package_generic_files(target_outpath, pkg_properties, pkg_name, base_pkg_path, heritage_list, static) ## end of the package generation build_package_path_done = os.path.join(self.get_build_path(pkg_name), "generatePackageDone.txt") #Check date between the current file "list of action to generate package and the end of package generation need_generate_package = depend.need_re_package(build_package_path_done, [__file__], True) ## create the package: if ret_share \ or ret_bin \ or ret_lib \ or ret_file \ or need_generate_package: """ ## create the package: debug.debug("package : " + self.get_staging_path(pkg_name) + "/" + pkg_name + ".app.pkg") os.system("cd " + self.get_staging_path(pkg_name) + " ; tar -czf " + pkg_name + ".app.tar.gz " + pkg_name + ".app") #multiprocess.run_command("cd " + self.get_staging_path(pkg_name) + " ; tar -czf " + pkg_name + ".app.tar.gz " + pkg_name + ".app") tools.create_directory_of_file(self.get_final_path()) tools.copy_file(self.get_staging_path(pkg_name) + "/" + pkg_name + ".app.tar.gz", self.get_final_path() + "/" + pkg_name + ".app.gpkg") def make_package_binary(self, pkg_name, pkg_properties, base_pkg_path, heritage_list, static): """ self.get_staging_path(pkg_name) target_outpathDebian = self.get_staging_path(pkg_name) + "/DEBIAN/" finalFileControl = target_outpathDebian + "control" finalFilepostRm = target_outpathDebian + "postrm" # create the paths : tools.create_directory_of_file(finalFileControl) tools.create_directory_of_file(finalFilepostRm) ## Create the control file tools.create_directory_of_file(finalFileControl) tmpFile = open(finalFileControl, 'w') tmpFile.write("Package: " + debianpkg_name + "\n") tmpFile.write("Version: " + tools.version_to_string(pkg_properties["VERSION"]) + "\n") tmpFile.write("Section: " + self.generate_list_separate_coma(pkg_properties["SECTION"]) + "\n") tmpFile.write("Priority: " + pkg_properties["PRIORITY"] + "\n") tmpFile.write("Architecture: all\n") tmpFile.write("Depends: bash\n") tmpFile.write("Maintainer: " + self.generate_list_separate_coma(pkg_properties["MAINTAINER"]) + "\n") tmpFile.write("Description: " + pkg_properties["DESCRIPTION"] + "\n") tmpFile.write("\n") tmpFile.flush() tmpFile.close() ## Create the PostRm tmpFile = open(finalFilepostRm, 'w') tmpFile.write("#!/bin/bash\n") tmpFile.write("touch ~/." + pkg_name + "\n") if pkg_name != "": tmpFile.write("touch ~/.local/share/" + pkg_name + "\n") tmpFile.write("rm -r ~/.local/share/" + pkg_name + "\n") tmpFile.write("\n") tmpFile.flush() tmpFile.close() ## Enable Execution in script os.chmod(finalFilepostRm, stat.S_IRWXU + stat.S_IRGRP + stat.S_IXGRP + stat.S_IROTH + stat.S_IXOTH); ## Readme donumentation readmeFileDest = self.get_staging_path(pkg_name) + "/usr/share/doc/"+ debianpkg_name + "/README" tools.create_directory_of_file(readmeFileDest) if os.path.exists(base_pkg_path + "/os-Linux/README")==True: tools.copy_file(base_pkg_path + "/os-Linux/README", readmeFileDest) elif os.path.exists(base_pkg_path + "/README")==True: tools.copy_file(base_pkg_path + "/README", readmeFileDest) elif os.path.exists(base_pkg_path + "/README.md")==True: tools.copy_file(base_pkg_path + "/README.md", readmeFileDest) else: debug.info("no file 'README', 'README.md' or 'os-Linux/README' ==> generate an empty one") tmpFile = open(readmeFileDest, 'w') tmpFile.write("No documentation for " + pkg_name + "\n") tmpFile.flush() tmpFile.close() ## licence file license_file_dest = self.get_staging_path(pkg_name) + "/usr/share/doc/"+ debianpkg_name + "/copyright" tools.create_directory_of_file(license_file_dest) if os.path.exists(base_pkg_path + "/license.txt")==True: tools.copy_file(base_pkg_path + "/license.txt", license_file_dest) else: debug.info("no file 'license.txt' ==> generate an empty one") tmpFile = open(license_file_dest, 'w') tmpFile.write("No license define by the developper for " + pkg_name + "\n") tmpFile.flush() tmpFile.close() ##changeLog file change_log_file_dest = self.get_staging_path(pkg_name) + "/usr/share/doc/"+ debianpkg_name + "/changelog" tools.create_directory_of_file(change_log_file_dest) if os.path.exists(base_pkg_path + "/changelog")==True: tools.copy_file(base_pkg_path + "/changelog", change_log_file_dest) else: debug.info("no file 'changelog' ==> generate an empty one") tmpFile = open(change_log_file_dest, 'w') tmpFile.write("No changelog data " + pkg_name + "\n") tmpFile.flush() tmpFile.close() ## create the package : debug.debug("package : " + self.get_staging_path(pkg_name) + "/" + debianpkg_name + ".deb") os.system("cd " + self.get_staging_path("") + " ; dpkg-deb --build " + pkg_name) tools.create_directory_of_file(self.get_final_path()) tools.copy_file(self.get_staging_path("") + "/" + pkg_name + self.suffix_package, self.get_final_path() + "/" + pkg_name + self.suffix_package) # package is done corectly ... tools.file_write_data(build_package_path_done, "done...")
# reject it, wrong start file return None debug.verbose(" ==> '" + base_name[len(__base_element_name):] + "'") return base_name[len(__base_element_name):] def get_element_depend(_path): sys.path.append(os.path.dirname(_path)) name = get_element_name(_path) the_element = __import__(__base_element_name + name) if "depend_on" in dir(the_element): return the_element.depend_on return [] debug.info("======================================================") debug.info("== Create project element") debug.info("======================================================") project_elements = [] for elem in tmp_out: dependency = get_element_depend(elem) name = get_element_name(elem) project_elements.append({ "file": elem, "name": name, "dependency": copy.deepcopy(dependency), "dependency2": copy.deepcopy(dependency) }) debug.info( "--------------------------------------------------------------------------------------------------"
def push_video_file(_path, _basic_key={}): file_name, file_extension = os.path.splitext(_path) debug.info("Send file: '" + file_name + "' with extention " + file_extension) # internal file_extension ... if file_extension == "sha512": debug.verbose("file: '" + _path + "' sha512 extention ...") return True debug.info("Add media : '" + _path + "'") if file_extension[1:] not in ["avi", "mkv", "mov", "mp4", "ts"] \ and file_name not in ["cover_1.jpg","cover_1.png", "cover_1.till", "cover_1.bmp", "cover_1.tga"]: debug.warning("Not send file : " + _path + " Not manage file_extension... " + file_extension) return False if file_name in [ "cover_1.jpg", "cover_1.png", "cover_1.till", "cover_1.bmp", "cover_1.tga" ]: # find a cover... debug.warning("Not send cover Not managed ... : " + _path + " Not manage ...") """ debug.info("Send cover for: " + _basic_key["series-name"] + " " + _basic_key["saison"]); if _basic_key["series-name"] == "": debug.error(" ==> can not asociate at a specific seri"); return False; etk::String groupName = _basic_key["series-name"]; if _basic_key["saison"] != "": groupName += ":" + _basic_key["saison"]; auto sending = _srv.setGroupCover(zeus::File::create(_path.getString(), ""), groupName); sending.onSignal(progressCallback); sending.waitFor(echrono::seconds(20000)); """ return True """ if etk::path::exist(_path + ".sha512") == True: debug.verbose("file sha512 exist ==> read it"); uint64_t time_sha512 = get_modify_time(_path + ".sha512"); uint64_t time_elem = get_modify_time(_path); storedSha512_file = file_read_data(_path + ".sha512") debug.verbose("file sha == " + storedSha512_file); if time_elem > time_sha512: debug.verbose("file time > sha time ==> regenerate new one ..."); # check the current sha512 storedSha512 = calculate_sha512(_path); debug.verbose("calculated new sha'" + storedSha512 + "'"); if storedSha512_file != storedSha512: # need to remove the old sha file auto idFileToRemove_fut = _srv.getId(storedSha512_file).waitFor(echrono::seconds(2)); if idFileToRemove_fut.hasError() == True: debug.error("can not remove the remote file with sha " + storedSha512_file); else: debug.info("Remove old deprecated file: " + storedSha512_file); _srv.remove(idFileToRemove_fut.get()); # note, no need to wait the call is async ... and the user does not interested with the result ... # store new sha512 ==> this update tile too ... file.open(etk::io::OpenMode::Write); file.writeAll(storedSha512); file.close(); else: # store new sha512 /* storedSha512 = file.readAllString(); file.open(etk::io::OpenMode::Read); file.writeAll(storedSha512); file.close(); */ storedSha512 = storedSha512_file; debug.verbose("read all sha from the file'" + storedSha512 + "'"); else: """ """ if True: storedSha512 = calculate_sha512(_path) file_write_data(_path + ".sha512", storedSha512); debug.info("calculate and store sha512 '" + storedSha512 + "'"); debug.info("check file existance: sha='" + storedSha512 + "'"); """ # push only if the file exist """ # TODO : Check the metadata updating ... auto idFile_fut = _srv.getId(storedSha512).waitFor(echrono::seconds(2)); if idFile_fut.hasError() == False: # media already exit ==> stop here ... return True; # TODO: Do it better ==> add the calback to know the push progression ... debug.verbose("Add File : " + _path + " sha='" + storedSha512 + "'"); auto sending = _srv.add(zeus::File::create(_path, storedSha512)); sending.onSignal(progressCallback); debug.verbose("Add done ... now waiting ... "); uint32_t mediaId = sending.waitFor(echrono::seconds(20000)).get(); debug.verbose("END WAITING ... "); if mediaId == 0: debug.error("Get media ID = 0 With no error"); return False; """ mime = magic.Magic(mime=True) mime_type = mime.from_file(_path) headers_values = {'filename': _path, 'mime-type': mime_type} result_send_data = requests.post("http://127.0.0.1:15080/data", headers=headers_values, data=upload_in_chunks(_path, chunksize=4096)) debug.info("result *********** : " + str(result_send_data) + " " + result_send_data.text) file_name = os.path.basename(file_name) debug.info("Find file_name : '" + file_name + "'") # Remove Date (XXXX) or other titreadsofarle file_name, dates = extract_and_remove(file_name, '(', ')') have_date = False have_Title = False for it in dates: if len(it) == 0: continue if it[0] == '0' \ or it[0] == '1' \ or it[0] == '2' \ or it[0] == '3' \ or it[0] == '4' \ or it[0] == '5' \ or it[0] == '6' \ or it[0] == '7' \ or it[0] == '8' \ or it[0] == '9': # find a date ... if have_date == True: debug.info(" '" + file_name + "'") debug.error("Parse Date error : () : " + it + " ==> multiple date") continue have_date = True _basic_key["date"] = it else: if have_Title == True: debug.info(" '" + file_name + "'") debug.error("Parse Title error : () : " + it + " ==> multiple title") continue have_Title = True # Other title _basic_key.set["title2"] = it # Remove the actors [XXX YYY][EEE TTT]... file_name, actors = extract_and_remove(file_name, '[', ']') if len(actors) > 0: debug.info(" '" + file_name + "'") actor_list = [] for it_actor in actors: if actor_list != "": actor_list += ";" actor_list.append(it_actor) _basic_key["actors"] = actor_list list_element_base = file_name.split('-') debug.warning("==> Title file: " + file_name) debug.warning("==> Title cut : " + str(list_element_base)) list_element = [] tmp_start_string = "" iii = 0 while iii < len(list_element_base): if list_element_base[iii][0] != 's' \ and list_element_base[iii][0] != 'e': if tmp_start_string != "": tmp_start_string += '-' tmp_start_string += list_element_base[iii] else: list_element.append(tmp_start_string) tmp_start_string = "" while iii < len(list_element_base): list_element.append(list_element_base[iii]) iii += 1 iii += 1 debug.warning("==> start elem: " + str(tmp_start_string)) if tmp_start_string != "": list_element.append(tmp_start_string) debug.warning("==> list_element : " + str(list_element)) if len(list_element) == 1: # nothing to do , it might be a film ... _basic_key["title"] = list_element[0] else: if len(list_element) > 3 \ and list_element[1][0] == 's' \ and list_element[2][0] == 'e': debug.warning("Parse format: xxx-sXX-eXX-kjhlkjlkj(1234).*") # internal formalisme ... saison = -1 episode = -1 series_name = list_element[0] _basic_key["series-name"] = series_name full_episode_name = list_element[3] for yyy in range(4, len(list_element)): full_episode_name += "-" + list_element[yyy] _basic_key["title"] = full_episode_name if list_element[1][1:] == "XX": # saison unknow ... ==> nothing to do ... #saison = 123456789; pass else: saison = int(list_element[1][1:]) if list_element[2][1:] == "XX": # episode unknow ... ==> nothing to do ... pass else: episode = int(list_element[2][1:]) _basic_key["episode"] = int(episode) debug.info("Find a internal mode series: :") debug.info(" origin : '" + file_name + "'") saisonPrint = "XX" episodePrint = "XX" if saison < 0: # nothing to do pass else: saisonPrint = str(saison) _basic_key["saison"] = saison if episode < 0: # nothing to do pass elif episode < 10: episodePrint = "0" + str(episode) _basic_key["episode"] = episode else: episodePrint = str(episode) _basic_key["episode"] = episode debug.info(" ==> '" + series_name + "-s" + saisonPrint + "-e" + episodePrint + "-" + full_episode_name + "'") elif len(list_element) > 2 \ and list_element[1][0] == 'e': debug.warning("Parse format: xxx-eXX-kjhlkjlkj(1234).*") # internal formalisme ... saison = -1 episode = -1 series_name = list_element[0] _basic_key["series-name"] = series_name full_episode_name = list_element[2] for yyy in range(3, len(list_element)): full_episode_name += "-" + list_element[yyy] _basic_key["title"] = full_episode_name if list_element[1][1:] == "XX": # episode unknow ... ==> nothing to do ... pass else: episode = int(list_element[1][1:]) _basic_key["episode"] = int(episode) debug.info("Find a internal mode series: :") debug.info(" origin : '" + file_name + "'") saisonPrint = "XX" episodePrint = "XX" if episode < 0: # nothing to do pass elif episode < 10: episodePrint = "0" + str(episode) _basic_key["episode"] = episode else: episodePrint = str(episode) _basic_key["episode"] = episode debug.info(" ==> '" + series_name + "-s" + saisonPrint + "-e" + episodePrint + "-" + full_episode_name + "'") result_send_data_json = json.loads(result_send_data.text) debug.info("pared meta data: " + json.dumps(_basic_key, sort_keys=True, indent=4)) data_model = { "type_id": _basic_key["type"], "sha512": result_send_data_json["sha512"], #"group_id": int, "name": _basic_key["title"], # number of second "time": None, } for elem in ["date", "description", "episode" ]: #["actors", "date", "description", "episode", "title2"]: if elem in _basic_key.keys(): data_model[elem] = _basic_key[elem] if "series-name" in _basic_key.keys(): result_group_data = requests.post( "http://127.0.0.1:15080/group/find", data=json.dumps({"name": _basic_key["series-name"]}, sort_keys=True, indent=4)) debug.info("Create group ??? *********** : " + str(result_group_data) + " " + result_group_data.text) if result_group_data.status_code == 404: result_group_data = requests.post( "http://127.0.0.1:15080/group", data=json.dumps({"name": _basic_key["series-name"]}, sort_keys=True, indent=4)) debug.info("yes we create new group *********** : " + str(result_group_data) + " " + result_group_data.text) group_id = result_group_data.json()["id"] data_model["group_id"] = group_id if "saison" in _basic_key.keys(): result_saison_data = requests.post( "http://127.0.0.1:15080/saison/find", data=json.dumps( { "number": _basic_key["saison"], "group_id": group_id }, sort_keys=True, indent=4)) debug.info("Create saison ??? *********** : " + str(result_saison_data) + " " + result_saison_data.text) if result_saison_data.status_code == 404: result_saison_data = requests.post( "http://127.0.0.1:15080/saison", data=json.dumps( { "number": _basic_key["saison"], "group_id": group_id }, sort_keys=True, indent=4)) debug.info("yes we create new saison *********** : " + str(result_saison_data) + " " + result_saison_data.text) saison_id = result_saison_data.json()["id"] data_model["saison_id"] = saison_id result_send_data = requests.post("http://127.0.0.1:15080/video", data=json.dumps(data_model, sort_keys=True, indent=4)) debug.info("result *********** : " + str(result_send_data) + " " + result_send_data.text) return True
return True elif argument.get_option_name() == "folder": folder = argument.get_arg() return True elif argument.get_option_name() == "action": global requestAction requestAction = argument.get_arg() return True return False # parse default unique argument: for argument in local_argument: parse_arg(argument) debug.info("==================================") debug.info("== ZEUS test client start ==") debug.info("==================================") def show_video(elem_video_id, indent): indent_data = "" while indent > 0: indent_data += "\t" indent -= 1 result_video = requests.get("http://127.0.0.1:15080/video/" + str(elem_video_id) + "") if result_video.status_code == 200: video = result_video.json() debug.info(indent_data + "- " + str(video["generated_name"])) else:
def __init__(self, name, config, arch): if tools.get_type_string(name) != "list": debug.error("You must define a name in a list ...") if len(name) < 1: debug.error("You must define a name for your target ...") ## configuration of the build self.config = config if self.config["bus-size"] == "auto": debug.error("system error ==> must generate the default 'bus-size' config") if self.config["arch"] == "auto": debug.error("system error ==> must generate the default 'bus-size' config") debug.debug("config=" + str(config)) if arch != "": self.arch = "-arch " + arch else: self.arch = "" self.end_generate_package = config["generate-package"] # todo : remove this : self._name = name[-1] self._config_based_on = name debug.info("================================="); debug.info("== Target='" + self._name + "' " + self.config["bus-size"] + " bits for arch '" + self.config["arch"] + "'"); debug.info("== Target list=" + str(self._config_based_on)) debug.info("================================="); self.set_cross_base() ############################################################################### # Target global variables. ############################################################################### self.global_include_cc=[] self.global_flags={} self.global_libs_ld=[] self.global_libs_ld_shared=[] self.suffix_cmd_line='.cmd' self.suffix_warning='.warning' self.suffix_dependence='.d' self.suffix_obj='.o' self.prefix_lib='lib' self.suffix_lib_static='.a' self.suffix_lib_dynamic='.so' self.suffix_binary='' self.suffix_package='.deb' self.path_generate_code="/generate_header" self.path_arch = "/" + self._name for elem in self._config_based_on: self.add_flag("c", '-D__TARGET_OS__' + elem) self.add_flag("c", [ '-D__TARGET_ARCH__' + self.config["arch"], '-D__TARGET_ADDR__' + self.config["bus-size"] + 'BITS', '-D_REENTRANT' ]) if self.config["compilator"] == "clang" \ and self.xx_version >= 4002001: # >= 4.2.1 self.add_flag("c++", "-Wno-undefined-var-template") self.add_flag("c", "-nodefaultlibs") self.add_flag("c++", "-nostdlib") # this disable the need to have the __cxa_guard_release self.add_flag("c++", "-fno-threadsafe-statics") #self.add_flag("c", "-nostdinc") #ignores standard C include directories #self.add_flag("c++", "-nostdinc++") #ignores standard C++ include directories self.add_flag("ar", 'rcs') if self._name == "Windows": self.add_flag("c++", [ '-static-libgcc', '-static-libstdc++' ]) if "debug" == self.config["mode"]: self.add_flag("c", [ "-g", "-DDEBUG" ]) if env.get_force_optimisation() == False: self.add_flag("c", "-O0") else: self.add_flag("c", "-O3") else: self.add_flag("c", [ "-DNDEBUG", "-O3" ]) ## To add code coverate on build result system if self.config["gcov"] == True: if self.config["compilator"] == "clang": self.add_flag("c", [ "--coverage" ]) self.add_flag("link", [ "--coverage" ]) else: self.add_flag("c", [ "-fprofile-arcs", "-ftest-coverage" ]) self.add_flag("link", [ "-lgcov", "--coverage" ]) self._update_path_tree() self.path_bin="bin" self.path_lib="lib" self.path_data="share" self.path_doc="doc" self.path_include="include" self.path_temporary_generate="generate" self.path_object="obj" self.build_done=[] self.build_tree_done=[] self.module_list=[] # output staging files list : self.list_final_file=[] self.sysroot="" self.action_on_state={} # set some default package path self.pkg_path_version_file = "version.txt" self.pkg_path_maintainer_file = "maintainer.txt" self.pkg_path_application_name_file = "appl_name.txt" self.pkg_path_application_description_file = "appl_description.txt" self.pkg_path_readme_file = "readme.txt" self.pkg_path_change_log_file = "changelog.txt" # special case for IOS (example) no build dynamicly ... self.support_dynamic_link = True
def show_log(self, pkg_name): debug.debug("------------------------------------------------------------------------") debug.info("-- Show log logcat '" + pkg_name + "'") debug.debug("------------------------------------------------------------------------") debug.error("action not implemented ...")
def run(self, pkg_name, option_list, binary_name = None): debug.debug("------------------------------------------------------------------------") debug.info("-- Run package '" + pkg_name + "' + option: " + str(option_list)) debug.debug("------------------------------------------------------------------------") debug.error("action not implemented ...")
def un_install_package(self, pkg_name): debug.debug("------------------------------------------------------------------------") debug.info("Un-Install package '" + pkg_name + "'") debug.debug("------------------------------------------------------------------------") os.system("sudo dpkg -r " + self.get_final_path() + "/" + pkg_name + self.suffix_package)
add_interface(data_global_elements.API_TYPE) add_interface(data_global_elements.API_GROUP) add_interface(data_global_elements.API_SAISON) add_interface(data_global_elements.API_VIDEO) import api.root as api_root api_root.add(app) import api.type as api_type api_type.add(app, data_global_elements.API_TYPE) import api.group as api_group api_group.add(app, data_global_elements.API_GROUP) import api.saison as api_saison api_saison.add(app, data_global_elements.API_SAISON) import api.video as api_video api_video.add(app, data_global_elements.API_VIDEO) import api.data as api_data api_data.add(app, data_global_elements.API_DATA) if __name__ == "__main__": debug.info("Start REST application: " + str(app.config['REST_HOST']) + ":" + str(app.config['REST_PORT'])) app.config.REQUEST_MAX_SIZE = 10 * 1024 * 1024 * 1024 app.run(host=app.config['REST_HOST'], port=int(app.config['REST_PORT'])) debug.info("END program") sys.exit(0)