-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add pywws.service.copy and remove pywws.towebsite
This completes making the file copying/uploading simpler and more flexible. Signed-off-by: Jim Easterbrook <jim@jim-easterbrook.me.uk>
- Loading branch information
1 parent
1e2219e
commit 5c989ad
Showing
7 changed files
with
114 additions
and
365 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
__version__ = '18.8.0' | ||
_release = '1582' | ||
_commit = 'bf291f6' | ||
_release = '1583' | ||
_commit = '1e2219e' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
# pywws - Python software for USB Wireless Weather Stations | ||
# http://github.com/jim-easterbrook/pywws | ||
# Copyright (C) 2008-18 pywws contributors | ||
|
||
# This program is free software; you can redistribute it and/or | ||
# modify it under the terms of the GNU General Public License | ||
# as published by the Free Software Foundation; either version 2 | ||
# of the License, or (at your option) any later version. | ||
|
||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
|
||
# You should have received a copy of the GNU General Public License | ||
# along with this program; if not, write to the Free Software | ||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
|
||
"""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:: | ||
[copy] | ||
directory = public_html/weather/data/ | ||
[hourly] | ||
plot = [('24hrs.png.xml', 'L'), ('rose_12hrs.png.xml', 'L')] | ||
text = [('24hrs.txt', 'L')] | ||
services = [('copy', '24hrs.txt'), ('copy', '24hrs.png'), | ||
('copy', 'rose_12hrs.png')] | ||
Run :py:mod:`pywws.service.copy` once to set the default configuration, | ||
which you can then change. ``directory`` is the name 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 copied needs a | ||
service entry like ``('copy', 'filename')``. If the file is not in your | ||
``local files`` directory then ``filename`` should be the full path. | ||
""" | ||
|
||
from __future__ import absolute_import | ||
|
||
from contextlib import contextmanager | ||
from datetime import timedelta | ||
import logging | ||
import os | ||
import shutil | ||
import sys | ||
|
||
import pywws.service | ||
|
||
__docformat__ = "restructuredtext en" | ||
service_name = os.path.splitext(os.path.basename(__file__))[0] | ||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class ToService(pywws.service.FileService): | ||
logger = logger | ||
service_name = service_name | ||
|
||
def __init__(self, context): | ||
# base class init | ||
super(ToService, self).__init__(context) | ||
# get config | ||
self.directory = context.params.get(service_name, 'directory', '') | ||
if not self.directory: | ||
raise RuntimeError('No directory specified in weather.ini') | ||
|
||
@contextmanager | ||
def session(self): | ||
yield None | ||
|
||
def upload_file(self, session, path): | ||
try: | ||
if not os.path.isdir(self.directory): | ||
os.makedirs(self.directory) | ||
shutil.copy(path, self.directory) | ||
except Exception as ex: | ||
return False, str(ex) | ||
return True, 'OK' | ||
|
||
|
||
if __name__ == "__main__": | ||
sys.exit(pywws.service.main(ToService)) |
Oops, something went wrong.