[TIC-Web] change the default path of tic-web 36/111636/1
authorChangHyun Lee <leechwin.lee@samsung.com>
Mon, 23 Jan 2017 07:23:56 +0000 (16:23 +0900)
committerChangHyun Lee <leechwin.lee@samsung.com>
Mon, 23 Jan 2017 07:23:56 +0000 (16:23 +0900)
- change the default path to /var/tmp/tic-web

Change-Id: I9423f384038afef645a96b73af738395a3a5bd3a
Signed-off-by: ChangHyun Lee <leechwin.lee@samsung.com>
config.json
public/src/js/page/image.js
public/src/js/page/package.js
server/fs/filesystem.js
server/fs/mic.js

index 4f6014a..f7b2098 100644 (file)
@@ -1,13 +1,13 @@
 {
     "TIC_WEB": {
         "PORT" : 8081,
-        "LOG_FILE" : "/tmp/tic/tic-web.log"
+        "LOG_FILE" : "/var/tmp/tic-web/tic-web.log",
+        "KS_OUT_DIR" : "/var/tmp/tic-web/ks/"
     },
     "TIC_CORE": {
-        "PORT" : 8082,
-        "KS_OUT_DIR" : "/tmp/tic/ks/"
+        "PORT" : 8082
     },
     "MIC" : {
-        "OUT_DIR" : "/tmp/tic/images/"
+        "OUT_DIR" : "/var/tmp/tic-web/images/"
     }
 }
\ No newline at end of file
index 82e801b..5a622f1 100644 (file)
@@ -174,7 +174,7 @@ define([
                     name: 'default'
                 },
                 packages: _.map(checkedPackagesList, 'name'),
-                output: AppConfig.TIC_CORE.KS_OUT_DIR
+                output: AppConfig.TIC_WEB.KS_OUT_DIR
             };
             return Util.POST(getExportsUrl(), msgData)
             .then(function (result) {
index 936e425..27885c2 100644 (file)
@@ -24,15 +24,10 @@ define([
     var groups = null;
     var groupId = 0;
 
-    if (!Date.now) { Date.now = function now() {
-            return new Date().getTime();
-        };
-    }
-
     function _getChecked() {
         var checkedList = [];
-        _.forEach(pkgInfo, function(value, key){
-            if(value.view[0].state.checked === true){
+        _.forEach(pkgInfo, function(value, key) {
+            if(value.view[0].state.checked === true) {
                 checkedList.push(value);
             }
         });
@@ -54,9 +49,9 @@ define([
     function _setDefaultPackage(defaultPackages) {
         var nodes = []
         var pickDefault = _.pick(pkgInfo, defaultPackages);
-        _.forEach(pickDefault, function(value, key){
+        _.forEach(pickDefault, function(value, key) {
             // One or more of the same nodes can exist
-            _.forEach(value.view, function(node){
+            _.forEach(value.view, function(node) {
                 nodes.push(node);
             });
         });
@@ -70,11 +65,11 @@ define([
     // Compares two rpm version numbers (e.g. "1.7.1" or "1.2b").
     // This function is based on https://gist.github.com/em92/d58944f21c68b69433cefb6c49e0defd
     function versionCompare(v1, v2, options) {
-        if(!v1 && !v2){
+        if (!v1 && !v2) {
             return 0;
-        } else if(!v2){
+        } else if (!v2) {
             return 1;
-        } else if(!v1){
+        } else if (!v1) {
             return -1;
         }
 
@@ -90,22 +85,22 @@ define([
             }
 
             for (var i = 0; i < v1parts.length; ++i) {
-                if (v2parts.length == i) {
+                if (v2parts.length === i) {
                     return 1;
                 }
 
                 var v1part = parseInt(v1parts[i]);
                 var v2part = parseInt(v2parts[i]);
                 // (NaN == NaN) -> false
-                var v1part_is_string = !(v1part == v1part);
-                var v2part_is_string = !(v2part == v2part);
+                var v1part_is_string = !(v1part === v1part);
+                var v2part_is_string = !(v2part === v2part);
                 v1part = v1part_is_string ? v1parts[i] : v1part;
                 v2part = v2part_is_string ? v2parts[i] : v2part;
 
-                if (v1part_is_string == v2part_is_string) {
-                    if (v1part_is_string == false) {
+                if (v1part_is_string === v2part_is_string) {
+                    if (v1part_is_string === false) {
                         // integer compare
-                        if (v1part == v2part) {
+                        if (v1part === v2part) {
                             continue;
                         } else if (v1part > v2part) {
                             return 1;
@@ -117,11 +112,11 @@ define([
                         // split letters and numbers
                         var v1subparts = v1part.match(/[a-zA-Z]+|[0-9]+/g);
                         var v2subparts = v2part.match(/[a-zA-Z]+|[0-9]+/g);
-                        if ( (v1subparts.length == 1) && (v2subparts.length == 1) ) {
+                        if ( (v1subparts.length === 1) && (v2subparts.length === 1) ) {
                             // only letters in string
                             v1part = v1subparts[0];
                             v2part = v2subparts[0];
-                            if (v1part == v2part) {
+                            if (v1part === v2part) {
                                 continue;
                             } else if (v1part > v2part) {
                                 return 1;
@@ -130,7 +125,7 @@ define([
                             }
                         }
                         var result = compareParts(v1subparts, v2subparts);
-                        if (result == 0) {
+                        if (result === 0) {
                             continue;
                         } else {
                             return result;
@@ -164,56 +159,57 @@ define([
         var min_num = new Array(pkg_count);
 
         // init check type
-        _.forEach(pkgInfo, function(value, key){
+        _.forEach(pkgInfo, function(value, key) {
             // check type: -1(unchecked), 0(checked), 1~N(checking)
             selected[value.id] = value.view[0].state.checked ? 0 : -1;
             scc_id[value.id] = 0;
         });
 
-        function _comapre_ver(ver1, ver2, flag){
+        function _comapre_ver(ver1, ver2, flag) {
             var epoch1 = ver1.epoch;
             var epoch2 = ver2.epoch;
             // epoch is a number (optional, default=0)
             epoch1 = epoch1 ? epoch1 : 0;
             epoch2 = epoch2 ? epoch2 : 0;
 
-            if (epoch1 == epoch2){
+            if (epoch1 === epoch2) {
                 var result = versionCompare(ver1.ver, ver2.ver);
                 // version match (ver1 == ver2)
-                if(result == 0){
+                if (result === 0) {
                     // flag == true means to compare versions between require and provide
-                    if(!flag || ver1.rel){
+                    if (!flag || ver1.rel) {
                         return versionCompare(ver1.rel, ver2.rel);
                     }
                     return result;
                 }
                 return result;
-            } else if(epoch1 > epoch2){
+            } else if (epoch1 > epoch2) {
                 return 1
             } else {
                 return -1;
             }
         }
 
-        function _makeSCC(pkgId){
+        function _makeSCC(pkgId) {
             sccNum += 1;
             var sccList = [];
 
             // make scc
-            while(!_.isEmpty(stack)){
+            while(!_.isEmpty(stack)) {
                 var pkg = stack.pop();
                 scc_id[pkg.id] = sccNum;
                 sccList.push(pkg);
 
-                if(pkg.id === pkgId)
+                if (pkg.id === pkgId) {
                     break;
+                }
             }
 
             // circular depependency
-            if (sccList.length > 1){
+            if (sccList.length > 1) {
                 groupId += 1;
                 var groupPkgList = [];
-                _.forEach(sccList, function(pkg){
+                _.forEach(sccList, function(pkg) {
                     pkg.group = groupId;
                     groupPkgList.push(pkg.name);
                 });
@@ -222,38 +218,38 @@ define([
             }
         }
 
-        function _createReference(node1, node2){
-            if(!_.isEmpty(node1.forward) && _.includes(node1.forward, node2.name))
+        function _createReference(node1, node2) {
+            if (!_.isEmpty(node1.forward) && _.includes(node1.forward, node2.name))
                 return
 
-            if(!_.isEmpty(node1.forward)){
+            if (!_.isEmpty(node1.forward)) {
                 node1.forward.push(node2.name);
             } else {
                 node1.forward = [node2.name];
             }
 
-            if(!_.isEmpty(node2.backward)){
+            if (!_.isEmpty(node2.backward)) {
                 node2.backward.push(node1.name);
             } else {
                 node2.backward = [node1.name];
             }
         }
 
-        function _select_rpm(capability, require){
-            if(capability.length == 1){
+        function _select_rpm(capability, require) {
+            if (capability.length === 1) {
                 return pkgInfo[capability[0].name];
             }
 
             var provideList = [];
             // 1. Choose the rpm included in version from provides
-            if (require.ver){
-                _.forEach(capability, function(provide){
+            if (require.ver) {
+                _.forEach(capability, function(provide) {
                     var cmpResult = _comapre_ver(require, provide.data, true);
-                    if (cmpResult === 0 && _.includes(['EQ', 'GE', 'LE'], require.flags)){
+                    if (cmpResult === 0 && _.includes(['EQ', 'GE', 'LE'], require.flags)) {
                         provideList.push(provide);
-                    } else if(cmpResult === 1 && _.includes(['LT', 'LE'], require.flags)){
+                    } else if (cmpResult === 1 && _.includes(['LT', 'LE'], require.flags)) {
                         provideList.push(provide);
-                    } else if(cmpResult === -1 && _.includes(['GT', 'GE'], require.flags)){
+                    } else if (cmpResult === -1 && _.includes(['GT', 'GE'], require.flags)) {
                         provideList.push(provide);
                     }
                 });
@@ -262,30 +258,30 @@ define([
             }
 
             // error case (the rpm does not exist)
-            if (_.isEmpty(provideList)){
+            if (_.isEmpty(provideList)) {
                 return null;
             }
 
-            if (provideList.length == 1){
+            if (provideList.length === 1) {
                 return pkgInfo[provideList[0].name];
             }
 
             // 2 Select one of the rpms by priority
             // 2-1. Choose the default rpm or the selected rpm
             // TODO: default profile rpm should be selected
-            _.forEach(provideList, function(provide){
+            _.forEach(provideList, function(provide) {
                 var tmpInfo = pkgInfo[provide.name];
-                if(tmpInfo.view[0].state.checked || selected[tmpInfo.id] >= 1){
+                if (tmpInfo.view[0].state.checked || selected[tmpInfo.id] >= 1) {
                     return tmpInfo;
                 }
             });
 
             var maxVersion = null;
             // # 2-2. Select the latest version of rpm
-            _.forEach(provideList, function(provide){
-                if(maxVersion){
+            _.forEach(provideList, function(provide) {
+                if (maxVersion) {
                     var ret = _comapre_ver(maxVersion.data, provide.data)
-                    if(ret == -1){
+                    if (ret === -1) {
                         maxVersion = provide;
                     }
                 } else {
@@ -296,7 +292,7 @@ define([
             return pkgInfo[maxVersion.name];
         }
 
-        function _analyzeDep(node){
+        function _analyzeDep(node) {
             var pkgId = node.id;
             number += 1;
             selected[pkgId] = number;
@@ -308,31 +304,31 @@ define([
 
             // installation dependency analysis of package
             // TODO: recommends
-            _.forEach(['requires'], function(depTag){
-                if(_.has(node, depTag)){
-                    _.forEach(node.requires, function(require){
+            _.forEach(['requires'], function(depTag) {
+                if (_.has(node, depTag)) {
+                    _.forEach(node.requires, function(require) {
                         var choose = null;
 
-                        if(_.has(provides, require.name)){
+                        if (_.has(provides, require.name)) {
                             var capList = provides[require.name];
                             choose = _select_rpm(capList, require);
-                        } else if(_.has(files, require.name)){
+                        } else if (_.has(files, require.name)) {
                             choose = pkgInfo[files[require.name][0]];
                         }
 
-                        if (choose){
+                        if (choose) {
                             // add forward/backward reference
                             _createReference(node, choose);
 
-                            if(selected[choose.id] == -1){
+                            if (selected[choose.id] === -1) {
                                 var result = _analyzeDep(choose);
-                                _.forEach(result, function(value, key){
-                                     if(!_.has(dependents, key)){
+                                _.forEach(result, function(value, key) {
+                                     if (!_.has(dependents, key)) {
                                          dependents[key] = value;
                                      }
                                 });
                                 min_num[pkgId] = Math.min(min_num[pkgId], min_num[choose.id])
-                            } else if(selected[choose.id] >= 1 && scc_id[choose.id] == 0){
+                            } else if (selected[choose.id] >= 1 && scc_id[choose.id] === 0) {
                                 // cross edge that can not be ignored
                                 min_num[pkgId] = Math.min(min_num[pkgId], min_num[choose.id])
                             }
@@ -343,7 +339,7 @@ define([
                 }
             });
 
-            if (min_num[pkgId] == selected[pkgId]){
+            if (min_num[pkgId] === selected[pkgId]) {
                 _makeSCC(pkgId);
             }
 
@@ -356,13 +352,13 @@ define([
     // analyze uncheck dependency
     function _analyzeUncheckDependency(uncheckNode) {
 
-        function _checkCircularDependency(node){
+        function _checkCircularDependency(node) {
             var groupId = node.group
             var groupPkgList = groups[groupId];
             var groupObj = {};
 
             // Set object for group
-            _.forEach(groupPkgList, function(pkgName){
+            _.forEach(groupPkgList, function(pkgName) {
                 groupObj[pkgName] = null;
             });
 
@@ -371,22 +367,22 @@ define([
                 var pkg = _find(pkgName);
 
                 // the node is selfChecked or uncheckable
-                if(pkg.selfChecked || !isUncheckable){
+                if (pkg.selfChecked || !isUncheckable) {
                     isUncheckable = false;
                     return false;
                 }
 
                 _.forEach(pkg.backward, function(backRef) {
-                    // If node is Referenced by another node (Not a node in the group), 
+                    // If node is Referenced by another node (Not a node in the group),
                     // unable to uncheck group nodes
-                    if(!_.has(groupObj, backRef)){
+                    if (!_.has(groupObj, backRef)) {
                         isUncheckable = false;
                         return false;
                     }
                 });
             });
 
-            if(isUncheckable){
+            if (isUncheckable) {
                 // init visited obj
                 groupVisited[groupId] = {};
 
@@ -406,27 +402,29 @@ define([
             }
         }
 
-        function _analyzeUncheck(parent, node){
-            if(!_.isEmpty(parent)){
+        function _analyzeUncheck(parent, node) {
+            if (!_.isEmpty(parent)) {
                 // TODO: performance
-                if(!_.isEmpty(node.backward)){
+                if (!_.isEmpty(node.backward)) {
                     var bIndex = node.backward.indexOf(parent.name);
-                    if(bIndex > -1){
+                    if (bIndex > -1) {
                         // TODO: performance
                         // remove backward reference (parent)
                         node.backward.splice(bIndex, 1);
                     }
                 }
                 // selfCheck node is not unchecked
-                if (node.selfChecked == true)
+                if (node.selfChecked === true) {
                     return null;
+
+                }
             }
 
             var uncheckPkgs = null;
             // Check that the selected node is uncheckable
-            if(!_.isEmpty(node.backward)){
+            if (!_.isEmpty(node.backward)) {
                 // check circular dependency
-                if(!node.group || !_checkCircularDependency(node)){
+                if (!node.group || !_checkCircularDependency(node)) {
                     return null;
                 }
             }
@@ -435,28 +433,28 @@ define([
             uncheckPkgs = {};
             uncheckPkgs[node.name] = node;
             // uncheckable pkg of group
-            if(node.group && !_.isEmpty(groupVisited[node.group])){
+            if (node.group && !_.isEmpty(groupVisited[node.group])) {
                 groupVisited[node.group][node.name] = 1;
             }
 
             // if selected node has forward references
-            if(!_.isEmpty(node.forward)){
-                _.forEach(node.forward, function(fname){
+            if (!_.isEmpty(node.forward)) {
+                _.forEach(node.forward, function(fname) {
                     var forwardNode = _find(fname);
 
                     // If pkg has a circular dependency and is unchekcable,
                     // circular dep. pkgs can only be visited once
                     var fvisit = groupVisited[forwardNode.group];
-                    if(!_.isEmpty(fvisit) && fvisit[fname] === 1){
+                    if (!_.isEmpty(fvisit) && fvisit[fname] === 1) {
                         return; // continue;
                     }
 
                     var result = _analyzeUncheck(node, forwardNode);
 
                     // updates pkgs for uncheck
-                    if(!_.isEmpty(result)){
-                        _.forEach(result, function(value, key){
-                            if(!_.has(uncheckPkgs, key)){
+                    if (!_.isEmpty(result)) {
+                        _.forEach(result, function(value, key) {
+                            if (!_.has(uncheckPkgs, key)) {
                                 uncheckPkgs[key] = value;
                             }
                         });
@@ -475,8 +473,8 @@ define([
         var uncheckPkgs = _analyzeUncheck(null, uncheckNode);
 
         // delete groupId from groups
-        _.forEach(groupVisited, function(groupList, groupId){
-            if(!_.isEmpty(groups[groupId])){
+        _.forEach(groupVisited, function(groupList, groupId) {
+            if (!_.isEmpty(groups[groupId])) {
                 delete groups[groupId];
             }
         });
@@ -541,7 +539,7 @@ define([
             text.html(pkg.name);
         }
         if (!_.isEmpty(pkg.version)) {
-            if(!_.isEmpty(pkg.version.rel)){
+            if (!_.isEmpty(pkg.version.rel)) {
                 version.html(pkg.version.ver + '-' + pkg.version.rel);
             } else {
                 version.html(pkg.version.ver);
@@ -572,7 +570,7 @@ define([
      * Treeview: A node is checked.
      */
     function _onNodeChecked(event, node) {
-        var startTS = Date.now();
+        var startTS = performance.now();
         var localNode = _find(node.text);
         if (localNode.view[0].state.checked === true) {
             $tree.treeview('uncheckNode', [node, { silent: false }]);
@@ -588,11 +586,11 @@ define([
         // analyze install-dependency (requires)
         var depPkg = _analyzeInstallDependency(localNode)
 
-        var analyzeTS = Date.now();
+        var analyzeTS = performance.now();
 
         // TODO: temporary code
         var tempcode = [];
-        _.forEach(depPkg, function(value, key){ tempcode.push(value.name); });
+        _.forEach(depPkg, function(value, key) { tempcode.push(value.name); });
         logger.info(localNode.name + ' install-dependency(' + tempcode.length +'): ' + tempcode);
 
         var toggleNode = [];
@@ -612,7 +610,7 @@ define([
             });
             _updateSummary();
 
-            var endTS = Date.now();
+            var endTS = performance.now();
             logger.info('[Check] Total time: ' + (endTS - startTS) + 'ms');
             logger.info('[Check] Analyze dep. time: ' + (analyzeTS - startTS) + 'ms');
             logger.info('[Check] Update view time: ' + (endTS - analyzeTS) + 'ms');
@@ -623,7 +621,7 @@ define([
      * Treeview: A node is unchecked.
      */
     function _onNodeUnchecked(event, node) {
-        var startTS = Date.now();
+        var startTS = performance.now();
         var localNode = _find(node.text);
         if (localNode.view[0].state.checked === false) {
             $tree.treeview('checkNode', [node, { silent: false }]);
@@ -634,17 +632,17 @@ define([
 
         var uncheckPkgs = _analyzeUncheckDependency(localNode);
 
-        var analyzeTS = Date.now();
+        var analyzeTS = performance.now();
 
         // TODO: temporary code
         var tempcode = [];
-        _.forEach(uncheckPkgs, function(value, key){ tempcode.push(value.name); });
+        _.forEach(uncheckPkgs, function(value, key) { tempcode.push(value.name); });
         logger.info(localNode.name + ' uncheck-dependency(' + tempcode.length +'): ' + tempcode);
 
         var toggleNode = [];
-        if(!_.isEmpty(uncheckPkgs)) {
-            _.forEach(uncheckPkgs, function(value, key){
-                _.forEach(value.view, function(node){
+        if (!_.isEmpty(uncheckPkgs)) {
+            _.forEach(uncheckPkgs, function(value, key) {
+                _.forEach(value.view, function(node) {
                     if (node.state.checked === true) {
                         toggleNode.push(node);
                     }
@@ -668,7 +666,7 @@ define([
             node.state.checked = true;
         }
 
-        var endTS = Date.now();
+        var endTS = performance.now();
         logger.info('[Uncheck] Total time: ' + (endTS - startTS) + 'ms');
         logger.info('[Uncheck] Analyze dep. time: ' + (analyzeTS - startTS) + 'ms');
         logger.info('[Uncheck] Update view time: ' + (endTS - analyzeTS) + 'ms');
@@ -684,7 +682,7 @@ define([
         files = rawData.data.files;
         groups = rawData.data.groups;
 
-        _.forEach(groups, function(value, key){
+        _.forEach(groups, function(value, key) {
             groupId += 1;
         })
 
@@ -696,7 +694,7 @@ define([
                      // add a reference variable for treeview
                      var pkg = pkgInfo[node.text]
                      if (pkg) {
-                         if(_.isEmpty(pkg.view)){
+                         if (_.isEmpty(pkg.view)) {
                              pkg.view = [node];
                          } else {
                              pkg.view.push(node);
@@ -809,7 +807,7 @@ define([
     return {
         /**
          * Initialize for treeview
-         * @method updatePackageTreepkginfo
+         * @method updatePackageTree
          * @param {array} array of objects
          * @return Promise
          */
index da5ac2a..6045b20 100644 (file)
@@ -4,19 +4,15 @@ var fs = require('fs');
 var mime = require('mime');
 var path = require('path');
 var mkdirp = require('mkdirp');
+var AppConfig = require('../../config.json');
+
 var JL = require('jsnlog').JL;
 
 var logger = JL('filesystem.js');
 
 var FileSystem = {};
-FileSystem.PATH_KS = '/tmp/tic/ks/';
-FileSystem.PATH_IMAGES = '/tmp/tic/images/';
 
 FileSystem.init = function () {
-    var ticKs, ticImages;
-
-    ticKs = this.PATH_KS;
-    ticImages = this.PATH_IMAGES;
 
     function fnMkdir(paramPath) {
         mkdirp(paramPath, function (err) {
@@ -28,8 +24,8 @@ FileSystem.init = function () {
         });
     }
 
-    fnMkdir(ticKs);
-    fnMkdir(ticImages);
+    fnMkdir(AppConfig.TIC_WEB.KS_OUT_DIR);
+    fnMkdir(AppConfig.MIC.OUT_DIR);
 };
 
 FileSystem.list = function (dirPath) {
@@ -66,7 +62,7 @@ FileSystem.download = function (req, res) {
     var fileName, filePath, fileMimetype, fileStream;
 
     fileName = req.params.filename;
-    filePath = this.PATH_IMAGES + fileName;
+    filePath = AppConfig.MIC.OUT_DIR + fileName;
     fileMimetype = mime.lookup(filePath);
 
     res.setHeader('Content-disposition', 'attachment; filename=' + fileName);
index 49a0c5b..c17dfc8 100644 (file)
@@ -65,7 +65,7 @@ Mic.create = function (paramObj, io) {
             // code is the final exit code of the process, otherwise null
             ps = null;
             logger.error('Terminated (' + code + ')');
-            if (code != null) {
+            if (code === 0) {
                 sendMsg(SocketEvent.FS_IMAGE_ADD_FINISH, 'Terminated (' + code + ')');
             } else {
                 sendMsg(SocketEvent.FS_IMAGE_ADD_FAIL, 'Failed (' + code + ')');