Gzip project export tar files.
git-svn-id: http://google-refine.googlecode.com/svn/trunk@394 7d457c2a-affb-35e4-300a-418c747d4874
This commit is contained in:
parent
309d682fcb
commit
0996b9e1dd
@ -4,6 +4,7 @@ import java.io.File;
|
|||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
|
import java.util.zip.GZIPOutputStream;
|
||||||
|
|
||||||
import javax.servlet.ServletException;
|
import javax.servlet.ServletException;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
@ -26,11 +27,11 @@ public class ExportProjectCommand extends Command {
|
|||||||
Project project = getProject(request);
|
Project project = getProject(request);
|
||||||
ProjectManager.singleton.ensureProjectSaved(project.id);
|
ProjectManager.singleton.ensureProjectSaved(project.id);
|
||||||
|
|
||||||
response.setHeader("Content-Type", "application/x-tar");
|
response.setHeader("Content-Type", "application/x-gzip");
|
||||||
|
|
||||||
OutputStream os = response.getOutputStream();
|
OutputStream os = response.getOutputStream();
|
||||||
try {
|
try {
|
||||||
tarToOutputStream(
|
gzipTarToOutputStream(
|
||||||
ProjectManager.singleton.getProjectDir(project.id),
|
ProjectManager.singleton.getProjectDir(project.id),
|
||||||
os
|
os
|
||||||
);
|
);
|
||||||
@ -42,6 +43,15 @@ public class ExportProjectCommand extends Command {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void gzipTarToOutputStream(File dir, OutputStream os) throws IOException {
|
||||||
|
GZIPOutputStream gos = new GZIPOutputStream(os);
|
||||||
|
try {
|
||||||
|
tarToOutputStream(dir, gos);
|
||||||
|
} finally {
|
||||||
|
gos.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected void tarToOutputStream(File dir, OutputStream os) throws IOException {
|
protected void tarToOutputStream(File dir, OutputStream os) throws IOException {
|
||||||
TarOutputStream tos = new TarOutputStream(os);
|
TarOutputStream tos = new TarOutputStream(os);
|
||||||
try {
|
try {
|
||||||
|
@ -7,6 +7,7 @@ import java.io.InputStream;
|
|||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.URLConnection;
|
import java.net.URLConnection;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
import java.util.zip.GZIPInputStream;
|
||||||
|
|
||||||
import javax.servlet.ServletException;
|
import javax.servlet.ServletException;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
@ -71,7 +72,11 @@ public class ImportProjectCommand extends Command {
|
|||||||
FilePart filePart = (FilePart) part;
|
FilePart filePart = (FilePart) part;
|
||||||
InputStream inputStream = filePart.getInputStream();
|
InputStream inputStream = filePart.getInputStream();
|
||||||
try {
|
try {
|
||||||
internalImportInputStream(projectID, inputStream);
|
internalImportInputStream(
|
||||||
|
projectID,
|
||||||
|
inputStream,
|
||||||
|
!filePart.getFileName().endsWith(".tar")
|
||||||
|
);
|
||||||
} finally {
|
} finally {
|
||||||
inputStream.close();
|
inputStream.close();
|
||||||
}
|
}
|
||||||
@ -117,17 +122,22 @@ public class ImportProjectCommand extends Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
internalImportInputStream(projectID, inputStream);
|
internalImportInputStream(projectID, inputStream, !urlString.endsWith(".tar"));
|
||||||
} finally {
|
} finally {
|
||||||
inputStream.close();
|
inputStream.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void internalImportInputStream(long projectID, InputStream inputStream) throws IOException {
|
protected void internalImportInputStream(long projectID, InputStream inputStream, boolean gziped) throws IOException {
|
||||||
File destDir = ProjectManager.singleton.getProjectDir(projectID);
|
File destDir = ProjectManager.singleton.getProjectDir(projectID);
|
||||||
destDir.mkdirs();
|
destDir.mkdirs();
|
||||||
|
|
||||||
untar(destDir, inputStream);
|
if (gziped) {
|
||||||
|
GZIPInputStream gis = new GZIPInputStream(inputStream);
|
||||||
|
untar(destDir, gis);
|
||||||
|
} else {
|
||||||
|
untar(destDir, inputStream);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void untar(File destDir, InputStream inputStream) throws IOException {
|
protected void untar(File destDir, InputStream inputStream) throws IOException {
|
||||||
|
@ -1 +1 @@
|
|||||||
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Freebase Gridworks</title>
<link rel="stylesheet" href="/styles/common.css" />
<link rel="stylesheet" href="/styles/index.css" />
<script type="text/javascript" src="externals/jquery-1.4.1.min.js"></script>
<script type="text/javascript" src="externals/date.js"></script>
<script type="text/javascript" src="scripts/util/string.js"></script>
<script type="text/javascript" src="scripts/version.js"></script>
<script type="text/javascript" src="scripts/index.js"></script>
<script type="text/javascript" src="http://www.freebase.com/labs/gridworks.js"></script>
</head>
<body>
<div id="header">
<a id="logo" href="http://www.freebase.com/" title="Freebase"><img alt="Freebase" src="images/freebase-headerlogo.png" /></a>
<div id="path"><span class="app-path-section"><a href="./index.html">Gridworks</a></span></div>
</div>
<div id="body">
<div id="body-empty">
<table><tr>
<td id="body-empty-logo-container"><img src="images/gridworks.png" /> Gridworks</td>
<td id="body-empty-create-project-panel-container"></td>
</tr></table>
</div>
<div id="body-nonempty">
<table><tr>
<td id="body-nonempty-logo-container"><img src="images/gridworks.png" /> Gridworks</td>
<td id="body-nonempty-projects-container">
<div id="projects"></div>
</td>
<td id="body-nonempty-create-project-panel-container"></td>
</tr></table>
</div>
</div>
<div id="footer">
<a href="about.html">About Freebase Gridworks</a>
•
© 2010 <a href="http://www.metaweb.com/">Metaweb Technologies, Inc.</a>
</div>
<div id="body-template">
<div id="create-project-panel">
<h1>Upload Data File</h1>
<form id="file-upload-form" method="post" enctype="multipart/form-data" action="/command/create-project-from-upload" accept-charset="UTF-8">
<div class="grid-layout layout-tight"><table>
<tr><td>Data File:</td><td>
<input type="file" id="project-file-input" name="project-file" />
</td></tr>
<tr><td>Project Name:</td><td>
<input type="text" size="30" id="project-name-input" name="project-name" />
</td></tr>
<tr><td>Load up to:</td><td>
<input id="limit-input" name="limit" size="5" /> data rows (optional)
</td></tr>
<tr><td>Skip:</td><td>
<input id="skip-input" name="skip" size="5" /> initial data rows (optional)
</td></tr>
<tr><td>Separator:</td><td>
<input id="separator-input" name="separator" size="2" /> column separator (optional)
</td></tr>
<tr><td></td><td>
<input type="submit" value="Create Project" id="upload-file-button" />
</td></tr>
</table></div>
</form>
<h1>Import Existing Project</h1>
<form id="project-upload-form" method="post" enctype="multipart/form-data" action="/command/import-project" accept-charset="UTF-8">
<table id="import-project-panel-layout">
<tr><td>Project TAR File:</td><td>
<input type="file" id="project-tar-file-input" name="project-file" />
</td></tr>
<tr><td>Re-name Project:</td><td>
<input type="text" size="30" id="project-name-input" name="project-name" /> (optional)
</td></tr>
<tr><td></td><td>
<input type="submit" value="Import Project" id="import-project-button" />
</td></tr>
</table>
</form>
</div>
</div>
</body>
</html>
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Freebase Gridworks</title>
<link rel="stylesheet" href="/styles/common.css" />
<link rel="stylesheet" href="/styles/index.css" />
<script type="text/javascript" src="externals/jquery-1.4.1.min.js"></script>
<script type="text/javascript" src="externals/date.js"></script>
<script type="text/javascript" src="scripts/util/string.js"></script>
<script type="text/javascript" src="scripts/version.js"></script>
<script type="text/javascript" src="scripts/index.js"></script>
<script type="text/javascript" src="http://www.freebase.com/labs/gridworks.js"></script>
</head>
<body>
<div id="header">
<a id="logo" href="http://www.freebase.com/" title="Freebase"><img alt="Freebase" src="images/freebase-headerlogo.png" /></a>
<div id="path"><span class="app-path-section"><a href="./index.html">Gridworks</a></span></div>
</div>
<div id="body">
<div id="body-empty">
<table><tr>
<td id="body-empty-logo-container"><img src="images/gridworks.png" /> Gridworks</td>
<td id="body-empty-create-project-panel-container"></td>
</tr></table>
</div>
<div id="body-nonempty">
<table><tr>
<td id="body-nonempty-logo-container"><img src="images/gridworks.png" /> Gridworks</td>
<td id="body-nonempty-projects-container">
<div id="projects"></div>
</td>
<td id="body-nonempty-create-project-panel-container"></td>
</tr></table>
</div>
</div>
<div id="footer">
<a href="about.html">About Freebase Gridworks</a>
•
© 2010 <a href="http://www.metaweb.com/">Metaweb Technologies, Inc.</a>
</div>
<div id="body-template">
<div id="create-project-panel">
<h1>Upload Data File</h1>
<form id="file-upload-form" method="post" enctype="multipart/form-data" action="/command/create-project-from-upload" accept-charset="UTF-8">
<div class="grid-layout layout-tight"><table>
<tr><td>Data File:</td><td>
<input type="file" id="project-file-input" name="project-file" />
</td></tr>
<tr><td>Project Name:</td><td>
<input type="text" size="20" id="project-name-input" name="project-name" />
</td></tr>
<tr><td>Load up to:</td><td>
<input id="limit-input" name="limit" size="5" /> data rows (optional)
</td></tr>
<tr><td>Skip:</td><td>
<input id="skip-input" name="skip" size="5" /> initial data rows (optional)
</td></tr>
<tr><td>Separator:</td><td>
<input id="separator-input" name="separator" size="2" /> column separator (optional)
</td></tr>
<tr><td></td><td>
<input type="submit" value="Create Project" id="upload-file-button" />
</td></tr>
</table></div>
</form>
<h1>Import Existing Project</h1>
<form id="project-upload-form" method="post" enctype="multipart/form-data" action="/command/import-project" accept-charset="UTF-8">
<table id="import-project-panel-layout">
<tr><td>Project .tar or .tar.gz File:</td><td><input type="file" id="project-tar-file-input" name="project-file" /></td></tr>
<tr><td>Re-name Project:</td><td><input type="text" size="20" id="project-name-input" name="project-name" /> (optional)</td></tr>
<tr><td></td><td><input type="submit" value="Import Project" id="import-project-button" /></td></tr>
</table>
</form>
</div>
</div>
</body>
</html>
|
@ -195,7 +195,7 @@ MenuBar.prototype._exportProject = function() {
|
|||||||
$(form)
|
$(form)
|
||||||
.css("display", "none")
|
.css("display", "none")
|
||||||
.attr("method", "post")
|
.attr("method", "post")
|
||||||
.attr("action", "/command/export-project/" + name + ".gridworks.tar")
|
.attr("action", "/command/export-project/" + name + ".gridworks.tar.gz")
|
||||||
.attr("target", "gridworks-export");
|
.attr("target", "gridworks-export");
|
||||||
$('<input />')
|
$('<input />')
|
||||||
.attr("name", "project")
|
.attr("name", "project")
|
||||||
|
@ -40,7 +40,11 @@
|
|||||||
|
|
||||||
#create-project-panel h1 {
|
#create-project-panel h1 {
|
||||||
font-size: 120%;
|
font-size: 120%;
|
||||||
margin: 1em 0;
|
margin: 2em 0 1em 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#import-project-panel-layout {
|
||||||
|
white-space: pre;
|
||||||
}
|
}
|
||||||
|
|
||||||
#projects {
|
#projects {
|
||||||
|
Loading…
Reference in New Issue
Block a user