This repository has been archived by the owner on May 27, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24 from eapowertools/convert-to-csv
Convert to csv
- Loading branch information
Showing
20 changed files
with
617 additions
and
231 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
#ignoring folders | ||
tmp/ | ||
tests/ | ||
|
||
# Logs | ||
logs | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
var csv = require('csvjson'); | ||
var cfg = require("../config/config") | ||
var path = require("path"); | ||
var winston = require("winston"); | ||
var fs = require('fs'); | ||
|
||
//set up logging | ||
var logger = new(winston.Logger)({ | ||
level: cfg.logLevel, | ||
transports: [ | ||
new(winston.transports.Console)(), | ||
new(winston.transports.File)({ filename: cfg.logFile }) | ||
] | ||
}); | ||
|
||
module.exports = function() { | ||
var appsFile = fs.readFileSync(path.join(cfg.csvFilePath, "app_paths.csv"), { encoding: 'utf8' }); | ||
|
||
var appsArray = csv.toObject(appsFile); | ||
if (appsArray.length > 0) { | ||
logger.info("appPaths: ", appsArray.length, " apps loaded"); | ||
} else { | ||
logger.info("appPaths: no apps parsed from csv file"); | ||
throw new Error("error: no apps parsed from csv file"); | ||
} | ||
return appsArray; | ||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
var csv = require('csvjson'); | ||
var cfg = require("../config/config") | ||
var path = require("path"); | ||
var winston = require("winston"); | ||
var fs = require('fs'); | ||
|
||
//set up logging | ||
var logger = new(winston.Logger)({ | ||
level: cfg.logLevel, | ||
transports: [ | ||
new(winston.transports.Console)(), | ||
new(winston.transports.File)({ filename: cfg.logFile }) | ||
] | ||
}); | ||
|
||
module.exports = { | ||
loadUsers: function(userFile, attributeFile) { | ||
logger.info('parseUdcFiles: Reading csv files (', cfg.csvFilePath, ")..."); | ||
var usersFile = fs.readFileSync(path.join(cfg.csvFilePath, userFile), { encoding: 'utf8' }); | ||
|
||
var attributesFile = fs.readFileSync(path.join(cfg.csvFilePath, attributeFile), { encoding: 'utf8' }); | ||
|
||
var userArray = csv.toObject(usersFile); | ||
if (userArray.length > 0) { | ||
logger.info("parseUdcFiles: ", userArray.length, " users loaded"); | ||
} else { | ||
logger.info("parseUdcFiles: no users parsed from csv file"); | ||
throw new Error("error: no users parsed from csv file"); | ||
} | ||
|
||
var attributesArray = csv.toObject(attributesFile); | ||
if (attributesArray.length > 0) { | ||
logger.info("parseUdcFiles: ", attributesArray.length, " attribute records loaded"); | ||
} else { | ||
logger.info("parseUdcFiles: no attributes parsed from csv file"); | ||
throw new Error("error: No attributes parsed from attributes file"); | ||
} | ||
|
||
|
||
var Users = {}; | ||
|
||
userArray.forEach(function(user, index) { | ||
var User = { | ||
userid: user.userid, | ||
name: user.name | ||
}; | ||
|
||
|
||
|
||
var userAttributes = attributesArray.filter(function(item) { | ||
return item.userid == User.userid; | ||
}); | ||
|
||
var userGroups = []; | ||
var userApps = []; | ||
|
||
userAttributes.forEach(function(item) { | ||
switch (item.type) { | ||
case "group": | ||
userGroups.push(item.value); | ||
break; | ||
case "app": | ||
userApps.push(item.value); | ||
break; | ||
case "image": | ||
User.image = item.value; | ||
break; | ||
case "udc": | ||
User.udc = item.value; | ||
break; | ||
case "title": | ||
User.title = item.value; | ||
break; | ||
default: | ||
User[item.type] = item.value; | ||
|
||
} | ||
}); | ||
|
||
User.groups = userGroups; | ||
User.apps = userApps; | ||
Users[index] = User; | ||
}) | ||
|
||
var config = {}; | ||
config.users = Users; | ||
logger.info("Completed parsing UDC csv files."); | ||
return config; | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.