-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* wip * working * extra zip * fix * tests working --------- Co-authored-by: Sean Shookman <seanshookman@Seans-MacBook-Pro.local> Co-authored-by: root <root@ip-172-28-197-111.cars.com>
- Loading branch information
1 parent
1020d8f
commit 9532b09
Showing
6 changed files
with
136 additions
and
2 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
2.0.1 | ||
2.1.0 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
"""Package Component""" | ||
|
||
from subprocess import call | ||
from schema import Schema, And, Optional | ||
from ..objects.component import Activation, Component | ||
|
||
HELP_TEMPLATE = "Package the codebase into a single zip file ({path})" | ||
COMMAND_TEMPLATE = "zip -r {path} .{ignores}" | ||
|
||
class Package(Component): | ||
""" | ||
Package Class | ||
Provides the ability to package the codebase into a zip file artifact for easy distribution | ||
""" | ||
|
||
activation = Activation.PROJECT | ||
commands = ["package"] | ||
|
||
schema = Schema({ | ||
'path': And(str, error='Package \'path\' must be a String'), | ||
Optional('ignores'): And(list, error='Package \'ignores\' must be a List') | ||
}, ignore_extra_keys=True) | ||
|
||
path = None | ||
ignores = None | ||
|
||
def __init__(self, path=None, ignores=None): | ||
"""Initialize the class with simple default values for path and ignores""" | ||
|
||
self.path = path | ||
self.ignores = ignores | ||
|
||
def addParsers(self, subparsers): | ||
""" | ||
SkeleParser Hook | ||
Adds a parser for the package command that zips up the codebase | ||
""" | ||
|
||
helpMessage = HELP_TEMPLATE.format(path=self.path) | ||
subparsers.add_parser("package", help=helpMessage) | ||
return subparsers | ||
|
||
def execute(self, config, args, host=None): | ||
""" | ||
Execution Hook | ||
Executed when the package command is provided it zips the codebase into a single file | ||
while ingoring a list of folders and files in the process | ||
""" | ||
|
||
ignores = f" -x {' '.join(self.ignores)}" if (self.ignores is not None) else "" | ||
command = COMMAND_TEMPLATE.format(path=self.path, ignores=ignores) | ||
return call(command, shell=True) |
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,70 @@ | ||
import copy | ||
import argparse | ||
import unittest | ||
from unittest import mock | ||
|
||
from schema import SchemaError | ||
|
||
import skelebot as sb | ||
|
||
class TestPlugin(unittest.TestCase): | ||
|
||
package_yaml = { | ||
"path": "test.zip", | ||
"ignores": ["one.txt", "two.txt"] | ||
} | ||
|
||
def test_addParsers(self): | ||
package = sb.components.package.Package() | ||
|
||
parser = argparse.ArgumentParser(formatter_class=argparse.RawTextHelpFormatter) | ||
subparsers = parser.add_subparsers(dest="job") | ||
subparsers = package.addParsers(subparsers) | ||
|
||
self.assertNotEqual(subparsers.choices["package"], None) | ||
|
||
@mock.patch('skelebot.components.package.call') | ||
def test_execute(self, mock_call): | ||
mock_call.return_value = 0 | ||
|
||
config = sb.objects.config.Config() | ||
args = argparse.Namespace() | ||
|
||
package = sb.components.package.Package(path="test.zip") | ||
package.execute(config, args) | ||
|
||
mock_call.assert_called_once_with("zip -r test.zip .", shell=True) | ||
|
||
@mock.patch('skelebot.components.package.call') | ||
def test_execute_ignores(self, mock_call): | ||
mock_call.return_value = 0 | ||
|
||
config = sb.objects.config.Config() | ||
args = argparse.Namespace() | ||
|
||
package = sb.components.package.Package(path="test.zip", ignores=["folder/**\*", "file.txt"]) | ||
package.execute(config, args) | ||
|
||
mock_call.assert_called_once_with("zip -r test.zip . -x folder/**\* file.txt", shell=True) | ||
|
||
def test_validate_valid(self): | ||
try: | ||
sb.components.package.Package.validate(self.package_yaml) | ||
except: | ||
self.fail("Validation Raised Exception Unexpectedly") | ||
|
||
def validate_error(self, attr, reset, expected): | ||
package_yaml = copy.deepcopy(self.package_yaml) | ||
package_yaml[attr] = reset | ||
|
||
try: | ||
sb.components.package.Package.validate(package_yaml) | ||
except SchemaError as error: | ||
self.assertEqual(error.code, "Package '{attr}' must be a{expected}".format(attr=attr, expected=expected)) | ||
|
||
def test_invalid(self): | ||
self.validate_error('path', 123, ' String') | ||
self.validate_error('ignores', 123, ' List') | ||
|
||
if __name__ == '__main__': | ||
unittest.main() |
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