# TODO: # - check if everything is filled in (computers, params, preparation) # - improve scoring # - test # - switch to a real SSH/SFTP client to properly handle filenames instructions = { 'si':u""" Ustvari dva navidezna računalnika - simpleArbiter in studentGUI. Poskrbi, da bosta oba na istem omrežju in da bo imel studentGUI naslov {student_IP}. Obenem mora biti simpleArbiter povezan na Internet. Računajte, da se na studentGUI ob zagonu zažene program {net_prog_name}, ki vam spreminja nastavitve mrežne kartice. V domačem imeniku uporabnika test obstaja program {P_c} v programskem jeziku C. Prevedite ga v program z imenom {P_executable}. Napišite skripto ali program {P_script} v domačem imeniku uporabnika test, ki: - požene {P_c} z argumentom {arg_c} in mu na standardni vhod pripelje vrednost spremenljivke {env_c} - vse, kar {P_c} izpiše na stderr, spravi v datoteko {out_stderr_c}. - vse vrstice, ki jih {P_c} izpiše na stdout in vsebujejo zaporedje znakov "ma", zapiši v {out_stdout_c}. Nekje v domačem imeniku uporabnika test se skriva datoteka "najdime.txt". V njej nadomestite vse pojavitve niza "mami" z "mati". Lastnik vseh ustvarjenih datotek mora biti uporabnik test. Gesla uporabnika test ne smete spreminjati. """, 'en': u''' ''', } computers = { 'SimpleArbiter': { 'disks': [ { 'name': 'simpleArbiter', }, ], 'network_interfaces': [ {'network': 'net1'}, {'network': 'net2'}, ], 'flavor': 'm1.tiny', 'config_drive': True, } 'SimpleStudent': { 'disks': [ {'name': 'student-mock_entrance'} ] 'flavor': 'm1.tiny', 'network_interfaces': [{'network': 'net1'}], 'config_drive': True, } } networks = { 'net1': { 'public': True, }, 'net2': { 'public': False, }, } params_meta = { 'student_IP': { 'descriptions': { 'si': 'IP naslov SimpleStudent', 'en': 'IP address of SimpleStudent', }, 'w': False, 'public': True, 'type': 'IP', 'generated': True, }, 'net_prog_name': { 'descriptions': { 'si': 'Ime programa, ki ponastalvlja naslov', 'en': 'The name of the program resetting the network' } 'w': False, 'public': True, 'type': 'filename', 'generated': True, }, 'P_c': { 'descriptions': { 'si': 'Datoteka s programom v C', 'en': 'Filename of the program in C', }, 'w': False, 'public': True, 'type': 'filename', 'generated': False, }, 'P_executable': { 'description': { 'si': 'Ime prevedenega programa v C', 'en': 'Filename of the compiled C program' } }, 'arg_c': { 'descriptions': { 'si': 'Vrednost argumenta', 'en': 'Argument value', }, 'w': False, 'public': True, 'type': 'short_text', 'generated': False, }, 'env_c': { 'descriptions': { 'si': 'Ime okoljske spremenljivke', 'en': 'The name of the environment environment', }, 'w': False, 'public': True, 'type': 'short_text', 'generated': False, }, 'out_stderr_c': { 'descriptions': { 'si': 'Datoteka z napakami', 'en': 'File to store errors', }, 'w': True, 'public': True, 'type': 'filename', 'generated': False, }, 'P_script': { 'descriptions': { 'si': 'Ime skripte', 'en': 'Filename of the script', }, 'w': False, 'public': True, 'type': 'filename', 'generated': True, }, 'out_stdout_c': { 'descriptions': { 'si': 'Datoteka z izhodom', 'en': 'File to store the output', }, 'w': False, 'public': True, 'type': 'filename', 'generated': False, }, 'mati_path': { 'descriptions': { 'si': 'Lokacija najdime.txt', 'en': 'Location of najdime.txt', }, 'w': False, 'public': False, 'type': 'dirname', 'generated': True, }, } def task(student_IP, net_prog_name, P_c, P_executable, arg_c, env_c, out_stderr_c, out_stdout_c, P_script mati_path): import pxssh # ideally, this would be done using a SFTP client instead of pxssh target = pxssh.pxssh() target.login(student_IP, 'test', 'test') results = { 'script_run': target.run('').split('\n'), # 'contents': target.run("cat *"), # '' } target.logout() return results def gen_params(user_id, params_meta): pass def task_check(results, params): import os score = 0 hints = [] matched = 0 files = os.listdir(params['folder']) for fn in files: if fn in results['files']: matched += 1 if matched > 0: score = 1 else: hints += ["no files"] if matched > len(files)/2: score += 2 else: hints += ["less than half the files"] if (matched == len(files)): score += 3 else: hints += ["wrong number of files"] rl = results['contents'].split('\n') rl.sort() tl = [] for fn in files: with open(fn) as f: tl += f.read().upper().split('\n') tl.sort() if rl == tl: score += 4 else: hints += ["wrong files"] return hints, score def prepare_disks(templates, params): pass