Commit 8ec3c2db authored by Nong Hoang Tu's avatar Nong Hoang Tu
Browse files

Add file header and comments

parent 4cae238e
#[
Description:
Contains core objects to use in tool and proc that parses configs,
check avaiable programs.
Authors: 2020, Nong Hoang Tu <dmknght@parrotsec.org>
Contributors:
Module structure:
- Objects:
+ Err: Return code of functions
+ LogHandler: Control console logs and file logs
+ DebPackage: Control information of package to update
+ ProgConf: Get all configurations from config file
- Proc:
+ checkPrograms: Check if full path of gbp and uscan is available
+ parseUscanOutput: Parse output of uscan. This is used from cmdutils
+ dirName: Add `/` to name of directory
+ initConfig: Load configuration from file and check if each config is valid
TODO:
]#
import logging
import os
import json
......@@ -9,7 +29,6 @@ type
updated,
outdated,
updateSuccess,
checkVersionErr,
failed
LogHandler* = object
print*: ConsoleLogger
......@@ -27,9 +46,9 @@ type
devName*: string
devMail*: string
# TODO variables for config parser, logger
var mainLog = newConsoleLogger(fmtStr="$levelname [$date $time] ")
proc checkPrograms(gbpPath, uscanPath: string): bool =
if not fileExists(gbpPath):
mainLog.log(lvlError, gbpPath & " not found. Try install git-buildpackage")
......@@ -41,6 +60,10 @@ proc checkPrograms(gbpPath, uscanPath: string): bool =
proc parseUscanOutput*(line: string, localVer, serverVer: var string) =
#[
Parse output of uscan when project is outdated.
Get the value of project's current version and server version
]#
let tmpLine = line.split(",")
serverVer = tmpLine[0].split(" ")[^1]
localVer = tmpLine[1].split(" ")[^1]
......
#[
Description:
Control workflow of update, clone and pull.
Authors: 2020, Nong Hoang Tu <dmknght@parrotsec.org>
Contributors:
Module structure:
- doUpdateProject: Control the way a project is updated
- updateProjectAll: Call doUpdateProject for all projects in root_folder
- updateProjectArr: Call doUpdateProject, update projects that were given by user
- pullProjectAll: Pull all projects in root_folder
- pullProjectArr: Pull projects were given by user
- cloneProject: Clone projects were given by user
- handleUpdateProject: Select updateProjectArr or updateProjectAll by
number of projects were given by user. This proc is called from main
- handlePullProject: Select updatePulltArr or updatePullAll by
number of projects were given by user. This proc is called from main
TODO:
]#
import configs
import .. / interfaces / logutils
import .. / update / cmdutils
......@@ -5,6 +25,15 @@ import os
proc doUpdateProject(config: ProgConf, project: DebPackage): Err =
#[
Workflow:
1. Pull project to sync changes from manual packaging
2. Check for update
3. Upgrade source code
4. Create changelog
5. Create tag
6. Push
]#
var stderr, localVer, serverVer: string
if gbpPull(config.uscanPath, project.path, stderr) != 0:
......@@ -17,7 +46,7 @@ proc doUpdateProject(config: ProgConf, project: DebPackage): Err =
if updateStt == Err.updated:
project.log.logInfo(project.name, "Up to date")
return Err.updated
elif updateStt == Err.checkVersionErr:
elif updateStt == Err.failed:
project.log.logErr(project.name, "Error while checking for new version", stderr)
return Err.updated
else:
......
#[
Description:
Module that control file logger and console logger
Authors: 2020, Nong Hoang Tu <dmknght@parrotsec.org>
Contributors:
Module structure:
- initLogs: Create object of FileLogger and ConsoleLogger with custom format
- initResultLogs: Call init log with result log as destination path
- initFullLogs: Call init log with full log as destination path
- logInfo: Show log info to screen and save it to file. Use color bright cyan for console
- logErr: Show log error to screen and save it to file with stderr bright magenta for console
TODO:
]#
import .. / cores / configs
import logging
# TODO rewrite log functions for better code structure
proc initLogs(fullPath: string): LogHandler =
var
......
......@@ -11,19 +11,17 @@
- gbpChange
- gbpPush
- checkUpdate
TODO:
TODO: Get stderr only
]#
import osproc
import strutils
import .. / cores / configs
# TODO get both output and stderr
proc gbpClone*(gbpPath, gitUrl, packageName, workDir: string, stderr: var string): int =
#[
Use command gbp clone to clone project with all branches
# TODO use git URL from setting instead of hard coded
]#
(stderr, result) = execCmdEx(
gbpPath & " clone " & gitUrl & packageName,
......@@ -104,5 +102,5 @@ proc checkUpdate*(uscanPath, path: string, localVer, serverVer, stderr: var stri
parseUscanOutput(line, localVer, serverVer)
return Err.outdated
else:
return Err.checkVersionErr
return Err.failed
\ No newline at end of file
#[
Description:
Main module of project that parse arguments from CLi
Main module of project that parse arguments from CLI
Authors: 2020, Nong Hoang Tu <dmknght@parrotsec.org>
Contributors:
Module structure:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment