コード例 #1
0
def edit_file_content():
    global CURRENT_DIR
    path = request.args.get('path')
    path = path.replace("../", "")
    if path is None:
        abort(400)
    if not os.path.exists(os.path.join(CURRENT_DIR, path)):
        abort(404)
    json_data = request.get_json(force=True)
    return file_service.edit_file_content(CURRENT_DIR, path,
                                          json_data['content'])
コード例 #2
0
def downloadArtifactsFolder():
         
    BASE_DIR = os.path.join(CURRENT_DIR, 'artifacts')
    try:
        json_data = request.get_json(force=True)
        path = os.path.join(CURRENT_DIR,'artifacts', json_data['folderName'])
        
        createdFolderPath = os.path.join(CURRENT_DIR,'abot/temp', json_data['folderName'])
        
        def zipdir(url, ziph):
            length = len(url)
            for root, dirs, files in os.walk(url):
                folder = root[length:] # path without "parent"
                for file in files:
                    ziph.write(os.path.join(root, file), os.path.join(folder, file))
                    
        zipfilename = json_data['folderName']
        
        zipFolderPath = createdFolderPath+".zip";
        
        zipf = zipfile.ZipFile(zipFolderPath, 'w', zipfile.ZIP_DEFLATED)
        
        zipdir(path, zipf)
        zipf.close()
        
        zipSourcePath = zipFolderPath
        
        zipDestinationPath = os.path.join(CURRENT_DIR,'artifacts/')
        
        #To copy the Report folder to Artifacts folder from temp folder 
        process = subprocess.Popen(["sudo", "cp", zipSourcePath , zipDestinationPath], stdout=subprocess.PIPE)
        
        #To delete the Report folder from temp folder 
        process = subprocess.Popen(["sudo", "rm", "-rf", zipFolderPath], stdout=subprocess.PIPE)

        result = str(zipfilename)
        
        return jsonify(status='OK',result=result) 

    except Exception,e:
        return jsonify(status='ERROR',message=str(e))
コード例 #3
0
def execute_feature_file():
    json_data = request.get_json(force=True)
    params = json_data['params']
    runner = FeatureFileRunner(json_data['params'])
    runner.start()
    return make_response(jsonify({'status': 'OK'}), 200)
コード例 #4
0
def getReportContent():
    try:
        #Initialize
        result = {'file' : '',
                   'mime' : '',
                   'message' : '',
                   'message_css' : '',
                   'download' : '',
                   'showDownload' : False,
                   'containerScroll' : True,
                   'content' : '',
                   'keywords' : ''}
    
        json_data = request.get_json(force=True)      
        file = os.path.join(CURRENT_DIR, json_data['path'].replace("../",""))
        #print "632", file
        
        pdfName = file.split("/")[-1].split(".")[0]
        
        reportDate = file.split("/")[-3]
        #print "636", reportDate 
        
        pdfName = pdfName + "_" + reportDate + ".pdf"
        #print "639", pdfName

        BASE_DIR = os.path.join(CURRENT_DIR, 'abot')
        #print "638", BASE_DIR

        newFilePath = ''
        
        # load the file
        with open(file) as fp:
            #print "649"
            soup = BeautifulSoup(fp)
            
            # Remove header and footer from html
            soup.find(attrs={"id" : "fullwidth_header"}).extract()
            soup.find(attrs={"class" : "footer"}).extract()
           
            for a in soup.findAll('a'):
                # Delete the link from  
                del a['href']

            #print "666", (os.path.isdir("temp"))
            
            if not os.path.isdir("temp"):
                print "670"
                os.makedirs("temp");

            #print(os.path.exists("/home/el/myfile.txt"))

            tempdir = os.path.join(CURRENT_DIR,'abot/temp')
            #print "652", tempdir
            delTempFilesCmd = "rm"+" -rf"+" temp/*.pdf"
            #print "653", delTempFilesCmd
            
            # delete temp folder content    
            delTempFile = subprocess.Popen(delTempFilesCmd, stdout=subprocess.PIPE, shell=True)
             
            newFilePath = os.path.join(tempdir, "output.html")

            with open(newFilePath, "w") as f:
                #print "684"
		f.write(str(soup))
                f.close()

        bindir = os.path.join(CURRENT_DIR,'abot/bin')
        #print "692", bindir

        # Set execution permission for wkhtmltopdf file
        # find /opt/lampp/htdocs -type f -exec chmod 777 {} \;
        exePermissionStr = "find " + bindir + "/wkhtmltopdf" + " -type " + "f " "-exec" + " chmod " + "ugo+x " + "{} " +"\;"
        #print "697", exePermissionStr
        binPermission = subprocess.Popen(exePermissionStr, stderr=subprocess.PIPE, stdout=subprocess.PIPE, shell=True)
        #print "701", binPermission
        
        # create pdf file - cat test.html | ./wkhtmltopdf - test.pdf
        strs = "cat "+newFilePath+" | bin/wkhtmltopdf - "+pdfName
        process = subprocess.Popen(strs, stdout=subprocess.PIPE, shell=True)
        
        #output, err = process.communicate(b"input data that is passed to subprocess' stdin")
        output, err = process.communicate()
        rc = process.returncode
        
        if rc==0:
            # move pdf file to temp dir from bas dir - mv 002-sip_register.pdf temp/
            mvFile = subprocess.Popen(["mv " + BASE_DIR +"/"+ pdfName + " temp/"], stdout=subprocess.PIPE, shell=True)
            output, err = mvFile.communicate()
            mvFileval = mvFile.returncode
            
        if mvFileval==0:
            result['download'] = pdfName
            result['showDownload'] = True

        return jsonify(status='OK',result=result)
        
    except Exception,e:
        return
コード例 #5
0
def editFileContent():
    try:
        #Initialize
        result = {'file' : '',
                   'mime' : '',
                   'message' : '',
                   'message_css' : '',
                   'download' : '',
                   'showDownload' : False,
                   'containerScroll' : True,
                   'content' : '',
                   'keywords' : ''}
    
        #json_data = request.json
        
        json_data = request.get_json(force=True)
        
        #file = json_data['path']
        file = os.path.join(CURRENT_DIR, json_data['path'].replace("../",""))
        fileContent = json_data['content'].replace("<br>", "\n")
        
        # cleanr = re.compile('<.*?>')
        # cleantext = re.sub(cleanr, '', fileContent)
        #print "584", cleantext
        
        # fileContent = cleantext
        
        # Providing Read, Write and Execute permission to selected featureFiles 
        exePermissionStr = "sudo " + "find " + file + " -type " + "f " + "-exec " + "chmod " + "ugo+rwx " + "{} " +"\;"
        #print "569", exePermissionStr
        ffPermissionChange = subprocess.Popen(exePermissionStr, stderr=subprocess.PIPE, stdout=subprocess.PIPE, shell=True)
        output, err = ffPermissionChange.communicate()
        temp = ffPermissionChange.returncode
        #print "572", temp

        if temp == 0:
            with open(file, "w") as f:
                #print "575"
                f.write(fileContent)
        else: 
            print "Write permission not granted to the feature file"

        mime = MimeTypes()
        mime_type = mime.guess_type(urllib.pathname2url(file))[0] if mime.guess_type(urllib.pathname2url(file))[0] else 'text/plain' 
        result['file'] = file
        result['mime'] = mime_type
        download_html = ''
        download_html+='<div class="">'
        download_html+='<a class="btn-download btn btn-lg btn-primary" href="' + file + '" target="_blank"><i class="glyphicon glyphicon-download-alt"></i> Download</a>'
        download_html+='</div>'
        result['download'] = download_html
        
        supported_application = ['application/xml', 'text/x-php', 'text/plain', 'text/xml', 'text/csv' ]
        mime = mime_type.split('/')
        file_mime = mime[0]
        if mime_type in supported_application:
            content = ''
            words = ''
            
            file_ext = file.split('.')
            
            if file_ext[len(file_ext)-1] == "properties":
                with open(file) as f:
                    for line in f:
                        content += line
            elif file_ext[len(file_ext)-1] == "feature":
                #print "569"
                content = open(file).read()
                x = open(file, "r")
                words = [w for w in x.read().split() if w[0] == "@"]   
                
            else:
                content = open(file).read()

            result['content'] = content
            
            result['containerScroll'] = True
            result['showDownload'] = False
            result['keywords'] = words
            
        elif (file_mime == 'text'):
            html_content = ''
            html_content+= '<object data="' + file + '" type="' + mime_type + '" id="fileObject" style="width:100% ">'
            html_content+='<embed type="' + mime_type + '" src="' + file + '" style="width:100%">'
            html_content+='</object>'
            result['content'] = html_content
            result['containerScroll'] = False
            result['showDownload'] = False
        else:
            html_content = ''
            html_content+= '<object data="' + file + '" type="' + mime_type + '" id="fileObject" style="width:100% " class="hidden">'
            html_content+='<embed type="' + mime_type + '" src="' + file + '" style="width:100%">'
            html_content+='</object>'
            result['content'] = html_content
            result['containerScroll'] = False
            result['showDownload'] = True
       
        return jsonify(status='OK',result=result)
        
    except Exception,e:
        return jsonify(status='ERROR',message=str(e))
コード例 #6
0
def getFileContent():
    try:
        #Initialize
        result = {'file' : '',
                   'mime' : '',
                   'message' : '',
                   'message_css' : '',
                   'download' : '',
                   'showDownload' : False,
                   'containerScroll' : True,
                   'content' : '',
                   'keywords' : ''}
    
        #json_data = request.json
        
        json_data = request.get_json(force=True)
        
        #file = json_data['path']
        file = os.path.join(CURRENT_DIR, json_data['path'].replace("../",""))
        
        mime = MimeTypes()
        mime_type = mime.guess_type(urllib.pathname2url(file))[0] if mime.guess_type(urllib.pathname2url(file))[0] else 'text/plain' 
        result['file'] = file
        result['mime'] = mime_type
        download_html = ''
        download_html+='<div class="">'
        download_html+='<a class="btn-download btn btn-lg btn-primary" href="' + file + '" target="_blank"><i class="glyphicon glyphicon-download-alt"></i> Download</a>'
        download_html+='</div>'
        result['download'] = download_html
        
        supported_application = ['application/xml', 'text/x-php', 'text/plain', 'text/xml', 'text/csv']
        mime = mime_type.split('/')
        file_mime = mime[0]
        if mime_type in supported_application:
            content = ''
            words = ''
            
            file_ext = file.split('.')
            
            if file_ext[len(file_ext)-1] == "properties":
                with open(file) as f:
                    for line in f:
                        content += line
            elif file_ext[len(file_ext)-1] == "feature":
                content = open(file).read()
                x = open(file, "r")
                words = [w for w in x.read().split() if w[0] == "@"]
            elif file_ext[len(file_ext)-1] == "csv":
                with open(file, 'rb') as csvfile:
                    spamreader = csv.reader(csvfile, delimiter=' ', quotechar='|')
                    for row in spamreader:
                        line = ' '.join(row)
                        content += line + "\n"
            else:
                content = open(file).read()
                content = unicode(content, errors='ignore')

            result['content'] = content
            
            result['containerScroll'] = True
            result['showDownload'] = False
            result['keywords'] = words
            
        elif (file_mime == 'text'):
            html_content = ''
            html_content+= '<object data="' + file + '" type="' + mime_type + '" id="fileObject" style="width:100% ">'
            html_content+='<embed type="' + mime_type + '" src="' + file + '" style="width:100%">'
            html_content+='</object>'
            result['content'] = html_content
            result['containerScroll'] = False
            result['showDownload'] = False
        else:
            html_content = ''
            html_content+= '<object data="' + file + '" type="' + mime_type + '" id="fileObject" style="width:100% " class="hidden">'
            html_content+='<embed type="' + mime_type + '" src="' + file + '" style="width:100%">'
            html_content+='</object>'
            result['content'] = html_content
            result['containerScroll'] = False
            result['showDownload'] = True
       
        return jsonify(status='OK',result=result)
    except Exception,e:
        return jsonify(status='ERROR',message=str(e))