def add_test_attachment(test_id, afile, desc, comments):
    if afile.filename:
        db = connect(1)
        cur = db.cursor()
        originalname = os.path.basename(afile.filename)
        
        cur.execute("INSERT INTO Attachments (test_id,attachmime,attachdesc,comments,originalname) VALUES (%s,%s,%s,%s,%s)",
                    (test_id,afile.type,desc,comments,originalname));
        att_id=cur.lastrowid
        db.commit()
        ofn=settings.getAttachmentPathFor(int(test_id),int(att_id));
        sub_path = os.path.dirname(ofn)
        if not os.path.exists(sub_path):
            os.mkdir(sub_path)
        open(ofn,'wb').write(afile.file.read())
        print '<div> The file %s was uploaded successfully. </div>' % (originalname)
示例#2
0
def save(attach_id):
	db=connect(0)
	cur=db.cursor()

	cur.execute("SELECT test_id, attachmime, originalname FROM Attachments WHERE attach_id=%d" % (attach_id));

	if not cur.with_rows:
    		print "<h1>Attachment not available</h1>"
	else:    
		 thevals=cur.fetchall();
		 attpath=settings.getAttachmentPathFor(thevals[0][0],attach_id)
		 if not os.path.isfile(attpath):
   		        print "<h1>Attachment not found</h1>"
       		 else:
        		statinfo = os.stat(attpath)
        		sys.stdout.write(file(attpath,"rb").read() )
	cur.close()
def add_test_attachment(test_id, afile, desc):
    comments = "I think this field does nothing!"
    if afile.filename:
        db = connect(1)
        cur = db.cursor()
        originalname = os.path.basename(afile.filename)

        cur.execute(
            "INSERT INTO Attachments (test_id,attachmime,attachdesc,comments,originalname) VALUES (%s,%s,%s,%s,%s)",
            (test_id, afile.type, desc, comments, originalname))
        att_id = cur.lastrowid
        db.commit()
        ofn = settings.getAttachmentPathFor(int(test_id), int(att_id))
        sub_path = os.path.dirname(ofn)
        if not os.path.exists(sub_path):
            os.mkdir(sub_path)
        open(ofn, 'wb').write(afile.file.read())
        print '<br><br></br></br>'
        print '<center><div> The file %s was uploaded successfully. </div></center>' % (
            originalname)
示例#4
0
def get_ext(attach_id):

#form = cgi.FieldStorage()
#attach_id = base.cleanCGInumber(form.getvalue('attach_id'))
#attach_id = int(sys.argv[1])

    db=connect(0)
    cur=db.cursor()

    cur.execute("SELECT test_id, attachmime, originalname FROM Attachments WHERE attach_id=%d" % (attach_id));

    if not cur.with_rows:
        extension = 0
#    print "Content-type: text/html\n"
#    base.header("Attachment Request Error")
#    base.top()
#    print "<h1>Attachment not available</h1>"
#    base.bottom()
    else:    
        thevals=cur.fetchall();
        attpath=settings.getAttachmentPathFor(thevals[0][0],attach_id)
        if not os.path.isfile(attpath):
            extension = 0
#        print "Content-type: text/html\n"
#        base.header("Attachment Request Error")
#        base.top()
#        print "<h1>Attachment not found</h1>"
#        base.bottom()        
        else:
#        statinfo = os.stat(attpath)
#        print 'Content-type: %s \r\nContent-length: %d \r\nContent-Disposition: INLINE; filename="%s" \n' % (thevals[0][1],statinfo.st_size,thevals[0][2])
#        sys.stdout.write(file(attpath,"rb").read() )
            name,extension = os.path.splitext(thevals[0][2])
#        f = open("/var/www/html/attachments/get_attach_id%d%s" % (attach_id, extension),'w')
#        f.write(file(attpath,"rb").read() )
#        f.close
        
    return extension
示例#5
0
form = cgi.FieldStorage()
attach_id = base.cleanCGInumber(form.getvalue('attach_id'))

db=connect(0)
cur=db.cursor()

cur.execute("SELECT test_id, attachmime, originalname FROM Attachments WHERE attach_id=%d" % (attach_id));

if not cur.with_rows:
    print "Content-type: text/html\n"
    base.header("Attachment Request Error")
    base.top()
    print "<h1>Attachment not available</h1>"
    base.bottom()
else:    
    thevals=cur.fetchall();
    attpath=settings.getAttachmentPathFor(thevals[0][0],attach_id)
    if not os.path.isfile(attpath):
        print "Content-type: text/html\n"
        print 
        print attpath
        base.header("Attachment Request Error")
        base.top()
        print "<h1>Attachment not found</h1>"
        base.bottom()        
    else:
        statinfo = os.stat(attpath)
        print 'Content-type: %s \r\nContent-length: %d \r\nContent-Disposition: INLINE; filename="%s" \n' % (thevals[0][1],statinfo.st_size,thevals[0][2])
        sys.stdout.write(file(attpath,"rb").read() )

cur = db.cursor()

cur.execute(
    "SELECT test_id, attachmime, originalname FROM Attachments WHERE attach_id=%d"
    % (attach_id))

if not cur.with_rows:
    #    print "Content-type: text/html\n"
    #    base.header("Attachment Request Error")
    #    base.top()
    #    print "<h1>Attachment not available</h1>"
    #    base.bottom()
    print "Error: Attachment not found! (ID: %s)" % attach_id
else:
    thevals = cur.fetchall()
    attpath = settings.getAttachmentPathFor(thevals[0][0], attach_id)
    if not os.path.isfile(attpath):
        #        print "Content-type: text/html\n"
        #        base.header("Attachment Request Error")
        #        base.top()
        #        print "<h1>Attachment not found</h1>"
        #        base.bottom()
        print "Error: Attachment not found! (ID: %s)" % attach_id
    else:
        #        statinfo = os.stat(attpath)
        #        print 'Content-type: %s \r\nContent-length: %d \r\nContent-Disposition: INLINE; filename="%s" \n' % (thevals[0][1],statinfo.st_size,thevals[0][2])
        #        sys.stdout.write(file(attpath,"rb").read() )
        name, extension = os.path.splitext(thevals[0][2])
        f = open(
            "/var/www/static/attachments/get_attach_id%d%s" %
            (attach_id, extension), 'w')
示例#7
0
def ePortageTest(test_type_id, card_sn, test_name, revokes ,attempts):

	print  			'<div class="row">'
	print           			'<div class="col-md-12">'
	print					'<h3 id="test-{0}">{1}</h3>'.format(test_type_id, test_name)
	print					'<br>'

	background_colors = {
		-1: "#F6F6F6",
		0: "#FFE5E5",
		1: "#EBFFE4",
	}

	n = 0
#	print attempts
	for attempt in attempts:
		# Determine success of test:
		if attempt[5] in revokes:		# Card ID
			good = -1		# Unknown
		else:
			if attempt[2] == 1:		# Success bit
				good = 1		# Passed
			else:
				good = 0		# Failed
		n += 1
		
		# Print stuff:
		print	   			'<h4>Attempt: %d</h4>'%n
		print				'<table class="table table-bordered table-striped Portage_table" style="width: 60%; background-color: {0};">'.format(background_colors[good])
		print						'<tbody>'
		print						'<tr>'
		print							'<th>Name</th>'
		print							'<th>Date</th>'
		print							'<th colspan=2>Successful?</th>'
#		print							'<th>Comments</th>'
		print						'</tr>'
		print						'<tr>'
		print					                '<td> %(pname)s </td>' %{ "pname":attempt[0]}
		print					                '<td> %(when)s </td>' %{ "when":attempt[1]}
		if good == -1:
			print					'<td><b>Revoked</b>: %(comment)s </td>' %{ "comment":revokes[attempt[5]] }
		elif good == 1:
			print					'<td align=left> Yes </td>'
			print "<td align=right style='{ background-color: yellow; }' ><a href='revoke_success.py?test_id=%(id)s'>Revoke</a></td>" %{ "id":attempt[5]}
		elif good == 0:
			print					'<td colspan=2>No</td>'
			print "<td align=right style='{ background-color: yellow; }' ><a href='revoke_failure.py?test_id=%(id)s'>Revoke</a></td>" %{ "id":attempt[5]}
		print						'</tr>'
		print						'<tr>'
		print						            '<td><b>Comments:</b></td>' 
		print					                '<td colspan=3> %(comm)s </td>' %{ "comm":attempt[3]}
		print						'</tr>'
		
		## Attachements:
		attachments = Portage_fetch_attach(attempt[5])
		for afile in attachments:
			print '<tr><td>Attachment: <a href="get_attach.py?attach_id=%s">%s</a><td colspan=2><i>%s</i></tr>' % (afile[0],afile[3],afile[2])
		
		print						'</tbody>'
		print                               '</table>'
		
		## Display image if there is one:
		images = [(afile[0], afile[-1]) for afile in attachments if (".png" in afile[3] or ".jpg" in afile[3])]
#		print images
		if images:
			location = settings.getAttachmentPathFor(images[0][1], images[0][0]).replace("/var/www/html", "")
			print "<a href='{0}'><img src='{0}' style='width:66%'></a>".format(location)
#			print location

	print				'</div>'
	print				'</div>'
	print                       '<hr><br>'