-
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.
Merge pull request #3 from Lunik/develop
Release 0.2.0
- Loading branch information
Showing
16 changed files
with
522 additions
and
147 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
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,67 +1,39 @@ | ||
''' | ||
Root module for laflem | ||
Main module for laflem | ||
''' | ||
|
||
import sys | ||
import argparse | ||
|
||
from laflem.exceptions import CollectionNotFound | ||
from laflem.log import error_console | ||
|
||
from .collections.base import BaseCollection | ||
from .collections.git import GitCollection | ||
|
||
__version__ = '0.1.2' | ||
from .flem import Flem | ||
from .exceptions import FlemException | ||
from .log import error_console | ||
|
||
class FlemParser(argparse.ArgumentParser): | ||
''' | ||
Custom python parser for laflem. | ||
''' | ||
def error(self, message): | ||
''' | ||
Print an error message and exit. | ||
''' | ||
error_console.print(f"error: {message}\n", style="bold red") | ||
self.print_help() | ||
sys.exit(2) | ||
__version__ = '0.2.0' | ||
|
||
class Flem: | ||
def main(): | ||
''' | ||
Root class for laflem. | ||
Main function for laflem. | ||
''' | ||
collections = { | ||
'base': BaseCollection, | ||
'git': GitCollection, | ||
} | ||
|
||
def get_collection(self, name): | ||
''' | ||
Return an instance of the requested collection if it exists. | ||
Else raise a CollectionNotFound exception. | ||
''' | ||
if name in self.collections: | ||
return self.collections[name]() | ||
|
||
raise CollectionNotFound(name) | ||
|
||
@property | ||
def parser(self): | ||
''' | ||
Construct the parser for laflem. | ||
Returns an instance of FlemParser. | ||
''' | ||
parser = FlemParser(description='Process some integers.') | ||
|
||
subparsers = parser.add_subparsers(help='collection', dest='collection') | ||
subparsers.required = True | ||
for collection in self.collections.values(): | ||
collection_parser = subparsers.add_parser(collection.name, help=collection.description) | ||
collection.build_parser(collection_parser) | ||
|
||
collection_subparsers = collection_parser.add_subparsers(help='module', dest='module') | ||
collection_subparsers.required = True | ||
for module in collection.modules.values(): | ||
module_parser = collection_subparsers.add_parser(module.name, help=module.description) | ||
module.build_parser(module_parser) | ||
|
||
return parser | ||
flem = Flem( | ||
version=__version__ | ||
) | ||
args = flem.parser.parse_args() | ||
|
||
try: | ||
if args.collection: | ||
collection = flem.get_collection(args.collection) | ||
if args.module: | ||
module = collection.get_module(args.module) | ||
|
||
module.run(**args.__dict__) | ||
sys.exit(0) | ||
|
||
except Exception as error: # pylint: disable=broad-except | ||
if isinstance(error, FlemException): | ||
error_console.print(error, style="bold red") | ||
else: | ||
error_console.print_exception() | ||
|
||
sys.exit(1) | ||
|
||
if __name__ == '__main__': | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
''' | ||
Git module constants | ||
''' | ||
|
||
GIT_DEFAULT_CONFIG_PARAMS = [ | ||
('user', 'name', 'str', None), | ||
('user', 'email', 'str', None), | ||
('core', 'editor', 'str', 'vim'), | ||
('core', 'pager', 'str', 'less'), | ||
('core', 'autocrlf', 'str', 'input'), | ||
('init', 'defaultBranch', 'str', 'master'), | ||
('fetch', 'prune', 'bool', True), | ||
('pull', 'rebase', 'bool', True), | ||
('merge', 'ff', 'bool', True), | ||
('push', 'autoSetupRemote', 'bool', True), | ||
('push', 'rebase', 'str', 'preserve'), | ||
] | ||
|
||
GIT_GPP_CONFIG_PARAMS = [ | ||
('user', 'signingkey', 'str', None), | ||
('commit', 'gpgsign', 'bool', True), | ||
('tag', 'gpgsign', 'bool', True), | ||
('push', 'gpgsign', 'bool', False), | ||
('log', 'showSignature', 'bool', False), | ||
('gpg', 'program', 'str', 'gpg2'), | ||
] | ||
|
||
GIT_ALIASES_PARAMS = [ | ||
('alias', 'co', 'str', "commit --signoff"), | ||
('alias', 'lo', 'str', 'log'), | ||
('alias', 'st', 'str', 'status'), | ||
('alias', 'ph', 'str', 'push'), | ||
('alias', 'pl', 'str', 'pull'), | ||
('alias', 'a', 'str', 'add'), | ||
('alias', 'df', 'str', 'diff'), | ||
('alias', 'ck', 'str', 'checkout'), | ||
('alias', 'mr', 'str', "merge --signoff"), | ||
('alias', 'cp', 'str', "cherry-pick --signoff"), | ||
('alias', 'br', 'str', 'branch'), | ||
('alias', 'sh', 'str', 'stash'), | ||
('alias', 'plh', 'str', '!git pull --rebase && git push'), | ||
('alias', 'dp', 'str', '!git add . && git commit --signoff -m \'Dev\' && git push'), | ||
('alias', 'plr', 'str', '!git pull --rebase origin master'), | ||
('alias', 'rh', 'str', '!git reset --hard'), | ||
('alias', 't', 'str', 'tag'), | ||
] |
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,24 @@ | ||
''' | ||
Define the MacOS collection for Mac computers. | ||
''' | ||
from laflem.collections.base import BaseCollection | ||
|
||
from .homebrew import HomebrewSetupModule, HomebrewUpgradeModule, HomebrewCleanupModule | ||
|
||
class MacOSCollection(BaseCollection): | ||
''' | ||
The macos collection. | ||
''' | ||
name = "mac" | ||
description = "The MacOS collection." | ||
modules = { | ||
"homebrew-setup": HomebrewSetupModule, | ||
"homebrew-upgrade": HomebrewUpgradeModule, | ||
"homebrew-cleanup": HomebrewCleanupModule, | ||
} | ||
|
||
@classmethod | ||
def build_parser(cls, parser): | ||
''' | ||
Add arguments to the parser or options. | ||
''' |
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,6 @@ | ||
''' | ||
Import all modules in this package. | ||
''' | ||
from .setup import HomebrewSetupModule | ||
from .upgrade import HomebrewUpgradeModule | ||
from .cleanup import HomebrewCleanupModule |
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,42 @@ | ||
''' | ||
Define the Homebrew cleanup module. | ||
This module is used to cleanup Homebrew. | ||
''' | ||
import os | ||
import subprocess | ||
from rich.prompt import Confirm | ||
|
||
from laflem.log import console | ||
from laflem.collections.base.helloworld import HelloWorldModule | ||
from laflem.exceptions.modules import ModuleNotRunnable | ||
|
||
from .const import HOMEBREW_BIN_PATH | ||
|
||
class HomebrewCleanupModule(HelloWorldModule): | ||
''' | ||
The Homebrew cleanup module. | ||
''' | ||
name = "homebrew-cleanup" | ||
description = "Cleanup Homebrew." | ||
version = "0.1.0" | ||
|
||
def _check_installed(self): | ||
''' | ||
Check if Homebrew is installed. | ||
''' | ||
return os.path.exists(HOMEBREW_BIN_PATH) | ||
|
||
def _main(self, *_args, **_kwargs): | ||
''' | ||
Core the module. | ||
''' | ||
if not self._check_installed(): | ||
raise ModuleNotRunnable("Homebrew is not installed.") | ||
|
||
if Confirm.ask("Do you want to remove unused [bold blue]Homebrew[/] packages ?"): | ||
console.print("Removing unused [bold blue]Homebrew[/] packages...") | ||
subprocess.check_call([HOMEBREW_BIN_PATH, "autoremove"]) | ||
|
||
if Confirm.ask("Do you want to do a full cleanup of [bold blue]Homebrew[/] ?"): | ||
console.print("Doing a full cleanup of [bold blue]Homebrew[/]...") | ||
subprocess.check_call([HOMEBREW_BIN_PATH, "cleanup", "--prune=all"]) |
Oops, something went wrong.