-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Set up the distrubuted commands system
- Loading branch information
Arnaudov, Stanislav Tomov
committed
Jun 16, 2020
1 parent
675cc28
commit 1eb8f7c
Showing
9 changed files
with
200 additions
and
25 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
class CommitCommand: | ||
|
||
name = 'commit' | ||
|
||
def __init__(self): | ||
pass | ||
|
||
def execute(self, arguments, root): | ||
pass | ||
|
||
|
||
ExportedClass = CommitCommand |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import subprocess | ||
|
||
|
||
class GrepCommand: | ||
|
||
name = 'grep' | ||
|
||
def __init__(self): | ||
pass | ||
|
||
def execute(self, args, path): | ||
|
||
ret = subprocess.run(['git', '-C', path, 'grep', *args], stdout=subprocess.PIPE) | ||
return path, ret.returncode, ret.stdout | ||
|
||
|
||
ExportedClass = GrepCommand |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
class PullCommand: | ||
|
||
name = 'pull' | ||
|
||
def __init__(self): | ||
pass | ||
|
||
def execute(self, arguments, root): | ||
pass | ||
|
||
|
||
ExportedClass = PullCommand |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
class PushCommand: | ||
|
||
name = 'push' | ||
|
||
def __init__(self): | ||
pass | ||
|
||
def execute(self, arguments, root): | ||
pass | ||
|
||
|
||
ExportedClass = PushCommand |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
class SedCommand: | ||
|
||
name = 'sed' | ||
|
||
def __init__(self): | ||
pass | ||
|
||
def execute(self, arguments, root): | ||
pass | ||
|
||
|
||
ExportedClass = SedCommand |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import logging | ||
import os | ||
|
||
import code_manager.commands | ||
from code_manager.core.configuration import ConfigurationAware | ||
from code_manager.utils.importing import import_modules_from_folder | ||
from code_manager.utils.logger import debug_cyan | ||
from code_manager.utils.logger import debug_red | ||
|
||
|
||
class CommandContainer(ConfigurationAware): | ||
|
||
def __init__(self): | ||
self.commands = {} | ||
self.commands_dir = os.path.dirname(code_manager.commands.__file__) | ||
|
||
def load_commands(self): | ||
import_modules_from_folder(self.commands_dir, 'code_manager.commands', self._add_command) | ||
|
||
def _add_command(self, command, file): | ||
assert command is not None | ||
assert file is not None | ||
|
||
if not hasattr(command, 'ExportedClass'): | ||
debug_red('No exported command class found in file %s', file) | ||
return | ||
|
||
if command.ExportedClass.name is None: | ||
debug_red('The exported class does not have proper name.') | ||
return | ||
|
||
CommandClass = command.ExportedClass # pylint: disable=C0103 | ||
|
||
if CommandClass.name in self.commands.keys(): | ||
debug_red('Command with the name \'%s\' already exists', CommandClass.name) | ||
|
||
debug_cyan('Loading command: \'%s\'', CommandClass.name) | ||
|
||
self.commands[CommandClass.name] = CommandClass | ||
|
||
def execute_command(self, command, args, pack, root): | ||
|
||
if command not in self.commands.keys(): | ||
return | ||
|
||
command_obj = self.commands[command]() | ||
|
||
command_obj.root = root | ||
command_obj.args = args | ||
command_obj.pack = pack | ||
|
||
logging.debug('Executing command: \'%s\' on package \'%s\'', command, pack) | ||
command_obj.execute(args, root) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters