def siteroot(request): # In addition to requiring the site to be configured, we require that there be a user account. Due to the # setup workflow, the user will generally be created before constance configuration takes place, but if # the user account gets deleted (for example, in the admin) we want the user to go through that portion # of account setup. num_users = User.objects.all().count() if config.GIT_UPDATE_TYPE != "none": # TODO - Reset this to 18 hours # Check the git status at least every 6 hours now_time = pytz.timezone(settings.TIME_ZONE).localize( datetime.datetime.now()) if config.LAST_GIT_CHECK < now_time - datetime.timedelta(hours=6): if git_integration.app_is_current(): config.LAST_GIT_CHECK = now_time else: messages.info( request, "This app is not at the latest version! " + '<a href="/upgrade"">Upgrade from GitHub</a> to receive the latest version.' ) if not config.USER_HAS_COMPLETED_CONFIGURATION or num_users <= 0: # If things aren't configured, redirect to the guided setup workflow return redirect('setup_splash') else: # The default screen is the "lcd list" screen return device_lcd_list(request=request)
def github_trigger_upgrade(request, variant=""): # TODO - Add permission check here commit_info = git_integration.get_local_remote_commit_info() allow_git_branch_switching = config.ALLOW_GIT_BRANCH_SWITCHING app_is_current = git_integration.app_is_current() git_update_type = config.GIT_UPDATE_TYPE tags = git_integration.get_tag_info() if allow_git_branch_switching: branch_info = git_integration.get_remote_branch_info() else: branch_info = {} if request.POST: if app_is_current and 'new_branch' not in request.POST and 'tag' not in request.POST: messages.error(request, "Nothing to upgrade - Local copy and GitHub are at same commit") else: cmds = {} if variant == "": cmds['tag'] = "nohup utils/upgrade.sh -t \"{}\" -b \"master\" &".format(request.POST.get('tag', "")) cmds['no_branch'] = "nohup utils/upgrade.sh -b \"{}\" &".format(commit_info['local_branch']) cmds['branch'] = "nohup utils/upgrade.sh -b \"{}\" &".format(request.POST.get('new_branch', "master")) messages.success(request, "Triggered an upgrade from GitHub") elif variant == "force": cmds['tag'] = "nohup utils/force_upgrade.sh -t \"{}\" -b \"master\" &".format(request.POST.get('tag', "")) cmds['no_branch'] = "nohup utils/force_upgrade.sh -b \"{}\" &".format(commit_info['local_branch']) cmds['branch'] = "nohup utils/force_upgrade.sh -b \"{}\" &".format(request.POST.get('new_branch', "master")) messages.success(request, "Triggered an upgrade from GitHub") else: cmds['tag'] = "" cmds['no_branch'] = "" cmds['branch'] = "" messages.error(request, "Invalid upgrade variant '{}' requested".format(variant)) if 'tag' in request.POST: # If we were passed a tag name, explicitly update to it. Assume (for now) all tags are within master cmd = cmds['tag'] elif not allow_git_branch_switching or 'new_branch' not in request.POST: # We'll use the branch name from the current commit if we either aren't allowed to directly switch branches # or haven't been passed a branch name cmd = cmds['no_branch'] else: cmd = cmds['branch'] subprocess.call(cmd, shell=True) else: # We'll display this error message if the page is being accessed and no form has been posted if app_is_current: messages.warning(request, "Nothing to upgrade - Local copy and GitHub are at same commit") return render_with_devices(request, template_name="github_trigger_upgrade.html", context={'commit_info': commit_info, 'app_is_current': app_is_current, 'branch_info': branch_info, 'tags': tags, 'git_update_type': git_update_type, 'allow_git_branch_switching': allow_git_branch_switching})