<<

pytel Documentation

Tim-Oliver Husser

Mar 07, 2019

Contents:

1 Installing pytel 1 1.1 Recommended environment...... 1 1.2 Docker...... 2

2 Basic Usage 3 2.1 Environment...... 4 2.2 Comm...... 4

3 The Comm module 5

4 Indices and tables 7

i ii CHAPTER 1

Installing pytel

For installing, you first have to clone the pytel repository: git clone [email protected]:thusser/pytel.git pytel

Then you can simply it: pytel python setup.py install

1.1 Recommended environment

For using all features of pytel, it is recommended to use a standardized installation. You first have to create a new user. On Linux systems, this usually works like this (as root): adduser pytel--home/opt/pytel

Note that we’ve set the user’s home directory to /opt/pytel. Change into the new user, and checkout and install pytel: pytel /opt/pytel/src cd/opt/pytel/src git clone [email protected]:thusser/pytel.git pytel

Now create new directories for configuration files, log files and PID files: mkdir/opt/pytel/config mkdir/opt/pytel/log mkdir/opt/pytel/run

1 pytel Documentation

1.2 Docker

Build Docker image: docker build--tag=pytel.

And run it: docker run -v $()/camera.yaml:/pytel.yaml -v $(pwd)/camera.log:/pytel.log pytel

2 Chapter 1. Installing pytel CHAPTER 2

Basic Usage

After installing pytel, you have the new pytel, creates and starts pytel modules from the command line based on a configuration file, written in YAML. A simple configuration file (/opt/pytel/config/standalone.yaml) might look like this:

class: pytel.Application

module: class: pytel.modules..StandAlone message: Hello world interval: 10

Basically you always define a class for a block together with its properties. In this example, an object is created from the class pytel.Application, which usually should always be the -level class in a pytel configuration. Among other parameters, this class accepts a module parameter, in which we can define another object, that defines the logic of the program. The module itself is of pytel.modules.test.StandAlone, which is a trivial implementation of a module that does nothing than logging a given message continuously in a given interval:

class StandAlone(PytelModule): def __init__(self, *args, **kwargs): PytelModule.__init__(self, thread_funcs=self.thread_func, *args, **kwargs)

@classmethod def default_config(cls): cfg= super(StandAlone, cls).default_config() cfg['message']='Hello world' cfg['interval']= 10 return cfg

def open(self)-> bool: return PytelModule.open(self)

(continues on next page)

3 pytel Documentation

(continued from previous page) def close(self): PytelModule.close(self)

def thread_func(self): while not self.closing.is_set(): log.(self.config['message']) self.closing.(self.config['interval'])

The constructor just calls the constructor of pytel.PytelModule, adding the thread_funcs parameter, that takes a method that is run in an extra thread. In this case, it is the method thread_func(), that does some logging in a loop that runs until the program quits. The class method default_config() defines the default configuration for the module, and open() and close() are called when the module is opened and closed, respectively. If the configuration file is saved as standalone.yaml, one can easily start it via the pytel command:

pytel standalone.yaml

The program quits gracefully when it receives an interrupt, so you can stop it by simply pressing Ctrl+c.

2.1 Environment

There is some functionality that is required in many modules, including those concerning the environment, espe- cially the location of the telescope and the local . For this, the pytel.Application class has support for an additional module of type pytel.modules.environment.Environment, which can be defined in the appli- cation’s configuration like this:

environment: class: pytel.modules.environment.Environment timezone: utc location: longitude: 20.810808 latitude:-32.375823 elevation: 1798.

Now an object of this type is automatically pushed into the module and can be accessed via the environment property, e.g.:

def open(self)-> bool: print(self.environment.location) return PytelModule.open(self)

2.2 Comm

In case the module is supposed to communicate with others, we need another module of type pytel.comm.Comm, which can be defined in the application’s configuration like this:

comm: class: pytel.comm.xmpp.XmppComm jid: [email protected]

More details about this can be found in the The Comm module section.

4 Chapter 2. Basic Usage CHAPTER 3

The Comm module

5 pytel Documentation

6 Chapter 3. The Comm module CHAPTER 4

Indices and tables

• genindex • modindex • search

7