-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpatches.py
82 lines (73 loc) · 2.22 KB
/
patches.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/env python
import os
import logging
from invoke import task, Collection, run
from blessings import Terminal
from quilt.push import Push
from quilt.pop import Pop
from quilt.db import PatchSeries
from quilt.error import AllPatchesApplied, QuiltError, UnknownPatch
patches_dir = "patches"
pc_dir = ".pc"
series_file = 'series'
t = Terminal()
logger = logging.getLogger(__name__)
@task()
def applied(ctx, expect_empty=False):
'''Applied patches (quilt)'''
logger.info(t.bold('Patches Applied'))
res = run('quilt applied', warn=True)
patches = res.stdout.split('\n')
for patch in patches:
if expect_empty:
logger.info(t.red(patch))
return False
return True
@task()
def unapplied(ctx):
'''Unapplied patches (quilt)'''
logger.info(t.bold('Patches Not Applied'))
res = run('quilt unapplied', hide='stdout', warn=True)
patches = res.stdout.split('\n')
for patch in patches:
logger.info(t.red(patch))
def _pop(force=False):
pop = Pop(os.getcwd(), pc_dir)
try:
pop.unapply_all(force)
except QuiltError as e:
logger.info(t.red('KO: Error applying patch:' + str(e)))
return -1
except UnknownPatch as e:
logger.info(t.red('KO: Error applying patch:' + str(e)))
return -1
logger.info(t.green('OK: All Patches removed'))
return 0
@task()
def pop(ctx, force=False):
'''Pop patches (quilt)'''
_pop(force)
def _push(force=False, quiet=True):
push = Push(os.getcwd(), pc_dir, patches_dir)
try:
push.apply_all(force, quiet)
except AllPatchesApplied:
logger.info(t.green('OK: Patches already Applied'))
return 0
except QuiltError as e:
logger.info(t.red('KO: Error applying patch:' + str(e)))
return -1
except UnknownPatch as e:
logger.info(t.red('KO: Error applying patch:' + str(e)))
return -1
logger.info(t.green('OK: All Patches Applied'))
return 0
@task()
def push(ctx, force=False, quiet=True):
'''Push patches (quilt)'''
_push(force=False, quiet=True)
QuiltCollection = Collection('quilt')
QuiltCollection.add_task(pop)
QuiltCollection.add_task(applied)
QuiltCollection.add_task(unapplied)
QuiltCollection.add_task(push)