def downloadPackage(proj=None): print "Starting to download %s" %proj lines = [] rpm = None if proj and proj in c.PKGS.keys(): idNum = c.PKGS[proj] for line in commands.getoutput(''.join(['curl ', c.SITE, idNum])).split('\n'): if line.find('buildinfo') > 0 or line.find('complete.png') > 0: if line.find('complete.png') > 0: break rpm = line.split('>')[2].split('<')[0] majorVer = rpm.split('-')[-2:-1][0] minorVer = rpm.split('-')[-1:][0] src = 'src' POSTFIX = '/x86_64/' noarch = 'noarch' if proj in ('dracut','gpxe','perl-Net-Telnet', 'vgabios','pexpect','python-suds', 'spice-protocol'): url = ''.join([c.BASE,proj,'/',majorVer,'/',minorVer,'/',src]) cmd = ['wget', '-r', '-l1', '-H', '-t1', '-nd', '-N', '-q','-np', '-A.rpm', '-erobots=off', url, '--directory-prefix=/root/rpmbuild/RPMS/x86_64'] return utils.execCommand(cmd) elif proj in ('sgabios-bin','seabios-bin'): url = ''.join([c.BASE,proj,'/',majorVer,'/',minorVer,'/',noarch]) cmd = ['wget', '-r', '-l1', '-H', '-t1', '-nd', '-N', '-q','-np', '-A.rpm', '-erobots=off', url, '--directory-prefix=/root/rpmbuild/RPMS/x86_64'] else: url = ''.join([c.BASE,proj,'/',majorVer,'/',minorVer,'/',POSTFIX]) cmd = ['wget', '-r', '-l1', '-H', '-t1', '-nd', '-N', '-q','-np', '-A.rpm', '-erobots=off', url, '--directory-prefix=/root/rpmbuild/RPMS/x86_64'] return utils.execCommand(cmd)
def createRepo(): try: if len(os.listdir(c.DIRS[8])) > 0: print "Current repo '%s' is not empty - delelting old files" % c.DIRS[8] for pkg in os.listdir(c.DIRS[8]): cwd = c.DIRS[8] cmd = ['rm', '-rf', pkg] if not utils.execCommand(cmd, cwd): print "createRepo: return since utils.execCommand exit with non positive value" pkgIndex = buildPackageIndex() if pkgIndex and len(pkgIndex) > 0: print "Creating RPM repository under %s" % c.DIRS[8] for pkg in pkgIndex.values(): cmd = ['cp', pkg, c.DIRS[8]] if not utils.execCommand(cmd): print "utils.execCommands: utils.execCommand return False" return False else: print "No rpms found under %s" % ' and '.join([c.DIRS[9],c.DIRS[10]]) sys.exit(1) if os.path.exists(c.DIRS[8]) and len(os.listdir(c.DIRS[8])) > 0: cmd = ['createrepo', c.DIRS[8]] if not utils.execCommand(cmd): print "utils.execCommands: utils.execCommand return False" return False else: print "Restarting httpd service" cmd = ['/etc/init.d/httpd', 'restart'] if not utils.execCommand(cmd): print "utils.execCommands: utils.execCommand return False" return False except OSError: pass
def move_clear(path,outpath): if not path: print 'no ipa path ,resign error' raise Exception('no ipa path ,resign error') dir_path =os.path.split(path)[0] output_path =str(outpath)+'.ipa' command = 'mv -f '+path +' '+output_path if utils.execCommand(command): raise Exception('move ipa fail into'+output_path) command = 'rm -rf '+dir_path if utils.execCommand(command): raise Exception('remove temp dir fail')
def getEntitlements_plist(path,appath): temp_path =os.path.split(appath)[0] provision_path =os.path.join(temp_path,'mobileprovision.plist') execStr ='security cms -D -i '+path+' >'+provision_path ret = utils.execCommand(execStr) if ret: raise Exception(execStr+'command error') entitlements_path =os.path.join(temp_path,'entitlements.plist') execStr ="/usr/libexec/PlistBuddy -x -c 'Print:Entitlements' "+provision_path+'>'+entitlements_path ret =utils.execCommand(execStr) if ret: raise Exception(execStr+'command error') os.remove(provision_path) if os.path.exists(entitlements_path): return entitlements_path
def deployRepoToHost(hosts=None): if hosts: hosts = hosts.split(',') else: hosts = c.HOSTS for host in hosts: cmd = ['scp', createRepoFile(), 'root@'+host+':/etc/yum.repos.d/'] if not utils.execCommand(cmd): print "deployRepoToHost: return since utils.execCommand exit with non positive value"
def deployRepoToHost(hosts=None): if hosts: hosts = hosts.split(',') else: hosts = c.HOSTS for host in hosts: cmd = ['scp', createRepoFile(), 'root@' + host + ':/etc/yum.repos.d/'] if not utils.execCommand(cmd): print "deployRepoToHost: return since utils.execCommand exit with non positive value"
def downloadPackage(proj=None): print "Starting to download %s" % proj lines = [] rpm = None if proj and proj in c.PKGS.keys(): idNum = c.PKGS[proj] for line in commands.getoutput(''.join(['curl ', c.SITE, idNum])).split('\n'): if line.find('buildinfo') > 0 or line.find('complete.png') > 0: if line.find('complete.png') > 0: break rpm = line.split('>')[2].split('<')[0] majorVer = rpm.split('-')[-2:-1][0] minorVer = rpm.split('-')[-1:][0] src = 'src' POSTFIX = '/x86_64/' noarch = 'noarch' if proj in ('dracut', 'gpxe', 'perl-Net-Telnet', 'vgabios', 'pexpect', 'python-suds', 'spice-protocol'): url = ''.join([c.BASE, proj, '/', majorVer, '/', minorVer, '/', src]) cmd = [ 'wget', '-r', '-l1', '-H', '-t1', '-nd', '-N', '-q', '-np', '-A.rpm', '-erobots=off', url, '--directory-prefix=/root/rpmbuild/RPMS/x86_64' ] return utils.execCommand(cmd) elif proj in ('sgabios-bin', 'seabios-bin'): url = ''.join( [c.BASE, proj, '/', majorVer, '/', minorVer, '/', noarch]) cmd = [ 'wget', '-r', '-l1', '-H', '-t1', '-nd', '-N', '-q', '-np', '-A.rpm', '-erobots=off', url, '--directory-prefix=/root/rpmbuild/RPMS/x86_64' ] else: url = ''.join( [c.BASE, proj, '/', majorVer, '/', minorVer, '/', POSTFIX]) cmd = [ 'wget', '-r', '-l1', '-H', '-t1', '-nd', '-N', '-q', '-np', '-A.rpm', '-erobots=off', url, '--directory-prefix=/root/rpmbuild/RPMS/x86_64' ] return utils.execCommand(cmd)
def post(self): if self.arguments: api_logger.info("HEADERS: " + str(self.request)) # Parse each param data = self.arguments if "name" not in list(data.keys()) and "lines" not in list(data.keys()): api_logger.error("Error requests params.") self.finish('{"result":"error","description":"Error requests params"}') else: try: t_name = data["name"] except Exception as e: api_logger.error("Error requests params " + str(e)) self.finish('{"result":"error","description":"Error requests params","debug":"' + str(e) + '"}') # <STORM_PATH>/storm/bin/storm list cmd_launch = options.storm_binary + " list" cmd = utils.execCommand(cmd_launch) # Get output and error (output, err) = cmd.execute() if err: api_logger.error("Error getting topology list. " + str(err)) self.finish( '{"result":"error","description":"Error getting topology list","detail":"' + str(err) + '"}' ) elif output: api_logger.debug("Command output: " + str(output)) notFound = False topoState = "" for line in output.splitlines(): if t_name in line: notFound = True try: api_logger.info("Found Topology") api_logger.debug(line.split(" ")) for aux in line.split(" "): if aux != "" and aux != t_name: api_logger.info("Status found: " + str(aux)) topoState = aux break except Exception as e: api_logger.error("Error parsing errors from output. " + str(e)) pass if not notFound: api_logger.error("Topology not found.") self.finish('{"result":"error","description":"Topology not found"}') elif notFound: api_logger.info("Topology Status. " + str(topoState)) self.finish( '{"result":"success","description":"Topology Status", "detail":"' + str(topoState) + '"}' ) else: api_logger.error("Something was wrong.") self.finish('{"result":"error","description":"Something was wrong"}') else: api_logger.error("Content-Type:application/json missing") self.finish('{"result":"error","description":"Content-Type:application/json missing"}')
def get_app_path(path,root_path): temp_path =os.path.join(root_path,'Library','AutoPack/temp') if not os.path.exists(temp_path): command ='mkdir -p '+temp_path utils.execCommand(command) else: for files in os.listdir(temp_path): command ='rm -rf '+os.path.join(temp_path,files) utils.execCommand(command) print 'start copy app into %s' % temp_path command = "cp -R " + path + " " +temp_path if utils.execCommand(command): raise Exception('copy app fail into '+temp_path) tempo_filename =os.path.split(path)[1] if os.path.splitext(tempo_filename)[1]=='.ipa': command ='unzip -q -o '+os.path.join(temp_path,tempo_filename) +' -d '+temp_path ret =utils.execCommand(command) if ret: print 'unzip fail' raise Exception('copy app fail into '+temp_path) if not os.path.exists(os.path.join(temp_path,'Payload')): print 'not Payload dir' raise Exception('not Payload dir') else: command ='rm -rf '+os.path.join(temp_path,tempo_filename) if utils.execCommand(command): raise Exception('remove temp ipa fail') print 'delete temp ipa file success' for files in os.listdir(os.path.join(temp_path,'Payload')): if not os.path.splitext(files)[1]=='.app': continue command ='mv '+os.path.join(temp_path,'Payload',files)+' '+temp_path ret =utils.execCommand(command) if ret: print 'move file fail' raise Exception('move file fail') command ='rm -rf '+os.path.join(temp_path,'Payload') if utils.execCommand(command): raise Exception('remove null Payload dir fail') return os.path.join(temp_path,files) else: return os.path.join(temp_path,tempo_filename)
def cleanRepo(): cmd = ['service', 'httpd', 'stop'] if not utils.execCommand(cmd): print "cleanRepo: return since utils.execCommand exit with non positive value" return False pkgIndex = buildPackageIndex() if len(pkgIndex.values()) > 0: for pkg in pkgIndex.values(): cmd = ['rm', '-rf', pkg] if not utils.execCommand(cmd): print "cleanRepo: return since utils.execCommand exit with non positive value" return False path = c.DIRS[8] for link in glob.glob(path + '*.tar.gz'): if os.path.exists(link): cmd = ['unlink', link] if not utils.execCommand(cmd): print "cleanRepo: return since utils.execCommand exit with non positive value" return False return True
def cleanRepo(): cmd = ['service', 'httpd', 'stop'] if not utils.execCommand(cmd): print "cleanRepo: return since utils.execCommand exit with non positive value" return False pkgIndex = buildPackageIndex() if len(pkgIndex.values()) > 0: for pkg in pkgIndex.values(): cmd = ['rm', '-rf', pkg] if not utils.execCommand(cmd): print "cleanRepo: return since utils.execCommand exit with non positive value" return False path = c.DIRS[8] for link in glob.glob(path+'*.tar.gz'): if os.path.exists(link): cmd = ['unlink', link] if not utils.execCommand(cmd): print "cleanRepo: return since utils.execCommand exit with non positive value" return False return True
def installNeededPackages(): to_install = [] for pkg in c.NEEDED_PCKGS: o = commands.getoutput('rpm -q %s' % pkg) if 'not installed' in o: to_install.append(pkg) if to_install: print "Installing Needed packages:\n%s" % ', '.join(to_install) cmd = ['/usr/bin/yum', 'install', '-y'] + to_install if not utils.execCommand(cmd): print "installNeededPackages: return since utils.execCommand exit with non positive value" return False
def installNeededPackages(): to_install = [] for pkg in c.NEEDED_PCKGS: o = commands.getoutput('rpm -q %s' % pkg) if 'not installed' in o: to_install.append(pkg) if to_install: print "Installing Needed packages:\n%s" %', '.join(to_install) cmd = ['/usr/bin/yum', 'install', '-y'] + to_install if not utils.execCommand(cmd): print "installNeededPackages: return since utils.execCommand exit with non positive value" return False
def refreshGitRepo(projList=None, exclude=[]): gitStatus = {} if not exclude: exclud = [] if projList: projList = projList.split(',') else: projList = c.PROJECT_DICT.keys() for name, build in c.PROJECT_DICT.iteritems(): if build['buildFromGit'] == 'yes' and name in projList: if name not in exclude: try: git = c.PROJECT_DICT[name] path = git['dir'] cmd = ['git', 'stash'] utils.execCommand(cmd, path) cmd = ['git', 'pull'] utils.execCommand(cmd, path) gitStatus[name] = 'updated' except OSError: print "ERROR: Unable to refresh GIT repos; consider running --build-git first" sys.exit(1) return gitStatus
def createRepo(): try: if len(os.listdir(c.DIRS[8])) > 0: print "Current repo '%s' is not empty - delelting old files" % c.DIRS[ 8] for pkg in os.listdir(c.DIRS[8]): cwd = c.DIRS[8] cmd = ['rm', '-rf', pkg] if not utils.execCommand(cmd, cwd): print "createRepo: return since utils.execCommand exit with non positive value" pkgIndex = buildPackageIndex() if pkgIndex and len(pkgIndex) > 0: print "Creating RPM repository under %s" % c.DIRS[8] for pkg in pkgIndex.values(): cmd = ['cp', pkg, c.DIRS[8]] if not utils.execCommand(cmd): print "utils.execCommands: utils.execCommand return False" return False else: print "No rpms found under %s" % ' and '.join( [c.DIRS[9], c.DIRS[10]]) sys.exit(1) if os.path.exists(c.DIRS[8]) and len(os.listdir(c.DIRS[8])) > 0: cmd = ['createrepo', c.DIRS[8]] if not utils.execCommand(cmd): print "utils.execCommands: utils.execCommand return False" return False else: print "Restarting httpd service" cmd = ['/etc/init.d/httpd', 'restart'] if not utils.execCommand(cmd): print "utils.execCommands: utils.execCommand return False" return False except OSError: pass
def cut_image_py(icon_path,path,current_path): tempath =os.path.split(path)[0] ret = fileutils.copyFile(icon_path,os.path.join(tempath,'icon.png')) if ret: return ret print 'copy icon into %s success' %tempath command ='python '+os.path.join(current_path,'modify_icon.py')+' '+os.path.join(tempath,'icon.png') ret =utils.execCommand(command) if ret: print 'cut image fail' return ret icon_arr_path =os.path.join(tempath,'icon') modifyIcon(icon_arr_path,appPath) print 'modify icon success' #修改icon成功,开始清除中途产生的资源 fileutils.clearDir(icon_arr_path) os.rmdir(icon_arr_path) os.remove(os.path.join(tempath,'icon.png'))
def createRepoFile(): repoFile = ''.join([c.REPO_PATH,c.REPO_NAME]) if os.path.exists(repoFile): cmd = ['rm', '-rf', repoFile] if not utils.execCommand(cmd): print "createRepoFile: return since utils.execCommand exit with non positive value" sys.exit(1) f = open(repoFile ,'a') part1 = "^name=Fedora $releasever - $basearch^baseurl=http://" hostname = commands.getoutput('hostname') ipaddr = commands.getoutput('ifconfig').split('inet addr:')[1].split(' ')[0] part2 = "^enabled=1^gpgcheck=0" config = ''.join(['[',c.REPO_NAME.split('.')[0] ,']', part1, ipaddr, '/' ,c.DIRS[8].split('/')[4], part2]) parsedConfig = config.split('^') for line in parsedConfig: f.write(line) f.write('\n') f.close return repoFile
def createRepoFile(): repoFile = ''.join([c.REPO_PATH, c.REPO_NAME]) if os.path.exists(repoFile): cmd = ['rm', '-rf', repoFile] if not utils.execCommand(cmd): print "createRepoFile: return since utils.execCommand exit with non positive value" sys.exit(1) f = open(repoFile, 'a') part1 = "^name=Fedora $releasever - $basearch^baseurl=http://" hostname = commands.getoutput('hostname') ipaddr = commands.getoutput('ifconfig').split('inet addr:')[1].split( ' ')[0] part2 = "^enabled=1^gpgcheck=0" config = ''.join([ '[', c.REPO_NAME.split('.')[0], ']', part1, ipaddr, '/', c.DIRS[8].split('/')[4], part2 ]) parsedConfig = config.split('^') for line in parsedConfig: f.write(line) f.write('\n') f.close return repoFile
def recursive_file(path): sign_arr_suffix =[".dylib",".so",".0",".vis",".pvr",".framework",".appex",".app"] for files in os.listdir(path): files_path =os.path.join(path,files) #取应该签名的文件 if os.path.splitext(files)[1] in sign_arr_suffix: sign_arr.append(files_path) print 'found file need resign %s' %sign_arr #删除CodeResources文件 if os.path.split(files_path)[1]=='CodeResources': _CodeResources =os.path.split(files_path)[0] print 'will delete _CodeResources %s' %_CodeResources command = "rm -r " +_CodeResources if utils.execCommand(command): raise Exception('remove _CodeResources dir fail') if os.path.exists(_CodeResources): print 'delete _CodeSignature dir failed' raise Exception('remove _CodeResources dir fail') else: print 'delete _CodeSignature dir success' if os.path.isdir(files_path): recursive_file(files_path)
def post(self): if self.arguments: api_logger.info("HEADERS: "+str(self.request)) # Parse each param data = self.arguments if 'name' not in list(data.keys()) or 'type' not in list(data.keys()) or 'lang' not in list(data.keys()): api_logger.error("Error requests params") self.finish('{"result":"error","description":"Error requests params"}') else: try: t_name = data['name'] t_type = data['type'] t_lang = data['lang'] t_gist = data['gist'] except Exception as e: api_logger.error("Error requests params "+str(e)) self.finish('{"result":"error","description":"Error requests params","debug":"'+str(e)+'"}') # Create working dir try: workingPath = "/var/storm/src/sinfonier_backend"+str(int(time.time()+randint(50,150))) shutil.copytree(options.backend_working_path,workingPath) except Exception as e: api_logger.error("Error creating working dir. "+str(e)) self.finish('{"result":"error","description":"Error creating working dir","debug":"'+str(e)+'"}') # Change routes java_path_drains = workingPath+"/src/jvm/com/sinfonier/drains/" java_path_bolts = workingPath+"/src/jvm/com/sinfonier/bolts/" java_path_spouts = workingPath+"/src/jvm/com/sinfonier/spouts/" api_logger.info("New paths: "+java_path_drains+" - "+java_path_bolts+" - "+java_path_spouts) fileCfileCreatedreated = True # Get code from gist and write it util = Utils() # Check module type if t_type == "drain": dst_path = java_path_drains elif t_type == "bolt": dst_path = java_path_bolts elif t_type == "spout": dst_path = java_path_spouts else: shutil.rmtree(workingPath) api_logger.error("Module type must be spout/bolt/drain. Deleted working repo.") self.finish('{"result":"error","description":"Module type must be spout/bolt/drain"}') # Check module language. If Python or Ruby (soon) change path if t_lang == "python": dst_path = workingPath+"/multilang/resources/" module_lang = "py" elif t_lang == "java": module_lang = "java" elif t_lang == "ruby": shutil.rmtree(workingPath) api_logger.error("Ruby not supported yet. Deleted working repo.") self.finish('{"result":"error","description":"Ruby not supported yet"}') else: shutil.rmtree(workingPath) api_logger.error("Language must be supported. Current Python and Java. Deleted working repo.") self.finish('{"result":"error","description":"Language must be supported. Current Python and Java"}') try: api_logger.info("Get module.") fileName = util.get_module(t_name,module_lang,t_gist,dst_path,t_type) api_logger.info("Module Added: "+str(fileName)) fileCreated = True except Exception as e: shutil.rmtree(workingPath) api_logger.error("Error creating source code file. Deleted working repo. "+str(e)) self.finish('{"result":"error","description":"Error creating file","debug":"'+str(e)+'"}') fileCreated = False if fileCreated: # Regenerate jar on /var/storm/lastjar/ # <MAVEN_PATH>/maven/bin/mvn -f <SINFONIER_BACKEND_PATH>/pom.xml compile cmd_launch = options.maven_binary+" -f "+workingPath+"/pom.xml"+" compile" cmd = utils.execCommand(cmd_launch) # Get output and error (output, err) = cmd.execute() if err: shutil.rmtree(workingPath) api_logger.error("Error compiling jar file. Deleted working repo. "+str(err)) self.finish('{"result":"error","description":"Error compiling jar file", "detail":"'+str(err)+'"}') elif output: api_logger.debug("Command output: "+str(output)) errorDebug = False warDebug = False dedugStack = "" warStack = "" fDate = "" for line in output.splitlines(): if "ERROR" in line and t_name in line: try: api_logger.info("Found ERROR") dedugStack += time.strftime("%m-%d-%Y %H:%M:%S")+": " dedugStack += line.split("com/sinfonier")[1] dedugStack += "|" except Exception as e: api_logger.error("Error parsing errors from output. "+str(e)) pass if "BUILD FAILURE" in line: api_logger.info("Found BUILD FAUILURE") errorDebug = True if "WARNING" in line and t_name in line: try: api_logger.info("Found WARNING") warDebug = True warStack += time.strftime("%m-%d-%Y %H:%M:%S")+": " warStack += line.split("com/sinfonier")[1] warStack += "|" except Exception as e: api_logger.error("Error parsing errors from output. "+str(e)) pass if "Finished at:" in line: api_logger.info("Store Finished time") fDate = line shutil.rmtree(workingPath) if errorDebug: api_logger.error("Error compiling module. "+str(dedugStack)) self.finish('{"result":"error","description":"Error compiling...", "detail":"'+str(dedugStack)+'"}') elif warDebug: api_logger.info("Warning during compiling. "+str(warStack)) self.finish('{"result":"warning","description":"Warning during compiling", "detail":"'+str(warStack)+'"}') else: api_logger.info("Module compiled. "+str(fDate)) self.finish('{"result":"success","description":"Module compiled", "detail":"'+str(fDate)+'"}') else: api_logger.error("Content-Type:application/json missing") self.finish('{"result":"error","description":"Content-Type:application/json missing"}')
def modifyPlist(key,value,appPath): plistPath = os.path.join(appPath,'Info.plist') command ="/usr/libexec/PlistBuddy -c 'Set :"+key+" "+value+"'"+' '+plistPath return utils.execCommand(command)
def Build(runPath, toolPath, buildType, configName=None): configFile = os.path.join(runPath, "config/config.json") if configName: configFile = os.path.join(runPath, "config", configName) if not os.path.exists(configFile): print "Error! no config file, path: %s" % configFile return config = Configer() # load the config.json config.loadConfig(configFile, toolPath) # new project path oldProjPath = config.getProjPath() if not os.path.exists(oldProjPath): print "Error! no project path, please set in config.json" return oldProjPath = os.path.abspath(oldProjPath) oldProjDirName = os.path.basename(oldProjPath) print "[oldProjDirName:]", oldProjDirName buildPath = os.path.abspath(oldProjPath + "./../") print "[buildPath:]", buildPath baseProjDirName = oldProjDirName packageName = "" destDir = "" # copy to new channel_sdk dir channelSdks = config.getChannels() print("channelSdks = %s\n" % channelSdks) for sdk in channelSdks: destPath = os.path.join(buildPath, baseProjDirName + "_" + sdk) if os.path.exists(destPath): fileutils.clearDir(destPath) # copy Xcode Project fileutils.copyFiles(oldProjPath, destPath) index = sdk.find("_") if index != -1: parentSdk = sdk[0:index] print "parentSdk:" + parentSdk else: parentSdk = sdk # srcSdkDir is usually in: aonesdk/export/ios/sdks/sdkName srcSdkDir = config.getSdkDir(parentSdk) # srcSdkConfigDir is usually in:`autopack_lzws/ios/sdks/sdkName` for example srcSdkConfigDir = config.getSdkConfigDir(sdk) sdkConfigFile = os.path.join(srcSdkConfigDir, "config.json") # copy src sdk to the auto project print "-----[begin copy src sdk to the autopackage project]-----\n" print("srcSdkDir=%s\n" % srcSdkDir) fileutils.copyFiles(srcSdkDir, srcSdkConfigDir) print("srcSdkConfigDir=%s\n" % srcSdkConfigDir) if os.path.exists(sdkConfigFile): sdkConfig = copy.deepcopy(config) sdkConfig.loadConfig(sdkConfigFile, None) else: sdkConfig = config # load ForXcode.json ret = xcodeutils.loadForXcodeConfigFile( sdk, os.path.join(srcSdkConfigDir, "ForXcode.json")) if ret: print "[ %s ] Error! no file ForXcode.json!" % sdk return # copy resource files to Xcode Project xcodeProjPath = os.path.join(destPath, config.getXcodeProjPath()) print "[xcode proj path is ] = %s\n" % xcodeProjPath xcodeProjDir = os.path.dirname(xcodeProjPath) # load Xcode Project project = XcodeProject.load( os.path.join(xcodeProjPath, "project.pbxproj")) if project == None: print "load xcode project fail" return print "-----[begin copy SdkFiles to proj]-----\n" ret = xcodeutils.copySdkFilesToProj(sdk, srcSdkConfigDir, xcodeProjDir, project, buildPath, config) if ret: print "[ %s ] Error! copy sdk files to xcode project" % sdk return # modify info.plist according to ForXcode.json print "-----[begin modify info.plist]-----\n" ret = xcodeutils.modifyInfoPlist(sdk, srcSdkConfigDir, xcodeProjDir, project) if ret: print "[ %s ] Error! modify info.plist files to xcode project" % sdk return #copy icon and logo print "-----[begin copy icon and logo]-----\n" xcodeutils.modifyIconAndLogo(sdk, project, xcodeProjDir, config) # modify icon print "-----[begin modify icon]-----\n" ret = xcodeutils.modifyIcon(sdk, srcSdkConfigDir, xcodeProjDir, project) if ret: print "[ %s ] Error! modify icon" % sdk return # modify splash print "-----[begin modify splash]-----\n" if sdkConfig.getHasSplash() == "True": xcodeutils.modifySplash(sdk, srcSdkConfigDir, xcodeProjDir, project, sdkConfig.getAppOrientation()) # run special script print "-----[begin run special]-----\n" ret = runSpecial(sdk, srcSdkConfigDir, xcodeProjDir, sdkConfigFile, project) if ret: return # add sdks to channel print "-----[add sdks to channel]-----\n" ret = addSdksToChannel(parentSdk, xcodeProjDir, config, project, buildPath) if ret: return # modify general settings, like displayName ,versionNumber, buildNumber,BundleID ... xcodeutils.modifyGeneralSetting(sdk, xcodeProjDir, project, config) # modity package settings, like developemntTeam , codeSign, profileSpecifier .... xcodeutils.modifyPackageSettings(sdk, project, config) # save the Xcode project project.save() # build print "-----[begin build xcodeproject]-----\n" os.chdir(xcodeProjDir) #change the workspace buildConfig = config.getBuildConfig() productName = xcodeutils.getProductName(project) print "[xcode prodcut name ] = %s\n" % productName if buildType == "Dev": signId = config.getSignId_dev() profileSpecifier = config.getProfileSpcifier_dev() else: signId = config.getSignId() profileSpecifier = config.getProfileSpecifier() command = 'xcodebuild -sdk iphoneos -configuration ' + buildConfig + ' CODE_SIGN_IDENTITY="' + signId + '"' + ' PROVISIONING_PROFILE_SPECIFIER="' + profileSpecifier + '"' # command = 'xcodebuild -sdk iphoneos -configuration ' + buildConfig + ' CODE_SIGN_IDENTITY="' + signId + '"' + ' PROVISIONING_PROFILE="' + provisionFile + '"' + ' PROVISIONING_PROFILE_SPECIFIER="' + privisioningProfileSpecifier + '"' ret = utils.execCommand(command) if ret: return ret ''' appPath = subpackage.getAppPath('/Users/lastYear/Desktop/autopack_lzws/ios/build') subpackage.modifyConfig('td_appid','1234455',appPath) subpackage.modifyConfig('td_channel','1234455',appPath) name ='吕布无双斩' subpackage.modifyPlist('CFBundleDisplayName',name,appPath) iconpath = '/Users/lastYear/Desktop/icon/logo/lbwsz' subpackage.modifyIcon(iconpath,appPath) subpackage.modifyIcon('/Users/lastYear/Desktop/icon/lbwsz',appPath) print 'TEST END\n' command = 'xcrun -sdk iphoneos PackageApplication -v ' +appPath +' -o '+'/Users/lastYear/Desktop/autopack_lzws/ios/build/temp/sub.ipa' ret = utils.execCommand(command) if ret: return ret ''' appName = config.getDisplayName() command = 'xcrun -sdk iphoneos PackageApplication -v "' + xcodeProjDir + '/build/' + buildConfig + '-iphoneos/' \ + productName + '.app" -o "' + destPath + '/' + appName + "_" +buildType + '.ipa"' ret = utils.execCommand(command) if ret: return ret
def re_sign(appPath,certificateName,provisonpath): #证书名 # codeSign ='' #配置文件路径 mobileprovision_path =provisonpath #授权文件路径 entitlements_path ='' certificateName =certificateName.replace('kongge',' ') certificateName =certificateName.replace('kuohao','(') certificateName =certificateName.replace('fankuoshao',')') print 'certificate name :%s\n' %certificateName if os.path.exists(mobileprovision_path): ret =fileutils.copyFile(mobileprovision_path,os.path.join(appPath,'embedded.mobileprovision')) if ret: raise Exception('copy embedded.mobileprovision faid into'+appPath) print 'replace mobileprovision file success' else: print 'mobileprovision file don\'t exist' raise Exception('mobileprovision file don\'t exist') #生成getEntitlements_plist文件 entitlements_path=getEntitlements_plist(mobileprovision_path,appPath) if entitlements_path: print 'generate entitlements.plist success,path:%s' %entitlements_path else: raise Exception('generate entitlements.plist error') #修改bundleid appIdentifier =getAppIdentifier(entitlements_path) if appIdentifier: ret =modifyPlist('CFBundleIdentifier',appIdentifier,appPath) if ret: raise Exception('modify bundle id fail') else: print 'modify CFBundleIdentifier success value : %s' %appIdentifier else: raise Exception('getAppIdentifier fail') #找到需要签名的文件 print 'resursive file...\n' recursive_file(appPath) print 'resursive success \n' print 'start resign \n' print 'signfile: %s \n' %sign_arr for signfile in sign_arr: execStr = '/usr/bin/codesign -vvv -fs ' +'"'+certificateName+'"'+' --no-strict --entitlements '+entitlements_path+' '+signfile ret = utils.execCommand(execStr) if ret: raise Exception('sign fail --'+signfile) command = '/usr/bin/codesign -vvv -fs ' +'"'+certificateName+'"'+' --no-strict --entitlements '+entitlements_path+' '+appPath ret = utils.execCommand(command) if ret: print 'sign fail' raise Exception('sign fail --'+appPath) command ='/usr/bin/codesign --verify '+appPath ret =utils.execCommand(command) if ret: print 'sign error' raise Exception('verify sign fail') print '%s sign success \n' %appPath command ='/usr/bin/codesign -vv -d '+appPath utils.execCommand(command) #开始压缩 print 'start compress \n' Payload_path = os.path.join(os.path.split(appPath)[0],"Payload") if not os.path.exists(Payload_path): command = "mkdir " + Payload_path if utils.execCommand(command): raise Exception('mkdir Payload fail') print 'mk dir Payload success' else: for files in os.listdir(Payload_path): path = os.path.join(Payload_path,files) command ='rm -f '+path if utils.execCommand(command): raise Exception('remove fail '+path) command = "mv " + appPath + " " + Payload_path if utils.execCommand(command): raise Exception('move .app into Payload dir fail') print 'move .app into /Payload/ success' os.chdir(os.path.split(appPath)[0]) command = "zip -q -r -m " + os.path.join(os.path.split(appPath)[0],'re_sign_dev.ipa') + " " +'./Payload' ret =utils.execCommand(command) if ret: print 'zip fail' raise Exception('zip fail') print 'zip Payload success' print 'delete Payload dir success' for files in os.listdir(os.path.split(appPath)[0]): files_path = os.path.join(os.path.split(appPath)[0],files) if files!='re_sign_dev.ipa': command = 'rm -rf '+files_path utils.execCommand(command) return os.path.join(os.path.split(appPath)[0],'re_sign_dev.ipa')
def post(self): if self.arguments: api_logger.info("HEADERS: " + str(self.request)) # Parse each param data = self.arguments if 'name' not in list(data.keys()) or 'type' not in list( data.keys()) or 'lang' not in list(data.keys()): api_logger.error("Error requests params") self.finish( '{"result":"error","description":"Error requests params"}') else: try: t_name = data['name'] t_type = data['type'] t_lang = data['lang'] t_gist = data['gist'] except Exception as e: api_logger.error("Error requests params " + str(e)) self.finish( '{"result":"error","description":"Error requests params","debug":"' + str(e) + '"}') # Create working dir try: workingPath = "/var/storm/src/sinfonier_backend" + str( int(time.time() + randint(50, 150))) shutil.copytree(options.backend_working_path, workingPath) except Exception as e: api_logger.error("Error creating working dir. " + str(e)) self.finish( '{"result":"error","description":"Error creating working dir","debug":"' + str(e) + '"}') # Change routes java_path_drains = workingPath + "/src/jvm/com/sinfonier/drains/" java_path_bolts = workingPath + "/src/jvm/com/sinfonier/bolts/" java_path_spouts = workingPath + "/src/jvm/com/sinfonier/spouts/" api_logger.info("New paths: " + java_path_drains + " - " + java_path_bolts + " - " + java_path_spouts) fileCfileCreatedreated = True # Get code from gist and write it util = Utils() # Check module type if t_type == "drain": dst_path = java_path_drains elif t_type == "bolt": dst_path = java_path_bolts elif t_type == "spout": dst_path = java_path_spouts else: shutil.rmtree(workingPath) api_logger.error( "Module type must be spout/bolt/drain. Deleted working repo." ) self.finish( '{"result":"error","description":"Module type must be spout/bolt/drain"}' ) # Check module language. If Python or Ruby (soon) change path if t_lang == "python": dst_path = workingPath + "/multilang/resources/" module_lang = "py" elif t_lang == "java": module_lang = "java" elif t_lang == "ruby": shutil.rmtree(workingPath) api_logger.error( "Ruby not supported yet. Deleted working repo.") self.finish( '{"result":"error","description":"Ruby not supported yet"}' ) else: shutil.rmtree(workingPath) api_logger.error( "Language must be supported. Current Python and Java. Deleted working repo." ) self.finish( '{"result":"error","description":"Language must be supported. Current Python and Java"}' ) try: api_logger.info("Get module.") fileName = util.get_module(t_name, module_lang, t_gist, dst_path, t_type) api_logger.info("Module Added: " + str(fileName)) fileCreated = True except Exception as e: shutil.rmtree(workingPath) api_logger.error( "Error creating source code file. Deleted working repo. " + str(e)) self.finish( '{"result":"error","description":"Error creating file","debug":"' + str(e) + '"}') fileCreated = False if fileCreated: # Regenerate jar on /var/storm/lastjar/ # <MAVEN_PATH>/maven/bin/mvn -f <SINFONIER_BACKEND_PATH>/pom.xml compile cmd_launch = options.maven_binary + " -f " + workingPath + "/pom.xml" + " compile" cmd = utils.execCommand(cmd_launch) # Get output and error (output, err) = cmd.execute() if err: shutil.rmtree(workingPath) api_logger.error( "Error compiling jar file. Deleted working repo. " + str(err)) self.finish( '{"result":"error","description":"Error compiling jar file", "detail":"' + str(err) + '"}') elif output: api_logger.debug("Command output: " + str(output)) errorDebug = False warDebug = False dedugStack = "" warStack = "" fDate = "" for line in output.splitlines(): if "ERROR" in line and t_name in line: try: api_logger.info("Found ERROR") dedugStack += time.strftime( "%m-%d-%Y %H:%M:%S") + ": " dedugStack += line.split("com/sinfonier")[1] dedugStack += "|" except Exception as e: api_logger.error( "Error parsing errors from output. " + str(e)) pass if "BUILD FAILURE" in line: api_logger.info("Found BUILD FAUILURE") errorDebug = True if "WARNING" in line and t_name in line: try: api_logger.info("Found WARNING") warDebug = True warStack += time.strftime( "%m-%d-%Y %H:%M:%S") + ": " warStack += line.split("com/sinfonier")[1] warStack += "|" except Exception as e: api_logger.error( "Error parsing errors from output. " + str(e)) pass if "Finished at:" in line: api_logger.info("Store Finished time") fDate = line shutil.rmtree(workingPath) if errorDebug: api_logger.error("Error compiling module. " + str(dedugStack)) self.finish( '{"result":"error","description":"Error compiling...", "detail":"' + str(dedugStack) + '"}') elif warDebug: api_logger.info("Warning during compiling. " + str(warStack)) self.finish( '{"result":"warning","description":"Warning during compiling", "detail":"' + str(warStack) + '"}') else: api_logger.info("Module compiled. " + str(fDate)) self.finish( '{"result":"success","description":"Module compiled", "detail":"' + str(fDate) + '"}') else: api_logger.error("Content-Type:application/json missing") self.finish( '{"result":"error","description":"Content-Type:application/json missing"}' )
try: api_logger.info("Get module.") fileName = util.get_module(t_name,module_lang,t_gist,dst_path,t_type) api_logger.info("Module Added: "+str(fileName)) fileCreated = True except Exception,e: shutil.rmtree(workingPath) api_logger.error("Error creating source code file. Deleted working repo. "+str(e)) self.finish('{"result":"error","description":"Error creating file","debug":"'+str(e)+'"}') fileCreated = False if fileCreated: # Regenerate jar on /var/storm/lastjar/ # <MAVEN_PATH>/maven/bin/mvn -f <SINFONIER_BACKEND_PATH>/pom.xml compile cmd_launch = options.maven_binary+" -f "+workingPath+"/pom.xml"+" compile" cmd = utils.execCommand(cmd_launch) # Get output and error (output, err) = cmd.execute() if err: shutil.rmtree(workingPath) api_logger.error("Error compiling jar file. Deleted working repo. "+str(err)) self.finish('{"result":"error","description":"Error compiling jar file", "detail":"'+str(err)+'"}') elif output: api_logger.debug("Command output: "+str(output)) errorDebug = False warDebug = False dedugStack = "" warStack = "" fDate = "" for line in output.splitlines(): if "ERROR" in line and t_name in line:
def post(self): if self.arguments: api_logger.info("HEADERS: " + str(self.request)) # Parse each param data = self.arguments if 'name' not in list(data.keys()) and 'lines' not in list( data.keys()): api_logger.error("Error requests params.") self.finish( '{"result":"error","description":"Error requests params"}') else: try: t_name = data['name'] except Exception as e: api_logger.error("Error requests params " + str(e)) self.finish( '{"result":"error","description":"Error requests params","debug":"' + str(e) + '"}') # <STORM_PATH>/storm/bin/storm list cmd_launch = options.storm_binary + " list" cmd = utils.execCommand(cmd_launch) # Get output and error (output, err) = cmd.execute() if err: api_logger.error("Error getting topology list. " + str(err)) self.finish( '{"result":"error","description":"Error getting topology list","detail":"' + str(err) + '"}') elif output: api_logger.debug("Command output: " + str(output)) notFound = False topoState = "" for line in output.splitlines(): if t_name in line: notFound = True try: api_logger.info("Found Topology") api_logger.debug(line.split(" ")) for aux in line.split(" "): if aux != "" and aux != t_name: api_logger.info("Status found: " + str(aux)) topoState = aux break except Exception as e: api_logger.error( "Error parsing errors from output. " + str(e)) pass if not notFound: api_logger.error("Topology not found.") self.finish( '{"result":"error","description":"Topology not found"}' ) elif notFound: api_logger.info("Topology Status. " + str(topoState)) self.finish( '{"result":"success","description":"Topology Status", "detail":"' + str(topoState) + '"}') else: api_logger.error("Something was wrong.") self.finish( '{"result":"error","description":"Something was wrong"}' ) else: api_logger.error("Content-Type:application/json missing") self.finish( '{"result":"error","description":"Content-Type:application/json missing"}' )