Skip to content
This repository was archived by the owner on Mar 13, 2024. It is now read-only.

Commit 81025c9

Browse files
committed
Adds dist-upgrade option
1 parent 7e4e081 commit 81025c9

File tree

3 files changed

+17
-10
lines changed

3 files changed

+17
-10
lines changed

updatewrapper/__init__.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from updatewrapper.flavor import get_flavor_wrapper
99

1010

11-
def wrap(hosts, out_dir):
11+
def wrap(hosts, out_dir, dist_upgrade):
1212
print_banner()
1313

1414
logfiles = []
@@ -21,7 +21,7 @@ def wrap(hosts, out_dir):
2121
print()
2222
for host in hosts:
2323
try:
24-
wrapper = get_flavor_wrapper(host)
24+
wrapper = get_flavor_wrapper(host, dist_upgrade)
2525

2626
print_info('BEGIN host %s' % host.addr)
2727
host.ask_passwords()
@@ -61,17 +61,19 @@ def wrap(hosts, out_dir):
6161

6262

6363
def main():
64-
# TODO: Add --dist-upgrade option
65-
opts, args = getopt.getopt(sys.argv[1:], 'c:h:o', ['config=', 'host=', 'out-dir='])
64+
opts, args = getopt.getopt(sys.argv[1:], 'c:h:o', ['config=', 'dist-upgrade', 'host=', 'out-dir='])
6665

6766
config_file = get_config_file()
6867
hosts = []
6968
host = None
7069
out_dir = os.getcwd()
70+
dist_upgrade = False
7171

7272
for opt in opts:
7373
if opt[0] in ('-c', '--config'):
7474
config_file = opt[1]
75+
elif opt[0] == '--dist-upgrade':
76+
dist_upgrade = True
7577
elif opt[0] in ('-h', '--host'):
7678
addr = opt[1]
7779
host = Host(addr=addr) # TODO: Should allow to input other parameters or search from config
@@ -83,7 +85,7 @@ def main():
8385
else:
8486
hosts = get_hosts(config_file)
8587

86-
wrap(hosts, out_dir)
88+
wrap(hosts, out_dir, dist_upgrade)
8789

8890

8991
if __name__ == "__main__":

updatewrapper/flavor/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,21 @@
22
import importlib
33

44

5-
def get_flavor_wrapper(host):
5+
def get_flavor_wrapper(host, dist_upgrade):
66
flavor = host.flavor if host.flavor in ['debian', 'redhat'] else None
77

88
if flavor is None:
99
raise ValueError('Invalid flavor')
1010

1111
Wrapper = getattr(importlib.import_module('updatewrapper.flavor.' + flavor), flavor.capitalize())
1212

13-
return Wrapper(host)
13+
return Wrapper(host, dist_upgrade=dist_upgrade)
1414

1515

1616
class FlavorBase:
1717
__metaclass__ = abc.ABCMeta
1818

19-
def __init__(self, host):
19+
def __init__(self, host, **kwargs):
2020
self.host = host
2121

2222
@abc.abstractmethod

updatewrapper/flavor/debian.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,19 @@
44

55

66
class Debian(FlavorBase):
7+
def __init__(self, host, dist_upgrade=False, **kwargs):
8+
self.command = 'dist-upgrade' if dist_upgrade else 'upgrade'
9+
10+
super().__init__(host)
11+
712
def update_cache(self):
813
return self.host.run('DEBIAN_FRONTEND=noninteractive apt-get update')
914

1015
def check_update(self):
11-
return self.host.run('DEBIAN_FRONTEND=noninteractive apt-get --show-upgraded --assume-no upgrade')
16+
return self.host.run('DEBIAN_FRONTEND=noninteractive apt-get --show-upgraded --assume-no ' + self.command)
1217

1318
def has_update(self, returncode, stdout, stderr):
1419
return to_bytes('The following packages will be upgraded') in stdout
1520

1621
def perform_update(self):
17-
return self.host.run('DEBIAN_FRONTEND=noninteractive apt-get --show-upgraded --assume-yes upgrade')
22+
return self.host.run('DEBIAN_FRONTEND=noninteractive apt-get --show-upgraded --assume-yes ' + self.command)

0 commit comments

Comments
 (0)