def denied(request): if request.method == 'POST' and 'Tentative' in request.POST: t=request.POST.getlist('denied') request.session['ID'] = t tentative = Appreq.objects.filter(ID__in=t).update(value='0') denied = Appreq.objects.filter(value='-1').order_by('published_date') return render_to_response('app/denied.html', {'request': request, 'user': request.user, 'denied':denied}, RequestContext(request)) elif request.method == 'POST' and 'Accept' in request.POST: t=request.POST.getlist('denied') request.session['ID'] = t accept = Appreq.objects.filter(ID__in=t).update(value='1') create.get_credentials(request) create.main(request) denied = Appreq.objects.filter(value='-1').order_by('published_date') return render_to_response('app/denied.html', {'request': request, 'user': request.user, 'denied':denied}, RequestContext(request)) else: mail= request.user.email name= request.user.get_full_name() n= User.objects.filter(name=name) m=User.objects.filter(mail=mail) if n.exists() and m.exists(): denied = Appreq.objects.filter(value='-1', ename=n).order_by('published_date') return render_to_response('app/denied.html', {'request': request, 'user': request.user, 'denied':denied}, RequestContext(request)) return render_to_response('app/nomatch.html', {}, RequestContext(request))
def manage_control(self): if self.selector.get_selected() == "--------": if self.selector.h == "down": self.selector.down() elif self.selector.h == "up": self.selector.up() if self.selector.get_selected() == "<new>": if self.mode == "select": self.data = { "title":"create a new entry", "desc":"just hit enter", "info":"","from":"","until":"","importance":"" } elif self.mode == "view": create.main(self.body,"create") self.mode = "select" return if self.selector.get_selected() == "<options>": self.data = { "title":"change settings", "desc":"coming soon", "info":"","from":"","until":"","importance":"" }
def do_create(self,arg): """Creates terraform project from the campaign""" dir_path = "projects/"+self.project_id if not os.path.exists(dir_path): self.do_save(None) create.main(self.campaign,self.variables,self.project_id) proj = cmd2.ansi.style(self.project_id, fg='blue', bg='',bold=True, underline=False) notification = cmd2.ansi.style("***", fg='red', bg='',bold=True, underline=False) print(f"""\n{notification} The terrafrom files for the project with ID {proj} have been created {notification}\n""")
def pickMode(mode): #mode is user input string selecting create or search call = False while call == False: #keep asking for input until correct input is found if (mode[0] == "c"): create.main() call = True #stop looping elif (mode[0] == "s"): search.main() call = True #stop looping else: #incorrect input, ask for new input mode = input( 'Unknown Input\nType "c" for create or "s" for search: ')
def upload_file(): if request.method =='POST': # check if the post request has file part if 'file' not in request.files: flash('No file part') return redirect(request.url) file = request.files['file'] # if user does not select file, browser also submit an empty part without filename if file.filename == '': flash('No selected file') return redirect(request.url) if file and allowed_file(file.filename): filename = secure_filename(file.filename) file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename)) create.main(filename) print("it should have worked") return redirect('/')
def main(): refresh() while True: set_marquee() if gui.eventLoop(domainList) == None: break if domainList.getSelectedIndex() == 0: if create.main(window): refresh() else: if operate.run(domainList.getSelected().getDomain()): refresh()
def main(args): command = "" if len(args) > 1 : command = args[1] if command == "create": return create.main(args) elif command == "build": return build.main(args) else: return help.main(args)
def do_create(self, arg): """Creates terraform project from the campaign""" dir_path = "projects/" + self.project_id self.do_save(None) create.main(self.campaign, self.variables, self.project_id)
def edit_entry(self): self._refresh_display() # this too create.main(self.body,"edit",self.selector.get_selected(),self.data) self._loadentries() self.display()
def create_entry (self): self._refresh_display() #this should be in loop function / is done there? create.main(self.body,"new") self._loadentries() self.display() # this is already done in loop function i think, not gonna delete it though you never know
import pygame import create import front_screen import games from data import * pygame.init() screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT)) if __name__ == '__main__': run = 1 while run != 0: if run == 1: run = front_screen.main(screen) if run == 2: run = create.main(screen) if run == 3: run = games.main(screen)
def main(): """Main function in chain.py""" ### Check for existence of .env file in local directory. If not there, ### exit. file_status = str(os.path.exists('.env')) if file_status != 'True': print ('\n The .env file does not exist. Create this file and ' \ 'poplulate it with your API keys per the README.\n') print('Exiting...\n') exit() ### Load Tenable IO API keys from the .env file stored in the current ### directory. Make sure you chmod the file 600 to protect it, and ### assign ownership as necessary. A check below will set the perms to ### 600 if it's not already. Note this check does not run if using the ### -h/--help flag. It only works with create/delete/run args. ### Format of the .env is: # ACCESS_KEY=<access key goes here> # SECRET_KEY=<secret key goe shere> ### load_dotenv() access_key = os.getenv('ACCESS_KEY') secret_key = os.getenv('SECRET_KEY') ### Check for blank API keys or the stub value in the .env file if access_key == '' or secret_key == '' or \ access_key == '<access_key>' or secret_key == '<secret_key>': print ('\n One or more API keys were not declared in the .env file ' \ ' properly.') print(' Exiting...\n') exit() ###Configure command line options using argparse parser = argparse.ArgumentParser(formatter_class=\ argparse.RawTextHelpFormatter) parser.add_argument('--action', choices=[ 'create', 'run', 'delete', 'create-run', 'delete-create', 'delete-create-run', 'info' ], help=textwrap.dedent(''' NOTES: - You cannot delete and then run scans (delete-run), nor create and then delete scans (create-delete). Similarly, create-delete-run is not supported. - The "info" flag will output the folder, scanner, policy, and tag name:ID dictionaries to log.info to assist in buildiling scan definitions in the scans.ini file. Run "./chain.py --action info" to geneate this log. The data is also sent to STDOUT, however it is easier to search/grep from the log.info flat file. - The create/delete/run scripts all log to log.chain in the logs subdirectory. The log file is set to rotate when the size reaches 100K bytes, and keeps a history of 5 log files (log.chain.5 being the oldest and log.chain being the current). Successive instantiations of the run.py script will also log to log.chain. The script name is in the log.chain file, such as "create.py" in the second field (fields delimited by double-colons). Note that the log.info file is cleared on every run of the create/delete/run scripts. This is fine as this data is mutable and should be queried every time a scan in scans.ini is configured or updated. ''')) args = parser.parse_args() # Test to see if logs subdir exists, and if not, create/chmod it if not os.path.exists('logs'): os.makedirs('logs') os.chmod('logs', 0o700) # Test if .env file exists, and if so, chmod it. This file contains # your API keys, so needs to be secured as much as file permissions # allow. Note this check is not executed when using the -h/--help # argument. These perms should alrady be 600, but double checking. fix_perms('./.env') # Check for --action arguments. Will import # necessary .py scripts to create .pyc bytecode # files. Also run fix_perms function to chmod file. if args.action == 'create': import info info.main(access_key, secret_key) import create create.main(access_key, secret_key, info.folder_dict, \ info.scanner_dict, info.policies_dict, info.tag_dict) fix_perms('./logs/log.chain') elif args.action == 'run': import run run.main(access_key, secret_key) fix_perms('./logs/log.chain') elif args.action == 'delete': import delete delete.main(access_key, secret_key) fix_perms('./logs/log.chain') elif args.action == 'create-run': import info info.main(access_key, secret_key) import create create.main(access_key, secret_key, info.folder_dict, \ info.scanner_dict, info.policies_dict, info.tag_dict) import run run.main(access_key, secret_key) fix_perms('./logs/log.chain') elif args.action == 'delete-create': import delete delete.main(access_key, secret_key) import info info.main(access_key, secret_key) import create create.main(access_key, secret_key, info.folder_dict, \ info.scanner_dict, info.policies_dict, info.tag_dict) fix_perms('./logs/log.chain') elif args.action == 'delete-create-run': import delete delete.main(access_key, secret_key) import info info.main(access_key, secret_key) import create create.main(access_key, secret_key, info.folder_dict, \ info.scanner_dict, info.policies_dict, info.tag_dict) import run run.main(access_key, secret_key) fix_perms('./logs/log.chain') elif args.action == 'info': import info info.main(access_key, secret_key) fix_perms('./logs/log.info') else: print( '\n ERROR. No arguments supplied when runing the chain.py script.' ) print(' Run "./chain.py --help" to see usage info.\n') print(' Exiting...\n') exit()
def test_create(monkeypatch, setup): """Test main function.""" global input_num input_num = 0 def mock_input(_): global input_num input_num += 1 if input_num == 1: return '1000' if input_num == 2: return '1200' if input_num == 3: return '100' if input_num == 4: return '10' if input_num == 5: return '12' if input_num == 6: return '0.5' def get_all_out(test_dir, inpfile): res = [] for d in sorted(os.listdir(test_dir)): dir = os.path.join(test_dir, d) if not os.path.isdir(dir): continue with open(os.path.join(dir, inpfile), 'r') as f: res.extend(f.readlines()) return res name = 'WS' inpfile = name + '.dat' monkeypatch.setitem(__builtins__, 'input', mock_input) args = name + ' -e W S --cell create.cell --conv-test cutoff radius' create.main(args.split(), 'teptoolsrc') # Cutoff with open(os.path.join('cutoff', inpfile), 'r') as f: cutoff_out = f.readlines() with open('cutoff_expected.dat', 'r') as f: cutoff_expected = f.readlines() cutoff_all_out = get_all_out('cutoff', inpfile) cutoff_all_expected = [ 'includefile: ../WS.dat\n', '\n', 'cutoff_energy: 1000 eV', 'includefile: ../WS.dat\n', '\n', 'cutoff_energy: 1100 eV', 'includefile: ../WS.dat\n', '\n', 'cutoff_energy: 1200 eV' ] # Radius with open(os.path.join('radius', inpfile), 'r') as f: radius_out = f.readlines() with open('radius_expected.dat', 'r') as f: radius_expected = f.readlines() radius_all_out = get_all_out('radius', inpfile) radius_all_expected = [ 'includefile: ../WS.dat\n', '\n', '%block species\n', 'W W 74 -1 10.0\n', 'S S 16 -1 10.0\n', '%endblock species', 'includefile: ../WS.dat\n', '\n', '%block species\n', 'W W 74 -1 10.5\n', 'S S 16 -1 10.5\n', '%endblock species', 'includefile: ../WS.dat\n', '\n', '%block species\n', 'W W 74 -1 11.0\n', 'S S 16 -1 11.0\n', '%endblock species', 'includefile: ../WS.dat\n', '\n', '%block species\n', 'W W 74 -1 11.5\n', 'S S 16 -1 11.5\n', '%endblock species', 'includefile: ../WS.dat\n', '\n', '%block species\n', 'W W 74 -1 12.0\n', 'S S 16 -1 12.0\n', '%endblock species' ] assert cutoff_out == cutoff_expected assert cutoff_all_out == cutoff_all_expected assert radius_out == radius_expected assert radius_all_out == radius_all_expected