Skip to content

Commit

Permalink
Don't create top level data and work directories
Browse files Browse the repository at this point in the history
This should help prevent some of the beginner mistakes caused by
mistyping directory names on a pywws command line.

Signed-off-by: Jim Easterbrook <jim@jim-easterbrook.me.uk>
  • Loading branch information
jim-easterbrook committed Nov 9, 2015
1 parent 2e235e3 commit 50b01cf
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/doc/guides/hourlylogging.rst
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ You should have a ``[paths]`` section similar to the following (where ``xxx`` is
local_files = /home/xxx/weather/results/

Edit these to suit your installation and preferences.
``work`` is a temporary directory used to store intermediate files, ``templates`` is the directory where you keep your text template files, ``graph_templates`` is the directory where you keep your graph template files and ``local_files`` is a directory where template output that is not uploaded to your web site is put.
``work`` is an existing temporary directory used to store intermediate files, ``templates`` is the directory where you keep your text template files, ``graph_templates`` is the directory where you keep your graph template files and ``local_files`` is a directory where template output that is not uploaded to your web site is put.
Don't use the pywws example directories for your templates, as they will get over-written when you upgrade pywws.

Copy your text and graph templates to the appropriate directories.
Expand Down
2 changes: 1 addition & 1 deletion src/doc/guides/livelogging.rst
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ You should have a ``[paths]`` section similar to the following (where ``xxx`` is
local_files = /home/xxx/weather/results/

Edit these to suit your installation and preferences.
``work`` is a temporary directory used to store intermediate files, ``templates`` is the directory where you keep your text template files, ``graph_templates`` is the directory where you keep your graph template files and ``local_files`` is a directory where template output that is not uploaded to your web site is put.
``work`` is an existing temporary directory used to store intermediate files, ``templates`` is the directory where you keep your text template files, ``graph_templates`` is the directory where you keep your graph template files and ``local_files`` is a directory where template output that is not uploaded to your web site is put.
Don't use the pywws example directories for your templates, as they will get over-written when you upgrade pywws.

Copy your text and graph templates to the appropriate directories.
Expand Down
5 changes: 4 additions & 1 deletion src/pywws/DataStore.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ def __init__(self, root_dir, file_name):
self._lock = Lock()
with self._lock:
if not os.path.isdir(root_dir):
os.makedirs(root_dir)
raise RuntimeError(
'Directory "' + root_dir + '" does not exist.')
self._path = os.path.join(root_dir, file_name)
self._dirty = False
# open config file
Expand Down Expand Up @@ -215,6 +216,8 @@ def set_ptr(self, idx):
class core_store(object):
def __init__(self, root_dir):
self._root_dir = root_dir
if not os.path.isdir(self._root_dir):
os.mkdir(self._root_dir)
# initialise caches
self._wr_cache = _Cache()
self._rd_cache = _Cache()
Expand Down
5 changes: 3 additions & 2 deletions src/pywws/Plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -519,9 +519,10 @@ def __init__(self, params, status, raw_data, hourly_data,
params.get('config', 'gnuplot version', '4.2'))
# set language related stuff
self.encoding = params.get('config', 'gnuplot encoding', 'iso_8859_1')
# create work directory
# check work directory exists
if not os.path.isdir(self.work_dir):
os.makedirs(self.work_dir)
raise RuntimeError(
'Directory "' + self.work_dir + '" does not exist.')

def _local_offset(self, time):
try:
Expand Down
8 changes: 6 additions & 2 deletions src/pywws/Tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ def __init__(self, params, status,
self.flush = eval(self.params.get('config', 'frequent writes', 'False'))
# get directories
self.work_dir = self.params.get('paths', 'work', '/tmp/weather')
if not os.path.isdir(self.work_dir):
raise RuntimeError(
'Directory "' + self.work_dir + '" does not exist.')
self.template_dir = self.params.get(
'paths', 'templates', os.path.expanduser('~/weather/templates/'))
self.graph_template_dir = self.params.get(
Expand All @@ -77,7 +80,7 @@ def __init__(self, params, status,
self.uploader = Upload.Upload(self.params)
self.uploads_directory = os.path.join(self.work_dir, 'uploads')
if not os.path.isdir(self.uploads_directory):
os.makedirs(self.uploads_directory)
os.mkdir(self.uploads_directory)
# delay creation of a Twitter object until we know it's needed
self.twitter = None
# create a YoWindow object
Expand Down Expand Up @@ -250,7 +253,8 @@ def _do_common(self, sections, live_data=None):
uploads.append(upload)
if local_files:
if not os.path.isdir(self.local_dir):
os.makedirs(self.local_dir)
raise RuntimeError(
'Directory "' + self.local_dir + '" does not exist.')
for file in local_files:
targ = os.path.join(
self.local_dir, os.path.basename(file))
Expand Down
3 changes: 2 additions & 1 deletion src/pywws/Upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,8 @@ def __init__(self, logger, directory):
def connect(self):
self.logger.info("Copying to local directory")
if not os.path.isdir(self.directory):
os.makedirs(self.directory)
raise RuntimeError(
'Directory "' + self.directory + '" does not exist.')

def put(self, src, dest):
shutil.copy2(src, os.path.join(self.directory, dest))
Expand Down
6 changes: 3 additions & 3 deletions src/pywws/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
__version__ = '15.11.0.dev1318'
_release = '1318'
_commit = '9230995'
__version__ = '15.11.0.dev1319'
_release = '1319'
_commit = '2e235e3'

0 comments on commit 50b01cf

Please sign in to comment.