Fix upgrade stdout handling if file doesn't exist yet

plus some other tweaks..
This commit is contained in:
Lance Edgar 2017-08-09 11:56:25 -05:00
parent e5b0fe7198
commit 773a0c769d
3 changed files with 19 additions and 12 deletions

View file

@ -12,11 +12,13 @@
location.href = '${cancel_url}'; location.href = '${cancel_url}';
} else { } else {
var stdout = $('.stdout'); if (data.stdout) {
var height = $(window).height() - stdout.offset().top - 50; var stdout = $('.stdout');
stdout.height(height); var height = $(window).height() - stdout.offset().top - 50;
stdout.append(data.stdout); stdout.height(height);
stdout.animate({scrollTop: stdout.get(0).scrollHeight - height}, 250); stdout.append(data.stdout);
stdout.animate({scrollTop: stdout.get(0).scrollHeight - height}, 250);
}
if (data.complete || data.maximum) { if (data.complete || data.maximum) {
$('#message').html(data.message); $('#message').html(data.message);

View file

@ -895,6 +895,10 @@ class MasterView(View):
progress.session['success_url'] = success_url progress.session['success_url'] = success_url
progress.session.save() progress.session.save()
def execute_error_message(self, error):
return "Execution of {} failed: {}: {}".format(self.get_model_title(),
type(error).__name__, error)
def get_execute_success_url(self, obj, **kwargs): def get_execute_success_url(self, obj, **kwargs):
return self.get_action_url('view', obj, **kwargs) return self.get_action_url('view', obj, **kwargs)

View file

@ -298,13 +298,14 @@ class UpgradeView(MasterView):
path = self.rattail_config.upgrade_filepath(upgrade.uuid, filename='stdout.log') path = self.rattail_config.upgrade_filepath(upgrade.uuid, filename='stdout.log')
offset = session.get('stdout.offset', 0) offset = session.get('stdout.offset', 0)
size = os.path.getsize(path) - offset if os.path.exists(path):
with open(path, 'rb') as f: size = os.path.getsize(path) - offset
f.seek(offset) with open(path, 'rb') as f:
chunk = f.read(size) f.seek(offset)
data['stdout'] = chunk.replace('\n', '<br />') chunk = f.read(size)
session['stdout.offset'] = offset + size data['stdout'] = chunk.replace('\n', '<br />')
session.save() session['stdout.offset'] = offset + size
session.save()
return data return data