There is a file with a "configuration" from which variables are taken.
File - __main__.py
import sys import getopt import os import picamera from raspm import raspm camera = None camlock = Lock() USAGE = ''' Usage %s [OPTIONS] COMMAND COMMANDS: run -- Start RPM as Raspberry Pi Manager (default) http-server -- Start only http server CONFIGURATION: - Configuration specified on the command line - /etc/rpm.conf - ./etc/rpm.conf ''' def usage(retval = 0): print(USAGE % sys.argv[0]) sys.exit(retval) if __name__ == "__main__": cfg = '/etc/rpm.conf' if os.path.isfile('/etc/rpm.conf') else './etc/rpm.conf' try: app.run(host='0.0.0.0', port='8080') opts, args = getopt.getopt(sys.argv[1:], 'hc:' ['help', 'config=']) finally: #After work is finished shut off the camera with camlock: if camera: camera.close()
File - raspm.py
.... def update_configuration(cfgfile): from configobj import ConfigObj from raspm.config import cfgspec from validate import Validator cfg = ConfigObj(cfgfile, configspec=cfgspec) validator = Validator() cfg.validate(validator) globals()['CONFIG'] = cfg return cfg # Set up configuration CONFIG = update_configuration('/etc/rpm.conf') ...
Further config file config.py
# -*- coding: utf-8 -*- ''' Default configuration. ''' __CFG = ''' ...... ''' cfgspec = __CFG.split('\n')
And the last rpm.conf
When starting __main__.py I get the following:
Traceback (most recent call last): File "__main__.py", line 19, in <module> from raspm import raspm File "/home/pi/python-RPi-camera-controll/raspm/raspm.py", line 73, in <module> CONFIG = update_configuration('./etc/rpm.conf') File "/home/pi/python-RPi-camera-controll/raspm/raspm.py", line 64, in update_configuration from rpm.config import cfgspec ImportError: No module named rpm.config
files in folders:
python/ - etc/ - - rpm.conf - raspm/ - - __main__.py - - config.py - - raspm.py
I do not understand the problem