def edit_release(game_slug="", release_id=""): form = ReleaseForm() error = None game = Game.query.filter(Game.slug==game_slug).one() release = db.session.query(Release).filter(Release.id==release_id).one() if form.validate_on_submit(): release.release_date = form.release_date.data release.release_version = form.release_version.data release.engine_id = form.engine_id.data release.release_description = form.release_description.data release.engine_version = form.engine_version.data platforms = [] for platform in release.platforms: if not platform.platform_id in form.platforms.data: pl = PlatformRelease.query.filter_by(id=platform.id).first() db.session.delete(pl) platforms.append(platform.platform_id) for platform in form.platforms.data: if not platform in platforms: db.session.add(PlatformRelease(release_id=release.id, platform_id=platform)) db.session.commit() flash('Release data was saved.') return redirect(url_for('game_details', game_slug=game_slug)) else: form.release_date.data = release.release_date form.release_version.data = release.release_version form.engine_id.data = release.engine_id form.release_description.data = release.release_description form.engine_version.data = release.engine_version form.platforms.data = [] for platform in release.platforms: form.platforms.data.append(platform.platform_id) return render_template('add_release.html', game=game, navigation=return_navigation(), error=error, site_data=site_data(), form=form)
def add_release(game_slug=""): form = ReleaseForm() error = None game = Game.query.filter(Game.slug==game_slug).one() if form.validate_on_submit(): release = Release(game_id=game.id, release_date=form.release_date.data, release_version=form.release_version.data, engine_id=form.engine_id.data, release_description = form.release_description.data, engine_version = form.engine_version.data, user_id=g.user.id) save_release(release, form.platforms.data) db.session.commit() flash('New release data was added.') return redirect(url_for("upload_file", game_slug=game_slug)+'?release='+str(release.id)) return render_template('add_release.html', game=game, navigation=return_navigation(), error=error, site_data=site_data(), form=form)
def dir(id): def tagstring(str,tag): return "<%s>%s</%s>"%(tag,str,tag) PTYPE2URI = { 'f':'file', 'd':'dir' } from copyright import crtype2csstag ScanPathes = get_model("scanpathes") path = ScanPathes.get(id) assert(path.type=='d') children = ScanPathes.filter(ScanPathes.c.parent==path.id) from forms import ReleaseForm rform = ReleaseForm() if request.method == 'POST': if rform.validate(request.params, request.files): release = rform.data['release'] rnote = rform.data['rnote'] changed = False if release!=path.release: path.release=release changed = True if release: flash("Release this package !") else: flash("Do not release this package !") if rnote!=path.rnote: path.rnote = rnote changed = True if changed: path.save() else: rform.data['release']=path.release rform.data['rnote']=path.rnote return { 'path':path, 'children':children, 'crtype2csstag':crtype2csstag, 'tagstring':tagstring, 'PTYPE2URI':PTYPE2URI, 'rform':rform, }
def createRelease(request, num): App = apps.get_model('apps', 'App') try: release_app = App.objects.get(id=num) except: context = { 'message': "Requested App does not Exist!", 'go_back_to_url': "/app/" + release_app.name, 'go_back_to_title': "App Page", } return render(request, 'message.html', context) editors = release_app.editors.all() if request.user in editors or request.user.is_staff: if request.method == 'GET': form = ReleaseForm() elif request.method == 'POST': form = ReleaseForm(request.POST, request.FILES) if form.is_valid(): new_release = form.save(commit=False) new_release.app = release_app new_release.save() context = { 'message': "Release added Successfully!", 'go_back_to_url': "/app/" + release_app.name, 'go_back_to_title': "App Page", } return render(request, 'message.html', context) else: context = { 'message': "You are not authorized to view this page!", 'go_back_to_url': "/app/" + release_app.name, 'go_back_to_title': "App Page", } return render(request, 'message.html', context) return render(request, 'create_release.html', {'form': form})
def dir(id): def tagstring(str, tag): return "<%s>%s</%s>" % (tag, str, tag) PTYPE2URI = {'f': 'file', 'd': 'dir'} ScanPathes = get_model("scanpathes") path = ScanPathes.get(id) assert (path.type == 'd') children = ScanPathes.filter(ScanPathes.c.parent == path.id) from forms import ReleaseForm rform = ReleaseForm() if request.method == 'POST': if rform.validate(request.params, request.files): release = rform.data['release'] rnote = rform.data['rnote'] changed = False if release != path.release: path.release = release changed = True if release: flash("Release this package !") else: flash("Do not release this package !") if rnote != path.rnote: path.rnote = rnote changed = True if changed: path.save() else: rform.data['release'] = path.release rform.data['rnote'] = path.rnote return { 'path': path, 'children': children, 'crtype2csstag': crtype2csstag, 'tagstring': tagstring, 'PTYPE2URI': PTYPE2URI, 'rform': rform, }
def editRelease(request, num): Release = apps.get_model('apps', 'Release') App = apps.get_model('apps', 'App') try: edit_release = Release.objects.get(id=num) except: context = { 'message': "Requested App does not Exist!", 'go_back_to_url': "/app/" + edit_release.app.name, 'go_back_to_title': "App Page", } return render(request, 'message.html', context) editors = edit_release.app.editors.all() if request.user in editors or request.user.is_staff: if request.method == 'GET': form = ReleaseForm(instance=edit_release) elif request.method == 'POST': form = ReleaseForm(request.POST, request.FILES, instance=edit_release) if form.is_valid(): edited_release = form.save() edited_release.save() context = { 'message': "Release edited Successfully!", 'go_back_to_url': "/app/" + edit_release.app.name, 'go_back_to_title': "App Page", } return render(request, 'message.html', context) else: context = { 'message': "You are not authorized to view this page!", 'go_back_to_url': "/app/" + edit_release.app.name, 'go_back_to_title': "App Page", } return render(request, 'message.html', context) return render(request, 'edit_release.html', {'form': form})
def code_release(request, template_name='saltstack/code_release_form.html'): form = ReleaseForm(request.POST or None) servers = Assets.objects.all() departments = Department.objects.all() zones = Zone.objects.all() repo = Repository.objects.all() deploy_path = Path.objects.all() global status if form.is_valid(): repo_name = form.cleaned_data['repository_name'] result = Repository.objects.filter(repo_name__contains=repo_name)[0] if result.repo_protocol == '3': repository_url = 'https://%s:%s@%s' % (result.repo_user, result.repo_pass, result.repo_address) elif result.repo_protocol == '2': repository_url = 'http://%s:%s@%s' % (result.repo_user, result.repo_pass, result.repo_address) else: repository_url = '%s@%s' % (result.repo_user, result.repo_address) project_name = form.cleaned_data['repository_name'].repo_tag zone_name = form.cleaned_data['zones'].name deploy_path = form.cleaned_data['deploy_path'].path_value release_path = form.cleaned_data['release_path'].path_value # versions = form.cleaned_data['versions'] # version = versions.version # version_id = versions.id print project_name, zone_name, release_path if form.cleaned_data['use_zone']: deploy_abs_path = os.path.join(deploy_path, (project_name + '_' + zone_name)) release_abs_path = release_path + '_' + zone_name else: deploy_abs_path = os.path.join(deploy_path, project_name) release_abs_path = release_path fun_value = dict(RELEASE_FUN_CHOICES).get(form.cleaned_data['fun']) data = { 'expr_form': 'list', 'client': form.cleaned_data['client'], 'tgt': [item.host_name for item in form.cleaned_data['tgt']], 'fun': fun_value, 'arg': [deploy_abs_path, repository_url], } print data salt = SaltApi() salt.get_token() header = salt.get_header() context = process(header, **data) print context if form.cleaned_data['fun'] == u'1': shell = 'rm -rf %s && ln -s %s %s' % (release_abs_path, deploy_abs_path, release_abs_path) data = { 'expr_form': 'list', 'client': form.cleaned_data['client'], 'tgt': [item.host_name for item in form.cleaned_data['tgt']], 'fun': 'cmd.run', 'arg': shell, } # print data release_context = process(header, **data) else: release_context = "symlink not change." for item in form.cleaned_data['tgt']: result = yaml.load(context)['return'][0][item.host_name] if result is True or result == "Already up-to-date." and regex_match_error(release_context) is True: status = True else: status = False new_form = form.save(commit=False) new_form.context = context new_form.deploy_path = deploy_abs_path new_form.release_path = release_abs_path new_form.operate = request.session['username'] new_form.status = status new_form.save() form.save() return redirect('code_release_list') return render(request, template_name, {'highlight2': 'active', 'username': request.session['username'], 'form': form, 'servers': servers, 'departments': departments, 'zones': zones, 'deploy_path': deploy_path, 'repo': repo, 'var7': 'active', })