Commit c5eaa61f authored by Alain Takoudjou's avatar Alain Takoudjou

Allowing to calculate MD5 sum of a file in the git repository

parent 3928ec49
......@@ -44,7 +44,7 @@ textarea {
}
body {
background: #0271BF;
background: #7195c2 url('../images/cloud_bg.jpg') repeat-x;
font: 13px 'Helvetica Neue', Helvetica, Arial, sans-serif;
color: #000000;
}
......@@ -217,6 +217,13 @@ body {
font-weight: normal;
font-size: 18px;
}
.content h2 a{
text-decoration:none;
color: #4DA0C6;
}
.content h2 a:hover{
color: #19485C;
}
.main_foot{
height: 15px;
......@@ -631,9 +638,8 @@ a.lshare img{
.error_message{ background: url(../images/exit.png) center no-repeat; height: 26px;}
.confirm_message{ background: url(../images/confirm.png) center no-repeat; height: 26px;}
.info_message{ background: url(../images/info.png) center no-repeat; height: 26px;}
#error p{
fon-size: 13px;
color: #000;
}
#error p{ fon-size: 13px; color: #4A131F;}
#pClose{background:url(../images/close.png) no-repeat 0px 0px; display:block; width:22px; height:22px; cursor:pointer}
#pClose:hover{background:url(../images/close_hover.png) no-repeat 0px 0px;}
.md5sum {margin:10px; font-size:15px;}
.title{background: #e4e4e4; width: 100%; height: 25px; padding-top:2px; text-indent: 5px; color: #737373; text-shadow: 0px 1px #FFF;}
\ No newline at end of file
......@@ -10,6 +10,7 @@ $(document).ready( function() {
var file = $("input#profile").val();
var edit = false;
var send = false;
selectFile(file);
$("#save").click(function(){
......@@ -17,7 +18,8 @@ $(document).ready( function() {
$("#error").Popup("Can not load your file, please make sure that you have selected a Software Release", {type:'alert', duration:5000});
return false;
}
send = false;
if (send) return;
send =true
$.ajax({
type: "POST",
url: $SCRIPT_ROOT + '/saveFileContent',
......@@ -34,6 +36,10 @@ $(document).ready( function() {
});
return false;
});
$("#getmd5").click(function(){
getmd5sum();
return false;
});
function selectFile(file){
edit = false;
......@@ -53,4 +59,24 @@ $(document).ready( function() {
});
return;
}
function getmd5sum(){
if (send) return;
send =true
$.ajax({
type: "POST",
url: $SCRIPT_ROOT + '/getmd5sum',
data: {file: file},
success: function(data){
if(data.code == 1){
$("#md5sum").empty();
$("#md5sum").append('md5sum : <span>' + data.result + '</span>');
}
else{
$("#error").Popup(data.result, {type:'error', duration:5000});
}
send = false;
}
});
}
});
\ No newline at end of file
......@@ -74,15 +74,14 @@ $(document).ready( function() {
$("#error").Popup("Please select the file to edit", {type:'alert', duration:3000});
return false;
}
send = false;
if (send) return false;
send = true;
$.ajax({
type: "POST",
url: $SCRIPT_ROOT + '/saveFileContent',
data: {file: $("input#subfolder").val(), content: editor.getSession().getValue()},
success: function(data){
if(data.code == 1){
$("#flash").fadeOut('normal');
$("#flash").empty();
$("#error").Popup("File saved succefuly!", {type:'confirm', duration:3000});
}
else{
......@@ -108,9 +107,34 @@ $(document).ready( function() {
$("#info").empty();
$("#info").append("Select parent directory or nothing for root...");
$("input#subfolder").val("");
$("#edit_info").empty();
$("#edit_info").append("No file selected");
editor.getSession().setValue("");
$("#md5sum").empty();
return false;
});
function getmd5sum(){
var file = $("input#subfolder").val();
if (send) return;
send =true
$.ajax({
type: "POST",
url: $SCRIPT_ROOT + '/getmd5sum',
data: {file: $("input#subfolder").val()},
success: function(data){
if(data.code == 1){
$("#md5sum").empty();
$("#md5sum").append('md5sum : <span>' + data.result + '</span>');
}
else{
$("#error").Popup(data.result, {type:'error', duration:5000});
}
send = false;
}
});
}
function switchContent(){
var root = projectDir;
if(!softwareDisplay){
......@@ -149,6 +173,7 @@ $(document).ready( function() {
$("#info").empty();
$("#info").append(relativeFile);
$("input#subfolder").val(file);
$("#md5sum").empty();
path = "";
send = false;
edit = false;
......@@ -159,14 +184,17 @@ $(document).ready( function() {
data: "file=" + file,
success: function(data){
if(data.code == 1){
$("#flash").fadeOut('normal');
$("#flash").empty();
md5link = " <a href='#' id='getmd5' title='Show or Update md5sum value'>[md5]</a>"
$("#edit_info").empty();
var name = file.split('/');
$("#edit_info").append("Edit selected file: " +
relativeFile);
$("#edit_info").append("Current file: " +
relativeFile + md5link);
editor.getSession().setValue(data.result);
setEditMode(name[name.length - 1]);
$("#getmd5").click(function(){
getmd5sum();
return false;
});
edit = true;
}
else{
......@@ -178,7 +206,7 @@ $(document).ready( function() {
}
else{
$("#edit_info").empty();
$("#edit_info").append("Edit your selected file");
$("#edit_info").append("No file selected");
editor.getSession().setValue("");
}
return;
......
......@@ -14,7 +14,7 @@
<input type="hidden" name="method" id="method" value="{{method}}" />
{% if method == "new" %}
<div id="addsoftware">
<h2>What is the name of your software?</h2>
<h2>What is the name of your software release?</h2>
<label for='software'>Name: </label>
<input type="text" name="software" id="software" size='30' value="Enter software name..." />
<br/><br/>
......@@ -28,7 +28,7 @@
</div>
{% elif method == "open" %}
<div id="openSoftware">
<h2>Select the folder of your software into the box</h2>
<h2>Select the folder of your software release into the box</h2>
<div id="fileTree" class="file_tree"></div>
<div id="file_info" class="file_info">
<img src="{{ url_for('static', filename='images/check.png') }}" class="check" id="check" alt=""/>
......
......@@ -18,7 +18,7 @@
<input type="hidden" name="workdir" id="workdir" value="{{workDir}}" />
<input type="hidden" name="subfolder" id="subfolder" value="" />
<div id="software_folder">
<h2 class="hight show" id="details_head">Current software file content</h2>
<h2 class="hight show" id="details_head">Current software release file content</h2>
<div class="software_details" id="details_box">
<div id="fileTree" class="file_tree_short"></div>
<div class="box_software">
......@@ -37,7 +37,8 @@
<div class="clear"></div>
</div>
<div id="code" style="margin-top:10px">
<h2 id="edit_info">Edit your selected file</h2>
<h2 id="edit_info" class='title'>No file selected</h2>
<div class='md5sum' id='md5sum'></div>
<div class="main_content">
<pre id="editor">
......
......@@ -10,7 +10,8 @@
{% block body %}
<form method=post class=add-entry>
<dl>
<dd><h2>Instance Profile:</h2></dd>
<dd><h2>Edit instance profile <a href='#' id='getmd5' title='Show or Update md5sum value'>[md5]</a>:</h2></dd>
<dd><div class='md5sum' id='md5sum'></div></dd>
<dd>
<div class="main_content">
<pre id="editor"></pre>
......
......@@ -10,7 +10,8 @@
{% block body %}
<form method=post class=add-entry>
<dl>
<dd><h2>Software Profile:</h2></dd>
<dd><h2>Edit software profile <a href='#' id='getmd5' title='Show or Update md5sum value'>[md5]</a>:</h2></dd>
<dd><div class='md5sum' id='md5sum'></div></dd>
<dd>
<div class="main_content">
<pre id="editor"></pre>
......
......@@ -8,6 +8,7 @@ import urllib
from flask import jsonify
import shutil
import string
import hashlib
class Popen(subprocess.Popen):
......@@ -140,13 +141,17 @@ def runSoftwareWithLock(config):
for path in os.listdir(config['software_root']):
exist = False
for val in data:
if val['md5'] == path:
if val['md5'] == path:
exist = True
conf = os.path.join(config['runner_workdir'], ".project")
if not exist: #save this compile software folder
data.append({"title":getProjectTitle(config), "md5":path,
"path": open(os.path.join(config['runner_workdir'],
".project"), 'r').read()})
writeSoftwareData(config['runner_workdir'], data)
if os.path.exists(conf):
data.append({"title":getProjectTitle(config), "md5":path,
"path": open(os.path.join(config['runner_workdir'],
".project"), 'r').read()})
writeSoftwareData(config['runner_workdir'], data)
else:
shutil.rmtree(os.path.join(config['software_root'], path))
break
return True
return False
......@@ -433,5 +438,21 @@ def isText(file):
is_binary_string = lambda bytes: bool(bytes.translate(None, text_range))
try:
return not is_binary_string(open(file).read(1024))
except:
return False
def md5sum(file):
"""Compute md5sum of `file` and return hexdigest value"""
if os.path.isdir(file):
return False
try:
fh = open(file, 'rb')
m = hashlib.md5()
while True:
data = fh.read(8192)
if not data:
break
m.update(data)
return m.hexdigest()
except:
return False
\ No newline at end of file
......@@ -3,6 +3,7 @@ from flask import Flask, request, redirect, url_for, \
from utils import *
import os
import shutil
import md5
from gittools import cloneRepo, gitStatus, switchBranch, createBranch, getDiff, \
gitPush, gitPull
......@@ -48,12 +49,13 @@ def inspectSoftware():
@app.route('/removeSoftware')
def removeSoftware():
file_config = os.path.join(app.config['runner_workdir'], ".softdata")
if isSoftwareRunning(app.config) or isInstanceRunning(app.config):
flash('Software installation or instantiation in progress, cannot remove')
elif os.path.exists(app.config['software_root']):
elif os.path.exists(file_config):
svcStopAll(app.config)
shutil.rmtree(app.config['software_root'])
os.remove(os.path.join(config['runner_workdir'], ".softdata"))
os.remove(os.path.join(app.config['runner_workdir'], ".softdata"))
flash('Software removed')
return redirect(url_for('inspectSoftware'))
......@@ -288,4 +290,12 @@ def checkFileType():
if isText(path):
return jsonify(code=1, result="text")
else:
return jsonify(code=0, result="You can only open text files!")
\ No newline at end of file
return jsonify(code=0, result="You can only open text files!")
@app.route("/getmd5sum", methods=['POST'])
def getmd5sum():
md5 = md5sum(request.form['file'])
if md5:
return jsonify(code=1, result=md5)
else:
return jsonify(code=0, result="Can not get md5sum for this file!")
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment