Skip to content

Commit

Permalink
Added high-level methods to execute the channel enabling and disablin…
Browse files Browse the repository at this point in the history
…g actions.

Use the quick-and-dirty manager.py script to test them:

 ./manager.py enable semplice-devel

 ./manager.py enable semplice-jessie

 ./manager.py disable jessie

 ./manager.py enable semplice-current

Signed-off-by: Eugenio Paolantonio (g7) <[email protected]>
  • Loading branch information
g7 committed Apr 25, 2015
1 parent 47a8292 commit 4840ffd
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 1 deletion.
25 changes: 24 additions & 1 deletion libchannels/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,27 @@ def enable_channel(self, channel):
Enables the given channel.
"""

pass
if self.discovery.cache[channel].enabled:
# Nothing to do
return

for child_channel, action in self.resolver.get_channel_solution(channel, ActionType.ENABLE):
if action == ActionType.ENABLE:
self.discovery.cache[child_channel].enable()
elif action == ActionType.DISABLE:
self.discovery.cache[child_channel].disable()

def disable_channel(self, channel):
"""
Disables the given channel.
"""

if not self.discovery.cache[channel].enabled:
# Nothing to do
return

for child_channel, action in self.resolver.get_channel_solution(channel, ActionType.DISABLE):
if action == ActionType.ENABLE:
self.discovery.cache[child_channel].enable()
elif action == ActionType.DISABLE:
self.discovery.cache[child_channel].disable()
4 changes: 4 additions & 0 deletions libchannels/channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ def disable(self):
Disables enitrely the channel.
"""

print("Disabling %s channel..." % self.channel_name)

for repository, source_entry in self.repositories.items():
source_entry.set_enabled(False)

Expand All @@ -91,6 +93,8 @@ def enable(self):
Enables the channel.
"""

print("Enabling %s channel..." % self.channel_name)

for repository, source_entry in self.repositories.items():
if type(source_entry) == SourceEntry:
source_entry.set_enabled(True)
Expand Down
31 changes: 31 additions & 0 deletions manager.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/python3
# -*- coding: utf-8 -*-

import libchannels.discovery
import libchannels.resolver
import libchannels.actions

import sys

if len(sys.argv) < 3:
print("You should specify the action and the channel to execute the action on!")
sys.exit(1)

action = libchannels.actions.ActionType.DISABLE if sys.argv[1] == "disable" else libchannels.actions.ActionType.ENABLE
channel = sys.argv[2]

# Discovery
discovery = libchannels.discovery.ChannelDiscovery()
discovery.discover()

# Resolver
resolver = libchannels.resolver.DependencyResolver(discovery.cache)

# Actions
actions = libchannels.actions.Actions(discovery, resolver)

#print(action)
if action == libchannels.actions.ActionType.DISABLE:
actions.disable_channel(channel)
else:
actions.enable_channel(channel)

0 comments on commit 4840ffd

Please sign in to comment.