Skip to content

Commit

Permalink
getting started; geneontology#64
Browse files Browse the repository at this point in the history
  • Loading branch information
kltm committed May 20, 2015
1 parent 52a7b9a commit 27dc847
Show file tree
Hide file tree
Showing 3 changed files with 152 additions and 0 deletions.
9 changes: 9 additions & 0 deletions fs-to-s3/README.org
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
* Usage

To get ready:

: npm install

Running:

node ./fs-to-s3.js -b foo -d /tmp/node_modules
108 changes: 108 additions & 0 deletions fs-to-s3/fs-to-s3.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
////
//// Take a filesystem path and convert it to a website in S3.
////
//// TODO: S3 parts.
////
//// Example usage:
//// node ./fs-to-s3.js -b foo -d /tmp/node_modules/
////

var opts = require('minimist');
var fs = require("fs");
var us = require('underscore');
var find = require('findit');
var path = require('path');

// Aliases.
var each = us.each;

///
/// Incoming args.
///

// Args from CLI.
var argv = opts(process.argv.slice(2));
var bucket = null;
var scan_dir = null;
if( argv['b'] ){ bucket = argv['b']; }
console.log('S3 bucket: ' + bucket);
if( argv['d'] ){ scan_dir = argv['d']; }
console.log('scan dir: ' + scan_dir);

// Need args or die.
if( ! bucket || ! scan_dir ){
process.exit(1);
}

///
/// Scanning events.
///

var directories = [];
var files = [];
var directory_files = {}; // map of directorys to files

var finder = find(scan_dir);

finder.on('directory', function(dir, stat, stop){
//var base = path.basename(dir);

// Just dirs.
directories.push(dir);

// Keep hash made.
if( ! directory_files[dir] ){
directory_files[dir] = [];
}

// console.log('dir: ' + dir + '/');
});

finder.on('file', function(file, stat){
var dir = path.dirname(file);
var base = path.basename(file);

// console.log('file: ' + dir + ' ' + file);

files.push(file);

//
if( ! directory_files[dir] ){
directory_files[dir] = [];
}
directory_files[dir].push(file);

});

finder.on('link', function(link, stat){
console.log('skipping link: ' + link);
});

//
finder.on('end', function(){

//
each(directory_files, function(files, dir){

console.log('TODO: makedir: ' + dir);

// Order files.
files = files.sort();

// Send the files.
each(files, function(file){
console.log('TODO: send file: ' + file);
});
});

// //
// each(directories, function(dir){
// console.log('TODO: makedir: ' + dir);
// });

// //
// each(files, function(file){
// console.log('TODO: send file: ' + file);
// });

});
35 changes: 35 additions & 0 deletions fs-to-s3/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"name": "fs-to-s3",
"version": "0.0.1",
"description": "Filesystem to S3.",
"keywords": [
"application",
"gene ontology",
"GO",
"utility"
],
"author": {
"name": "SJC",
"email": "[email protected]",
"url": "http://berkeleybop.org/"
},
"homepage": "http://berkeleybop.org/",
"repository": {
"type": "git",
"url": "https://github.com/geneontology/go-exp"
},
"engines": {
"node": ">= 0.10.0",
"npm": ">= 2.7.4"
},
"bin": {
"noctua-repl": "./fs-to-s3.js"
},
"dependencies": {
"findit": "~2.0.0",
"underscore": "~1.8.3",
"minimist": "~1.1.1"
},
"devDependencies": {
}
}

0 comments on commit 27dc847

Please sign in to comment.