Skip to content

Commit

Permalink
Fix update_ozw_config. Fix #156. Thanks for reporting.
Browse files Browse the repository at this point in the history
  • Loading branch information
bibi21000 committed Jan 7, 2019
1 parent 8083b50 commit 3ef3e4b
Showing 1 changed file with 10 additions and 25 deletions.
35 changes: 10 additions & 25 deletions src-api/openzwave/controller.py
Expand Up @@ -367,7 +367,7 @@ def python_library_config_version(self):
tversion = "Original %s" % self.library_version
fversion = os.path.join(self.library_config_path, 'pyozw_config.version')
if os.path.isfile(fversion):
with open(fversion, 'r') as f:
with open(fversion, 'r') as f:
val = f.read()
tversion = "Git %s" % val
return tversion
Expand Down Expand Up @@ -1378,7 +1378,7 @@ def update_ozw_config(self):
shutil.rmtree(dest)
except Exception:
pass

if os.path.isdir(self.library_config_path):
#Try to remove old config
try:
Expand All @@ -1392,32 +1392,17 @@ def update_ozw_config(self):
logger.exception("Can't copy to %s", self.library_config_path)

try:
with open(os.path.join(self.library_config_path, 'pyozw_config.version'), 'w') as f:
f.write(time.strftime("%Y-%m-%d %H:%M"))
with open(os.path.join(self.library_config_path, 'pyozw_config.version'), 'w') as f:
f.write(time.strftime("%Y-%m-%d %H:%M"))
except Exception:
logger.exception("Can't update %s", os.path.join(self.library_config_path, 'pyozw_config.version'))
shutil.rmtree(dest)

try:
with open(os.path.join(self.library_config_path, '__init__.py'), 'a') as f:
f.write("#This file is part of **python-openzwave** project https://github.com/OpenZWave/python-openzwave.")
except Exception:
logger.exception("Can't create %s", os.path.join(self.library_config_path, '__init__.py'))
shutil.rmtree(dest)

def update_ozw_config(self):
"""
Update the openzwave config from github.
Not available for shared flavor as we don't want to update the config of the precompiled config.

"""
if self.python_library_flavor in ['shared']:
logger.warning(u"Can't update_ozw_config for this flavor (%s)."%self.python_library_flavor)
return
logger.info(u'Update_ozw_config from github.')
dest = tempfile.mkdtemp()
dest_file = os.path.join(dest, 'open-zwave.zip')
req = urlopen('https://codeload.github.com/OpenZWave/open-zwave/zip/master')
with open(dest_file, 'wb') as f:
f.write(req.read())
zip_ref = zipfile.ZipFile(dest_file, 'r')
zip_ref.extractall(dest)
zip_ref.close()
os.system("cp -rf %s %s"%(os.path.join(dest, 'open-zwave-master', 'config'), self.library_config_path))
with open(os.path.join(self.library_config_path, 'pyozw_config.version'), 'w') as f:
f.write(time.strftime("%Y-%m-%d %H:%M"))

0 comments on commit 3ef3e4b

Please sign in to comment.