Entry point for Python scripts
Project description
command_manager
===================
Entry point for Python scripts.
Helps you structure additional scripts of your application within one or more Python packages and call them from one place.
Installation
-------------
Install using `pip`...
pip install command_manager
Using
-------------------
Create a Python package anywhere in your application.
For example, the package `commands` and the entry point `manager.py`
.
├── commands
│ ├── __init__.py
│ └── my_first_command.py
├── src
└── manager.py
In `manage.py` add the following:
if __name__ == '__main__':
import logging.config # Optional for logging
from command_manager import Manager
LOGGING = { # Optional for logging
'version': 1,
'disable_existing_loggers': False,
'formatters': {
'verbose': {
'format': '%(levelname)s | %(asctime)s | %(module)s | %(message)s'
}
},
'handlers': {
'commands_handler': {
'level': 'INFO',
'class': 'logging.handlers.RotatingFileHandler',
'formatter': 'verbose',
'filename': os.path.join("logs", 'commands.log'),
'maxBytes': 100000,
'backupCount': 10,
}
},
'loggers': {
'commands.my_first_command': {
'handlers': ['commands_handler'],
'level': 'INFO',
'propagate': False
}
},
}
logging.config.dictConfig(LOGGING) # Optional for logging
manager = Manager(["commands"])
manager.run()
In `my_first_command.py` add the following:
from command_manager.commands import BaseCommand
class Command(BaseCommand):
description = "Simple command"
def add_arguments(self, parser):
parser.add_argument("--arg1", help="argument arg1")
parser.add_argument("--arg2", help="argument arg2")
def handle(self, *args, **kwargs):
self.logger.info("START")
print "Hello Word: arg1={arg1} arg2={arg2}".format(**kwargs)
self.logger.info("END")
> **Warning:**
> The class must be called the `Command` and inherited from `BaseCommand`
Now call `manage.py` from the console.
![python manage.py](/asserts/manage.png)
Call our command `my_first_command.py`
![python manage.py my_first_command](/asserts/command_call.png)
===================
Entry point for Python scripts.
Helps you structure additional scripts of your application within one or more Python packages and call them from one place.
Installation
-------------
Install using `pip`...
pip install command_manager
Using
-------------------
Create a Python package anywhere in your application.
For example, the package `commands` and the entry point `manager.py`
.
├── commands
│ ├── __init__.py
│ └── my_first_command.py
├── src
└── manager.py
In `manage.py` add the following:
if __name__ == '__main__':
import logging.config # Optional for logging
from command_manager import Manager
LOGGING = { # Optional for logging
'version': 1,
'disable_existing_loggers': False,
'formatters': {
'verbose': {
'format': '%(levelname)s | %(asctime)s | %(module)s | %(message)s'
}
},
'handlers': {
'commands_handler': {
'level': 'INFO',
'class': 'logging.handlers.RotatingFileHandler',
'formatter': 'verbose',
'filename': os.path.join("logs", 'commands.log'),
'maxBytes': 100000,
'backupCount': 10,
}
},
'loggers': {
'commands.my_first_command': {
'handlers': ['commands_handler'],
'level': 'INFO',
'propagate': False
}
},
}
logging.config.dictConfig(LOGGING) # Optional for logging
manager = Manager(["commands"])
manager.run()
In `my_first_command.py` add the following:
from command_manager.commands import BaseCommand
class Command(BaseCommand):
description = "Simple command"
def add_arguments(self, parser):
parser.add_argument("--arg1", help="argument arg1")
parser.add_argument("--arg2", help="argument arg2")
def handle(self, *args, **kwargs):
self.logger.info("START")
print "Hello Word: arg1={arg1} arg2={arg2}".format(**kwargs)
self.logger.info("END")
> **Warning:**
> The class must be called the `Command` and inherited from `BaseCommand`
Now call `manage.py` from the console.
![python manage.py](/asserts/manage.png)
Call our command `my_first_command.py`
![python manage.py my_first_command](/asserts/command_call.png)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
command_manager-1.2.0.tar.gz
(4.5 kB
view details)
File details
Details for the file command_manager-1.2.0.tar.gz
.
File metadata
- Download URL: command_manager-1.2.0.tar.gz
- Upload date:
- Size: 4.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a73df3b5bc81a50269354847bd59f7ba046335e5d30f4d1eabd629a67aa02db3 |
|
MD5 | b00cd5e20a5a22be41537064ca950e59 |
|
BLAKE2b-256 | f981df3eace50a657ccf0e407632dc90ef810eea4a6b62d964819f1ef769bd47 |