Skip to content

Python3 command SDK for the Cog ChatOps platform

License

Notifications You must be signed in to change notification settings

pan-net-security/pycog3

This branch is 13 commits ahead of, 1 commit behind operable/pycog3:master.

Folders and files

NameName
Last commit message
Last commit date

Latest commit

bb6e8c8 · Nov 12, 2017

History

20 Commits
Nov 12, 2017
Nov 9, 2017
Nov 12, 2017
Nov 12, 2017
Nov 12, 2017
Jun 9, 2016
Jun 9, 2016
Jun 9, 2016
Jun 9, 2016
Nov 12, 2017
Jun 9, 2016
Nov 9, 2017

Repository files navigation

Build Status

pycog3

Simple, opinionated library for building Cog commands in Python3.

Usage

pycog3 combines information available in the Cog runtime environment with assumptions about Python project structure to simplify command development.

pycog3 includes a driver executable, bin/cog-command, which dynamically imports, instantiates, and runs Python command code based on the values of $COG_BUNDLE and $COG_COMMAND.

cog-command's magic requires that Python projects follow a strict directory layout (basic):

<bundle_name>
  |
  |-- <bundle_name>
       |-- __init__.py
       |-- commands
           |
           |-- __init__.py
           |-- <command1>.py
           |-- <command2>.py

pycog3 also supports more advanced, multi-level structure when using the - field separator in the command name. For example, defining:

  • commands\commanda.py - maps to !commanda
  • commands\level1\commandb.py - maps to !level1-commandb
  • commands\level1\level2a\commandc.py - maps to !level1-level2a-commandb
  • commands\level1\level2b\leveln\commandz.py - maps to !level1-level2b-leveln-commandz
<bundle_directory>
  |
  |-- <bundle_name>
       |-- __init__.py
       |-- commands
           |
           |-- __init__.py
           |-- <commanda>.py
           |-- <commandb>.py
           .
           .
           |-- <commandz>.py
           |
           |-- <level1>
                |
                |-- __init__.py
                |-- <commanda>.py
                |-- <commandb>.py
                .
                .
                |-- <commandz>.py
                |
                |-- <level2a>
                |    |
                |    |-- <commanda>.py
                |    |-- <commandb>.py
                |    |-- <commandc>.py
                |    .
                |    .
                |    |-- <commandz>.py
                |
                |-- <level2b>
                     |
                     |-- __init__.py
                     |-- <...>
                         |
                         |-- __init__.py
                         | -- <leveln>
                              |
                              |-- __init__.py
                              |-- <commanda>.py
                              |-- <commandb>.py
                              .
                              .
                              |-- <commandz>.py

The only requirement is a class with the same name of the filename should exist (first letter capital).

Examples

See the cog-bundles/statuspage repository for an example of this library in action.

If you're interested in the multi-level usage, check the cog-bundle pi-bundle or the test bundle in test/.

Installation

Add this line to your application's setup.py or requirements.txt:

pycog3>=0.1.28

TODO

About

Python3 command SDK for the Cog ChatOps platform

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python 100.0%