Skip to content

Commit

Permalink
Auto edit weather.ini to use new service modules
Browse files Browse the repository at this point in the history
Signed-off-by: Jim Easterbrook <jim@jim-easterbrook.me.uk>
  • Loading branch information
jim-easterbrook committed Aug 23, 2018
1 parent 5c989ad commit 32c86b8
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 47 deletions.
4 changes: 2 additions & 2 deletions src/pywws/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
__version__ = '18.8.0'
_release = '1583'
_commit = '1e2219e'
_release = '1584'
_commit = '5c989ad'
79 changes: 34 additions & 45 deletions src/pywws/regulartasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,28 +86,7 @@ def __init__(self, context):
last_update += timezone.utcoffset(last_update)
while self.cron[section].get_current(datetime) <= last_update:
self.cron[section].get_next()
# convert old Twitter flags
for section in list(self.cron.keys()) + [
'live', 'logged', 'hourly', '12 hourly', 'daily']:
templates = eval(self.params.get(section, 'text', '[]'))
services = eval(self.params.get(section, 'services', '[]'))
changed = False
for n, template in enumerate(templates):
if not isinstance(template, (list, tuple)):
continue
template, flags = template
if 'T' not in flags:
continue
templates[n] = (template, 'L')
task = ('twitter', template)
if task not in services:
services.append(task)
changed = True
if changed:
logger.error('updating Twitter in [%s]', section)
self.params.set(section, 'text', repr(templates))
self.params.set(section, 'services', repr(services))
# convert to use pywws.service.{copy,ftp,sftp}
# convert to use pywws.service.{copy,ftp,sftp,twitter}
if self.params.get('ftp', 'local site') == 'True':
self.params.set(
'copy', 'directory', self.params.get('ftp', 'directory', ''))
Expand All @@ -117,33 +96,43 @@ def __init__(self, context):
'password', 'privkey'):
self.params.set('sftp', key, self.params.get('ftp', key, ''))
mod = 'sftp'
elif self.params.get('ftp', 'secure') == 'False':
mod = 'ftp'
else:
mod = None
mod = 'ftp'
for key in ('local site', 'secure', 'privkey'):
self.params.unset('ftp', key)
if mod:
for section in list(self.cron.keys()) + [
'live', 'logged', 'hourly', '12 hourly', 'daily']:
for t_p in ('text', 'plot'):
templates = eval(self.params.get(section, t_p, '[]'))
services = eval(self.params.get(section, 'services', '[]'))
changed = False
for n, template in enumerate(templates):
if isinstance(template, (list, tuple)):
continue
templates[n] = (template, 'L')
if t_p == 'plot':
template = os.path.splitext(template)[0]
task = (mod, template)
if task not in services:
services.append(task)
for section in list(self.cron.keys()) + [
'live', 'logged', 'hourly', '12 hourly', 'daily']:
for t_p in ('text', 'plot'):
templates = eval(self.params.get(section, t_p, '[]'))
services = eval(self.params.get(section, 'services', '[]'))
changed = False
for n, template in enumerate(templates):
if isinstance(template, (list, tuple)):
template, flags = template
else:
flags = ''
if 'T' in flags:
templates[n] = template
changed = True
if t_p == 'plot':
result = os.path.splitext(template)[0]
else:
result = template
if 'L' in flags:
task = None
elif 'T' in flags:
task = ('twitter', result)
elif any([x[1] == template for x in services]):
task = None
else:
task = (mod, result)
if task and task not in services:
services.append(task)
changed = True
if changed:
logger.error('updating %s in [%s]', t_p, section)
self.params.set(section, t_p, repr(templates))
self.params.set(section, 'services', repr(services))
if changed:
logger.error('updating %s in [%s]', t_p, section)
self.params.set(section, t_p, repr(templates))
self.params.set(section, 'services', repr(services))
# create service uploader objects
self.services = {}
for section in list(self.cron.keys()) + [
Expand Down

0 comments on commit 32c86b8

Please sign in to comment.