cmdutils.nim 3.22 KB
Newer Older
1
#[
Nong Hoang Tu's avatar
Nong Hoang Tu committed
2
3
4
5
6
7
8
9
10
11
12
13
14
  Description:
    Wrapper of gbp (git-buildpackage) and uscan
  Authors: 2020, Nong Hoang Tu <dmknght@parrotsec.org>
  Contributors:
  Module structure:
    - gbpClone: Use command gbp clone to clone project with all branches
    - gbpPull: 
    - gbpUpdate
    - gbpTag
    - gbpChange
    - gbpPush
    - checkUpdate
  TODO:
15
16
17
18
19
]#

import osproc
import strutils
import parser
Nong Hoang Tu's avatar
Nong Hoang Tu committed
20
import .. / cores / configs
21

22
# TODO get both output and stderr
23

Nong Hoang Tu's avatar
Nong Hoang Tu committed
24
proc gbpClone*(gbpPath, gitUrl, packageName, workDir: string, stderr: var string): int =
25
26
27
28
  #[
    Use command gbp clone to clone project with all branches
    # TODO use git URL from setting instead of hard coded
  ]#
Nong Hoang Tu's avatar
Nong Hoang Tu committed
29
30
31
32
  (stderr, result) = execCmdEx(
    gbpPath & " clone " & gitUrl & packageName,
    workingDir = workDir
  )
33
34


35
proc gbpPull*(gpbPath, workDir: string, stderr: var string): int =
36
37
38
39
  #[
    Run gbp pull to sync any changes to avoid conflict
    It must be run before doing anything on project
  ]#
Nong Hoang Tu's avatar
Nong Hoang Tu committed
40
  (stderr, result) = execCmdEx(gpbPath & " pull", workingDir = workDir)
41
42


Nong Hoang Tu's avatar
Nong Hoang Tu committed
43
proc gbpUpdate*(gbpPath, workDir: string, stderr: var string): int =
44
45
46
  #[
    Update debian project with gbp + uscan
  ]#
47
  (stderr, result) = execCmdEx(
Nong Hoang Tu's avatar
Nong Hoang Tu committed
48
49
    gbpPath & " import-orig --no-interactive --pristine-tar --uscan",
    workingDir = workDir
50
  )
51
52


Nong Hoang Tu's avatar
Nong Hoang Tu committed
53
proc gbpTag*(gbpPath, workDir: string, stderr: var string): int =
54
55
56
57
  #[
    Generate git tags for version change
    Solved gbp:error: revision 'debian/1.3.0-parrot0^{commit}' not found
  ]#
Nong Hoang Tu's avatar
Nong Hoang Tu committed
58
59
60
61
  (stderr, result) = execCmdEx(
    gbpPath & " tag",
    workingDir = workDir
  )
62
63


64
proc gbpDch*(gbpPath, workDir, version: string, stderr: var string): int =
65
66
67
68
69
70
71
72
  #[
    Generate new Debian version using gbp dch
    Distro name will be forced as rolling-testing (flag: --distribution=rolling-testing)
    Add flag --force-distribution to avoid stdin requires everytime it runs
    Add flag -c to auto commit change of debian/changelog
    Add flag -N <version> to solve the problem gbp:error: revision 'debian/1.3.0-parrot0^{commit}' not found
      The version name should be added -parrot0 by default. The -parrot0 is hardcoded text as a new upstream release
  ]#
Nong Hoang Tu's avatar
Nong Hoang Tu committed
73
74
75
76
  (stderr, result) = execCmdEx(
    gbpPath & " dch --distribution=rolling-testing --force-distribution -c -N " & version & "-parrot0",
    workingDir = workDir
  )
77
78


Nong Hoang Tu's avatar
Nong Hoang Tu committed
79
proc gbpPush*(gbpPath, workDir: string, stderr: var string): int =
80
81
82
83
  #[
    Push all changes with branches to nest
    PROBLEM: on update server, maintainer have to type ssh password multiple times
  ]#
Nong Hoang Tu's avatar
Nong Hoang Tu committed
84
85
86
87
  (stderr, result) = execCmdEx(
    gbpPath & " push --pristine-tar",
    workingDir = workDir
  )
88
89


90
proc checkUpdate*(uscanPath, path: string, localVer, serverVer, stderr: var string): Err =
91
92
  #[
    Use uscan --no-download to check new version
93
94
95
    Uscan exit code (Check man-page of uscan, part EXIT STATUS):
      0 (with output) -> has new update
      1 (empty output) -> updated
96
97
  ]#
  let
98
99
100
101
102
    command = uscanPath & " --no-download"
    (output, exitCode) = execCmdEx(command, workingDir = path)
  if exitCode == 1:
    return Err.updated
  elif exitCode == 0:
103
104
105
106
    for line in output.split("\n"):
      if line.startsWith("uscan:") and "Newest version" in line:
        parseUscanOutput(line, localVer, serverVer)
        return Err.outdated
107
  else:
108
    return Err.checkVersionErr
109