Copy files to another directory.

This module can be used to copy template and graph results to another directory on your computer. This could be useful if you are running a web server on the same machine as pywws (or on a machine that’s accessible as a network share).

  • Example weather.ini configuration:

    directory = /home/www/public_html/weather/data/
    plot = ['24hrs.png.xml', 'rose_12hrs.png.xml']
    text = ['24hrs.txt']
    services = [('copy', '24hrs.txt', '24hrs.png', 'rose_12hrs.png')]

Run pywws.service.copy once to set the default configuration, which you can then change. directory is the full path of a directory in which all the copied files will be put.

You can copy any files you like, as often as you like, but typical usage is to update a website once an hour. Each file to be uploaded needs to be listed in a service entry like ('copy', 'filename'). If the file is not in your work directory’s output directory then filename should be the full path.

If you need to copy some files to a different directory you can copy the pywws.service.copy module to your modules directory, making sure that you rename it, for example to This creates a copy2 service that you can use in the same way, but with a different directory.


ToService(context[, check_params])
class pywws.service.copy.ToService(context, check_params=True)[source]

Bases: pywws.service.FileService

config = {'directory': ('', True, None)}
logger = <Logger pywws.service.copy (WARNING)>
service_name = 'copy'

Context manager factory function for a batch of one or more uploads.

This makes it easy to ensure any resources such as an internet connection are properly closed after a batch of uploads. Use the contextlib.contextmanager() decorator when you implement this method.

For a typical example, see the source code of the pywws.service.openweathermap module. If your upload can’t benefit from a session object yield None, as in pywws.service.copy.

upload_file(session, path)[source]

Comments or questions? Please subscribe to the pywws mailing list and let us know.