Skip to main content

This module allows to execute python scripts.

Project description

1 Overview

This python module offers a framework which allows to execute given command in a modular fashion.

2 Installation

2.1 Setting Environment Variable

Before executing command you should set environment variable called "APP_RUNNER_ROOT_PATH" to the root directory of your python project.

APP_RUNNER_ROOT_PATH = /path/to/PYTHON_PROJECT_DIRECTORY

2.2 Setting Directory Structure

Now we need to set the directory structure of our python project as shown below.

- PYTHON_PROJECT_DIRECTORY
  + modules
  - resources
    + commands
    + configs

For details about directory structure please refer to Directory Structure

2.3 Main Configuration

Main configuration is a yaml file which contains required configurations for command executor to run. Main configuration file name should be “main.config.yaml”.

- PYTHON_PROJECT_DIRECTORY
  - resources
    - configs
        main.config.yml

Main configuration file should have following content.

application:
  name: Test Application

For details about main configuration please refer to Main Configuration

2.4 Generating Module

2.4.1 Setting Directory Structure

Application expects module complies with following directory structure and files.

- PYTHON_PROJECT_DIRECTORY
  - modules
    - base
      - src
        + executor
      + commands
      base.settings.yaml  

2.4.2 Adding Module Settings

We need to provide information about the module as shown below.

base.settings.yaml

name: base
description: This is a test module.
version: 0.0.1
2.4.2 Adding Command

We can define commands to be executed via a yaml file. System looks for yaml file “<COMMAND_ID>.yaml” in “commands” directory in module’s root directory as shown below.

- PYTHON_PROJECT_DIRECTORY
  - modules
    - base    
      - commands
          cmd1.yaml

Command yaml file should comply with following structure.

id: cmd1
title: Command 1
module: sample
executor: 
    class: TestCmdExecutor
    method: runCommand

2.4.3 Generating Executor

With above configuration command executor framework will search and find TestCmdExector class in sample module. Once executor class is found, its given method "runCommand" will called.

We need to provide TestCmdExecutor class in following directory.

- PYTHON_PROJECT_DIRECTORY
  - modules
    - MODULE_NAME    
      - src
        - executor
            TestCmdExecutor

TestCmdExecutor.py

from cmd_exec.classes.MarkupBuilder import MarkupBuilder
from cmd_exec.command.CmdResponse import CmdResponse
from cmd_exec.command.CmdExecutor import CmdExecutor
from cmd_exec.command.CmdRequest import CmdRequest

class TestCmdExecutor(CmdExecutor):

    def runCommand(self, request: CmdRequest) -> CmdResponse:
        response: CmdResponse = CmdResponse(True, 'view')
        builder: MarkupBuilder = MarkupBuilder()
        builder.addConstraintText("Hello World", 20)
        text = builder.getMarkupText()
        response.setContent(text)
        return response

For details about modules please refer to Modules

2.5 Initializing Command Executor Framework

Now we are all set with setting environment to executing command. Lets generate a python script which will initiate command executor framework to execute a command with following content.

run-command.py

from cmd_exec.app.CmdExecAppRunner import CmdExecAppRunner
CmdExecAppRunner.run()

2.6 Executing Command

We can now execute command via command executor framework by calling python script generated in previous step. Run above python script along with passing argument to identify the command to be executed.

python run-command.py -cmd base.cmd1

For details about other feature please refer to Command Executor User Manual

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cmd-exec-0.0.4.tar.gz (31.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cmd_exec-0.0.4-py3-none-any.whl (47.4 kB view details)

Uploaded Python 3

File details

Details for the file cmd-exec-0.0.4.tar.gz.

File metadata

  • Download URL: cmd-exec-0.0.4.tar.gz
  • Upload date:
  • Size: 31.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.2

File hashes

Hashes for cmd-exec-0.0.4.tar.gz
Algorithm Hash digest
SHA256 66648f7cfbde4cbca1da09edbff8b73e89d22334c13b8b917b072830f5f01dfd
MD5 49dd42f5c3043501e940b070d1a72790
BLAKE2b-256 bb9571840b68f1e50963a1bc71bd987e3916ef568cbecfdd2b4a7f76bc8d268e

See more details on using hashes here.

File details

Details for the file cmd_exec-0.0.4-py3-none-any.whl.

File metadata

  • Download URL: cmd_exec-0.0.4-py3-none-any.whl
  • Upload date:
  • Size: 47.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.2

File hashes

Hashes for cmd_exec-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 12a11289d0052fa6c30d44aa80710ff04a45d9b444fcfca73710ac487b6cbd1f
MD5 dcbf62b7f0df265ea23a0eb833d66fef
BLAKE2b-256 8202325503abc3c50663b513a81f7c8c62f00d5df7354c1013296de5d3b1b35e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page