Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] formio : Formio.js version updates in Windows environments are not available #92

Merged
merged 6 commits into from
Dec 15, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions formio/models/formio_version_github_tag.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import requests
import shutil
import tarfile
import sys

from odoo import api, fields, models, modules

Expand Down Expand Up @@ -76,17 +77,24 @@ def action_download_install(self):
response = requests.get(self.archive_url, stream=True)
logger.info('download => %s' % self.archive_url)
tar_path = '/tmp/%s.tar.gz' % self.version_name

static_path = modules.get_module_resource('formio', 'static/installed')
if sys.platform == 'win32':
tar_path = '%s\\%s.tar.gz' % (static_path, self.version_name)
if response.status_code == 200:
with open(tar_path, 'wb') as f:
f.write(response.raw.read())
tar = tarfile.open(tar_path)
tar.extractall('/tmp', members=self._tar_extract_members(tar))
if sys.platform == 'win32':
tar.extractall('%s' % static_path, members=self._tar_extract_members(tar))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@niulinlnc no need for string templating (%s) right?

else:
tar.extractall('/tmp', members=self._tar_extract_members(tar))
tar.close()

extract_path = '/tmp/formio.js-%s/dist' % self.version_name
if sys.platform == 'win32':
extract_path = '%s\\formio.js-%s\\dist' % (static_path, self.version_name)

static_path = modules.get_module_resource('formio', 'static/installed')
# static_path = modules.get_module_resource('formio', 'static/installed')
static_version_dir = '%s/%s' % (static_path, self.version_name)
os.makedirs(static_version_dir, exist_ok=True)

Expand Down Expand Up @@ -155,13 +163,17 @@ def action_download_install(self):

# cleanup and update
os.remove(tar_path)
shutil.rmtree(extract_path)
tmp_path = '/tmp/formio.js-%s' % self.version_name
if sys.platform == 'win32':
tmp_path = '%s\\formio.js-%s' % (static_path, self.version_name)
shutil.rmtree(tmp_path)
self.write({'state': STATE_INSTALLED, 'formio_version_id': version.id})

def action_reset_installed(self):
if self.formio_version_id:
vals = {'formio_version_id': False, 'state': STATE_REGISTERD}
vals = {'formio_version_id': False, 'state': STATE_AVAILABLE}
self.write(vals)
self.action_download_install()

def _tar_extract_members(self, members):
full_todo = ['formio.full.min.js', 'formio.full.min.css']
Expand Down