Skip to content

Commit

Permalink
Code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
mountaindude committed Nov 16, 2023
1 parent 986beff commit d9db29f
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 126 deletions.
177 changes: 92 additions & 85 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"request": "launch",
"name": "Launch Program",
"program": "${workspaceFolder}/src/ctrl-q.js",
"runtimeVersion": "19",
"runtimeVersion": "20",
"cwd": "${workspaceFolder}",

// ------------------------------------
Expand Down Expand Up @@ -100,38 +100,45 @@
// ------------------------------------
// Import tasks from CSV file
// ------------------------------------
// "args": [
// "task-import",
// "--auth-type",
// "cert",
// "--host",
// "192.168.100.109",
// // "--auth-cert-file",
// // "./cert/client.pem",
// // "--auth-cert-key-file",
// // "./cert/client_key.pem",
// "--auth-user-dir",
// "LAB",
// "--auth-user-id",
// "goran",
"args": [
"task-import",
"--auth-type",
"cert",
"--host",
// "192.168.100.109",
"10.211.55.15",

// "--file-type",
// "csv",
"--auth-cert-file",
"../../code/secret/winsrv.local/client.pem",
"--auth-cert-key-file",
"../../code/secret/winsrv.local/client_key.pem",
// "--auth-cert-file",
// "./cert/client.pem",
// "--auth-cert-key-file",
// "./cert/client_key.pem",
"--auth-user-dir",
"winsrv1",
// "LAB",
"--auth-user-id",
"goran",

// "--file-name",
// // "tasks2source.csv",
// // "task-chain.csv",
// // "testdata/reload-tasks.csv",
// "./tasks5.csv",
"--file-type",
"csv",

// // "--qvf-overwrite",
// // "no",
"--file-name",
// "tasks2source.csv",
// "task-chain.csv",
// "testdata/reload-tasks.csv",
"./tasks_all.csv",

// // "--limit-import-count",
// // "2",
// "--qvf-overwrite",
// "no",

// // "--dry-run"
// ]
"--limit-import-count",
"2",

// "--dry-run"
]

// ------------------------------------
// Export apps to QVF files
Expand Down Expand Up @@ -319,69 +326,69 @@
// "comprule"
// ]

------------------------------------
Get reload tasks as CSV/Excel/JSON file
------------------------------------
"args": [
"task-get",
"--auth-type",
"cert",
"--host",
"192.168.100.109",
// "--auth-cert-file",
// "./cert/client.pem",
// "--auth-cert-key-file",
// "./cert/client_key.pem",
"--auth-user-dir",
"LAB",
"--auth-user-id",
"goran",
// "--task-id",
// "82bc3e66-c899-4e44-b52f-552145da5ee0",
// "82bc3e66-c899-4e44-b52f-552145da5ee1",
// "5748afa9-3abe-43ab-bb1f-127c48ced075",
// "5520e710-91ad-41d2-aeb6-434cafbf366b",
// "--task-tag",
// "Ctrl-Q demo",
// "Butler 5.0 demo",

"--output-format",
"table",
"--output-dest",
"file",
"--output-file-name",
// "tasks.xlsx",
// "tasks.csv",
"tasks_all.csv",
// "tasks2.json",
// "tasks2.xlsx",
"--output-file-format",
// "excel",
// "json",
"csv",
// ------------------------------------
// Get reload tasks as CSV/Excel/JSON file
// ------------------------------------
// "args": [
// "task-get",
// "--auth-type",
// "cert",
// "--host",
// "192.168.100.109",
// // "--auth-cert-file",
// // "./cert/client.pem",
// // "--auth-cert-key-file",
// // "./cert/client_key.pem",
// "--auth-user-dir",
// "LAB",
// "--auth-user-id",
// "goran",
// // "--task-id",
// // "82bc3e66-c899-4e44-b52f-552145da5ee0",
// // "82bc3e66-c899-4e44-b52f-552145da5ee1",
// // "5748afa9-3abe-43ab-bb1f-127c48ced075",
// // "5520e710-91ad-41d2-aeb6-434cafbf366b",
// // "--task-tag",
// // "Ctrl-Q demo",
// // "Butler 5.0 demo",

// "--output-format",
// "table",
// "--output-dest",
// "file",
// "--output-file-name",
// // "reload-tasks.xlsx",
// "reload-tasks.csv",
// // "tasks.xlsx",
// // "tasks.csv",
// "tasks_all.csv",
// // "tasks2.json",
// // "tasks2.xlsx",
// "--output-file-format",
// // "excel",
// // "json",
// "csv",

// // "--text-color",
// // "no",
// // "--output-file-name",
// // // "reload-tasks.xlsx",
// // "reload-tasks.csv",

// // "--output-file-overwrite",
// // // "--text-color",
// // // "no",

// "--table-details",
// // "common",
// // "lastexecution",
// // "tag",
// // "customproperty",
// // "schematrigger",
// // "compositetrigger",
// // "comptimeconstraint",
// // "comprule",
// // // "--output-file-overwrite",

// // "--log-level",
// // "debug"
// ]
// // "--table-details",
// // // "common",
// // // "lastexecution",
// // // "tag",
// // // "customproperty",
// // // "schematrigger",
// // // "compositetrigger",
// // // "comptimeconstraint",
// // // "comprule",

// // // "--log-level",
// // // "debug"
// // ]

// ------------------------------------
// Create custom property with user activity buckets
Expand Down
2 changes: 1 addition & 1 deletion src/ctrl-q.js
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,7 @@ const program = new Command();
taskImportAssertOptions(options);
importTaskFromFile(options);
} catch (err) {
logger.error(`IMPORT TASK: ${err}`);
logger.error(`IMPORT TASK 1: ${err}`);
}
})
.addOption(
Expand Down
55 changes: 15 additions & 40 deletions src/lib/cmd/importtask.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,65 +15,40 @@ const { getCustomPropertiesFromQseow } = require('../util/customproperties');

const getHeaders = async (options) => {
const records = [];

const parser = fs.createReadStream(options.fileName).pipe(
parse({
info: true,
to_line: 1,
skip_empty_lines: true,
})
);
parser.on('readable', () => {
let record;
while ((record = parser.read()) !== null) {
// Work with each record
records.push(record);

// Get the header row
// eslint-disable-next-line no-restricted-syntax
for await (const record of parser) {
if (record.info.lines === 1) {
// Header row
records.push(record.record);
}
});
await finished(parser);
}

return records;
};

const processCsvFile = async (options) => {
// First get header row

// const parser = parse({
// delimiter: ',',
// info: true,
// // to_line: 1,
// });

// const parser = fs.createReadStream(options.fileName).pipe(
// parse({
// info: true,
// to_line: 1,
// }).pipe(process.stdout)
// );

const headers = await getHeaders(options);

// const headers = fs.createReadStream(options.fileName).pipe(parser).pipe(process.stdout);

// const content = await fsp.readFile(options.fileName);

// Parse the CSV content
// const headers = parse(content, { bom: true, to_line: 1 });

const headerRow = [];

// Push all column headers to array
// eslint-disable-next-line no-restricted-syntax
for (const record of headers) {
for (const record of headers[0]) {
// Get each column header text
headerRow.push(record.record);
headerRow.push(record);
}
// // eslint-disable-next-line no-restricted-syntax
// for await (const record of headers) {
// // for await (const record of parser) {
// // Get each column header text
// headerRow.push(record.record);
// }

// Get positions of column headers
const colHeaders = getTaskColumnPosFromHeaderRow(headerRow[0]);
const colHeaders = getTaskColumnPosFromHeaderRow(headerRow);

const records = [];
const parser = fs.createReadStream(options.fileName).pipe(
Expand Down Expand Up @@ -439,7 +414,7 @@ const importTaskFromFile = async (options) => {
await qlikSenseTasks.init(options, importedApps);
const taskList = await qlikSenseTasks.getTaskModelFromFile(tasksFromFile, tagsExisting, cpExisting);
} catch (err) {
logger.error(`IMPORT TASK: ${err.stack}`);
logger.error(`IMPORT TASK 2: ${err.stack}`);
}
};

Expand Down

0 comments on commit d9db29f

Please sign in to comment.