OSDN Git Service

modified work space
author平田健悟 <hiratakengo@hiratakengo-no-MacBook-Pro.local>
Mon, 13 Feb 2017 09:06:49 +0000 (18:06 +0900)
committer平田健悟 <hiratakengo@hiratakengo-no-MacBook-Pro.local>
Mon, 13 Feb 2017 09:06:49 +0000 (18:06 +0900)
server/api/commandExecution/index.js
server/api/v1/execution/index.js
server/app.js
server/class/DB.js
server/class/Eos.js
test/mocha/Eos.test.js

index 9069520..7af9ab9 100644 (file)
@@ -11,7 +11,6 @@ router.post('/', function(req, res) {
         inputPath  = path.normalize('workspace/'+params.inputDir),
         outputPath = path.normalize('workspace/'+params.outputDir),
         options    = params.options
-    dddddd
     var execLine = '/Users/hiratakengo/Eos/bin/X86MAC64/'+command
     console.log(execLine)
     if(options) {
index 34a30cc..9eb5010 100644 (file)
@@ -1,6 +1,7 @@
 'use strict';
 
 var express    = require('express');
+var fs = require('fs')
 var router     = express.Router()
 var path       = require('path')
 var formidable = require('formidable')
@@ -13,7 +14,7 @@ router.post('/', function(req, res) {
     ws.emit();
 
     var form = new formidable.IncomingForm();
-    var root; 
+    var root;
     var result;
 
     var command;
@@ -48,10 +49,42 @@ router.post('/', function(req, res) {
         .then(function(r) {
             var optionsArray = r[1];
             return eos.execute(command, optionsArray);
-        }).then(function(r) {
+        })
+        .then(function(r) {
             var info = {
                 status: 'success',
             };
+
+            console.log('start readdir');
+            fs.readdir(root, function(err, list) {
+                console.log('in readdir');
+                if(err) {
+                  console.log('in err');
+                  console.error(err);
+                  process.exit(1);
+                } else {
+                  console.log(list.length.tostring);
+                  for (var i = 0; i< list.length; i++) {
+                    console.log(list[i]);
+                    db.createFile(list[i], '/');
+                  }
+                }
+            });
+
+            console.log('end readdir');
+            db.createFile('test.out','/');
+            //var id = db.getDirectory('/');
+            //console.log(db.getDirectoryId('/').tostring);
+            /*
+            for( var name in db.getFiles(id)) {
+              consoiel.log(name);
+              if(db.notExistFile(name, '/')) {
+                  console.log(name);
+                  db.createFile(name, '/');
+              }
+            }
+            */
+
             res.send(r);
         });
     });
index 0ebbbeb..847e5e1 100644 (file)
@@ -17,9 +17,10 @@ require('./routes')(app);
 // DBのコンストラクタを実行
 var DB = require('./class/DB').instance;
 DB.init()
+/*
 .then(function() {
     return DB.test2();
-})
+})*/
 .then(function() {
     if(process.env.NODE_ENV === 'debug') {
         return DB.testRest();
index 8d0f0f4..e54e8d9 100644 (file)
@@ -48,7 +48,7 @@ var instance = {
  * @returns {promise}
  */
 
-/** 
+/**
  * productionモード時は、db.workspaceを永続化させる
  * DEBUGモードの時は、db.debugを実行毎に作成する。
  * DEBUGモードの時は、sync()の中で、/レコードがFilesテーブルに追加される。
@@ -152,7 +152,7 @@ function insertRoot() {
 
 /**
  * getDirectoryParentId
- * ディレクトリのparentIdを取得する 
+ * ディレクトリのparentIdを取得する
  * @param name
  * @returns {promise} ディレクトリが存在すればresolve(uuid), しなければreject
  */
@@ -179,7 +179,7 @@ function getDirectoryParentId(name) {
 
 /**
  * getDirectoryId
- * ディレクトリのfileIdを取得する 
+ * ディレクトリのfileIdを取得する
  * @param name
  * @returns {promise} ディレクトリが存在すればresolve(uuid), しなければreject
  */
@@ -206,7 +206,7 @@ function getDirectoryId(name) {
 
 /**
  * getDirectory
- * ディレクトリのfileIdを取得する 
+ * ディレクトリのfileIdを取得する
  * @param name
  * @returns {promise} ディレクトリが存在すればresolve(name), しなければreject
  */
@@ -233,8 +233,8 @@ function getDirectory(name) {
 
 /**
  * getFiles
- * ディレクトリのfileId一覧を取得する 
- * @param {string} fileId ディレクトリのfileId 
+ * ディレクトリのfileId一覧を取得する
+ * @param {string} fileId ディレクトリのfileId
  * @returns {promise} resolve([Array]<string>fileId) 引数で与えられたディレクトリを直接の親に持つファイルのレコードの配列を返す。
  *                    与えられたfileIdがディレクトリでなければresolve
  */
@@ -261,8 +261,8 @@ function getFiles(fileId) {
 
 /**
  * getDirectories
- * ディレクトリの一覧を取得する 
- * @returns {promise} resolve([Array]<Object>) 
+ * ディレクトリの一覧を取得する
+ * @returns {promise} resolve([Array]<Object>)
  */
 function getDirectories() {
     return new Promise(function(resolve, reject) {
@@ -273,8 +273,8 @@ function getDirectories() {
         };
         Files.findAll(q)
         .then(function(r) {
-            var dirs = r.map(function(data) { 
-                return data.dataValues; 
+            var dirs = r.map(function(data) {
+                return data.dataValues;
             });
             resolve(dirs);
         });
@@ -358,7 +358,7 @@ function existDirectory(directory) {
             reject(new Error('parameter "directory" is undefined'));
         }
 
-        var arrayDirectory; 
+        var arrayDirectory;
         var root = directory.substr(0,1);
 
         if(root !== '/') {
@@ -407,9 +407,9 @@ function notExistDirectory(directory) {
     return new Promise(function(resolve, reject) {
         if(!directory) {
             resolve();
-        } 
+        }
 
-        var arrayDirectory; 
+        var arrayDirectory;
         var root = directory.substr(0,1);
 
         if(root !== '/') {
@@ -450,7 +450,7 @@ function notExistDirectory(directory) {
 /**
  * createFile
  *
- * @param fileName 
+ * @param fileName
  * @param parentDirectory
  * @returns {promise}<sequelize.createの結果を格納したobject | Error>
  */
@@ -469,8 +469,9 @@ function createFile(fileName,parentDirectory) {
                 fileId: uuid.v1(),
                 name: fileName,
                 parentId: parentId,
-                fileType: 1 
+                fileType: 1
             }
+            //fs.linkSync(q.filename, q.fileID);
             return Files.create(q)
         })
         .then(function(r) {
@@ -534,7 +535,7 @@ function createDirectory(directory) {
                 fileId: uuid.v1(),
                 name: leaf,
                 parentId: parentId,
-                fileType: 0 
+                fileType: 0
             }
             return Files.create(q)
         })
@@ -568,7 +569,7 @@ function removeDirectory(directory) {
                 fileId: uuid.v1(),
                 name: leaf,
                 parentId: parentId,
-                fileType: 0 
+                fileType: 0
             }
             return Files.create(q)
         })
@@ -588,7 +589,7 @@ function test1() {
         fileId: uuid.v1(),
         name: 'hoge.txt',
         parentId: '1f83f620-c1ed-11e5-9657-7942989daa00', // rootのuuid
-        fileType: 1 
+        fileType: 1
     };
     return Files.create(q);
 }
@@ -612,7 +613,7 @@ function test2() {
             fileId: '1f83f620-c1ed-11e5-9657-7942989daa01',
             name: 'two',
             parentId: q1.fileId,
-            fileType: 0 
+            fileType: 0
 
         };
         return Files.create(q2);
@@ -622,7 +623,7 @@ function test2() {
             fileId: '1f83f620-c1ed-11e5-9657-7942989daa02',
             name: 'two',
             parentId: '1f83f620-c1ed-11e5-9657-7942989daa00', //rootのuuid
-            fileType: 0 
+            fileType: 0
         };
         return Files.create(q3);
     })
index a5efe08..e3fb940 100644 (file)
@@ -1,7 +1,7 @@
-/** * * Class variables */ 
-// include all Eos command's info.  
-// For seaching with O(n), the object key name is command name.  
-var db = require('./DB.js').instance; 
+/** * * Class variables */
+// include all Eos command's info.
+// For seaching with O(n), the object key name is command name.
+var db = require('./DB.js').instance;
 var commandList = require(__dirname + '/../../user-specific-files/OptionControlFile/command_list.json');
 var ocfReference = {};
 
@@ -26,7 +26,7 @@ function matchOption(options, ocf) {
     return new Promise(function(resolve, reject) {
         var ok = {};
         var notIncludingRequiredOptions = [];
-        options.forEach(function(o) { 
+        options.forEach(function(o) {
             ok[o.name] = o.arguments;
         });
         ocf.forEach(function(o) {
@@ -35,7 +35,7 @@ function matchOption(options, ocf) {
             }
         });
 
-        // check whether all required option exist 
+        // check whether all required option exist
         if(notIncludingRequiredOptions.length > 0) {
             var errorMsg = 'Option ' + notIncludingRequiredOptions.toString() + ' are required';
             reject(new Error(errorMsg));
@@ -103,7 +103,7 @@ function validOutfileName(options, ocfObj, workspace) {
 }
 
 /**
- * validate 
+ * validate
  * コマンドとオプションのバリデーション
  * @param command
  * @param params
@@ -235,7 +235,7 @@ function toExecString(command, options, workspaceId) {
 /**
  * toExecArray
  *
- * @param {fileId} 
+ * @param {fileId}
  * @returns {string}
  */
 function toExecArray(command, options, workspaceId) {
@@ -269,7 +269,8 @@ function toExecArray(command, options, workspaceId) {
                 var outRegExp = /out|append/;
                 o.arguments.forEach(function(arg, i) {
                     if(ocfObj[o.name].arg[i].formType === 'select') {
-                        s.push(uuids[arg]);
+                        //s.push(uuids[arg]);
+                        s.push(arg);
                     } else {
                         s.push(arg);
                     }
@@ -297,13 +298,13 @@ function toExecArray(command, options, workspaceId) {
  */
 function execute(command, optionsArray) {
     return new Promise(function(resolve, reject) {
-        var workspace; 
+        var workspace;
         if(process.env.NODE_ENV === 'debug') {
             workspace = __dirname + '/../../user-specific-files/workspace.debug';
         } else {
             workspace = _dirname + '/../../user-specific-files/workspace';
         }
-        
+
         var config = {
             cwd: workspace
         };
@@ -350,7 +351,7 @@ function getFiles(fileId) {
 
 /**
  * getUUID
- * @param fileId 
+ * @param fileId
  * @returns {object} key: filename, value: uuid
  */
 function getUUIDs(fileId) {
@@ -367,7 +368,7 @@ function getUUIDs(fileId) {
 }
 
 /**
- * Eosコマンドをエミュレートするクラス 
+ * Eosコマンドをエミュレートするクラス
  * @varructor
  * @returns {object}
  * function execute(command, params) {
index e189015..2fb7f46 100644 (file)
@@ -20,7 +20,7 @@
     */
     `;
 
-    
+
     describe('Eos クラス', function() {
         before(function() {
         });
@@ -78,7 +78,7 @@
 
         var test2 = `
         /**
-        * 実行時文字列への変換 
+        * 実行時文字列への変換
         *
         * @param command
         * @param options
         describe(test2, function() {
             it('should return true when all options is proper.', function() {
                 var result = eos.toExecString('dcdFilePrint', [{name: '-r', arguments: [1,2,3]}, { name: '-i', arguments: ['file1.txt']}, { name: '-o', arguments: ['file3.txt']} ], "1f83f620-c1ed-11e5-9657-7942989daa00");
-                expect(result).to.equal('dcdFilePrint -r 1 2 3 -s 10 -e 100 -d 10 -m 0 -i /Users/Takafumi/zephyr/server/class/../../user-specific-files/workspace/file1.txt -o /Users/Takafumi/zephyr/server/class/../../user-specific-files/workspace/file3.txt');
+                expect(result).to.equal('dcdFilePrint -r 1 2 3 -s 10 -e 100 -d 10 -m 0 -i /Users/hiratakengo/zephyr/server/class/../../user-specific-files/workspace/file1.txt -o /Users/hiratakengo/zephyr/server/class/../../user-specific-files/workspace/file3.txt');
             });
         });
 
         var toExecArray = `
         /**
-        * 実行時配列への変換 
+        * 実行時配列への変換
         *
         * @param command
         * @returns {string}
             });
 
         });
-        
+
         describe('execute', function() {
             before(function() {
                 process.env.NODE_ENV = '';
         var getUUIDs = `
         /**
         * function getUUIDs(fileId)
-        * uuidとファイル名のkey-valueを取得 
+        * uuidとファイル名のkey-valueを取得
         *
         * @param fileId
         * @returns {object} key: filename, value: uuid