From 2133ae0726e6e90800187c6008b01bc65afa0438 Mon Sep 17 00:00:00 2001 From: "gasperfele@fri1.uni-lj.si" Date: Sun, 1 Feb 2015 16:29:33 +0000 Subject: task_check for subtask 1 (rename files containing slashes) finished. git-svn-id: https://svn.lusy.fri.uni-lj.si/kpov-public-svn/kpov-public@261 5cf9fbd1-b2bc-434c-b4b7-e852f4f63414 --- .../tasks/copy_rename_20_files_tail_env/task.py | 57 ++++++++++++++-------- 1 file changed, 37 insertions(+), 20 deletions(-) (limited to 'kpov_judge/tasks') diff --git a/kpov_judge/tasks/copy_rename_20_files_tail_env/task.py b/kpov_judge/tasks/copy_rename_20_files_tail_env/task.py index 864d143..28990fc 100644 --- a/kpov_judge/tasks/copy_rename_20_files_tail_env/task.py +++ b/kpov_judge/tasks/copy_rename_20_files_tail_env/task.py @@ -76,14 +76,14 @@ networks = { 'net1': {'public': False}, 'test-net': {'public': True} } params_meta = { 'IP_malishell': {'descriptions': {'si': 'Naslov malishell'}, 'w': True, 'public':True, 'type': 'IP', 'generated': False}, 'file_creator_random_seed': {'descriptions': {'si': 'random file creator seed'}, 'w': False, 'public':False, 'type': None, 'generated': True}, - '20_file_dirname': {'descriptions': {'si': 'imenik z datotekami, ki naj se jih preimenuje'}, 'w': False, 'public':True, 'type': 'dirname', 'generated': True}, + 'file_rename_dirname': {'descriptions': {'si': 'imenik z datotekami, ki naj se jih preimenuje'}, 'w': False, 'public':True, 'type': 'dirname', 'generated': True}, 'mv_src_dir': {'descriptions': {'si': 'imenik, iz katerega premakni datoteke'}, 'w': False, 'public':True, 'type': 'dirname', 'generated': True}, 'mv_dst_dir': {'descriptions': {'si': 'imenik, v katerega premakni datoteke'}, 'w': False, 'public':True, 'type': 'dirname', 'generated': True}, 'cowsay_string': {'descriptions': {'si': 'Kaj rece krava?'}, 'w': False, 'public':True, 'type': 'short', 'generated': True}, 'syslog_n_zmeda': {'descriptions': {'si': 'st. zapisov zmeda v 5s'}, 'w': False, 'public':True, 'type': 'uint', 'generated': True}, } -def task(IP_malishell, 20_file_dirname, mv_src_dir, mv_dst_dir, cowsay_string): +def task(IP_malishell, file_rename_dirname, mv_src_dir, mv_dst_dir, cowsay_string): import pxssh # TODO: (polz) this has to be changed! Get a move on! # @@ -97,24 +97,24 @@ def task(IP_malishell, 20_file_dirname, mv_src_dir, mv_dst_dir, cowsay_string): conn = pxssh.pxssh() conn.login(IP_malishell, 'student', 'vaje') # preimenuj datoteke - conn.sendline('ls -a {}'.format(20_file_dirname)) + conn.sendline('/bin/ls -a1 {}'.format(file_rename_dirname)) conn.prompt() results['preimenuj'] = conn.before # premakni datoteke s cim krajsim ukazom - conn.sendline('ls -a {}'.format(mv_src_dir)) + conn.sendline('/bin/ls -a1 {}'.format(mv_src_dir)) conn.prompt() results['pre_mv_src'] = conn.before - conn.sendline('ls -a {}'.format(mv_dst_dir)) + conn.sendline('/bin/ls -a1 {}'.format(mv_dst_dir)) conn.prompt() results['pre_mv_dst'] = conn.before - conn.sendline('ls -l ~/mv_ukaz') + conn.sendline('/bin/ls -l ~/mv_ukaz') conn.prompt() results['mv_ls_size'] = conn.before conn.sendline('. ~/mv_ukaz') - conn.sendline('ls -a {}'.format(mv_src_dir)) + conn.sendline('/bin/ls -l {}'.format(mv_src_dir)) conn.prompt() results['post_mv_src'] = conn.before - conn.sendline('ls -a {}'.format(mv_dst_dir)) + conn.sendline('/bin/ls -a1 {}'.format(mv_dst_dir)) conn.prompt() results['post_mv_dst'] = conn.before # mama_ukaz @@ -132,7 +132,6 @@ def task(IP_malishell, 20_file_dirname, mv_src_dir, mv_dst_dir, cowsay_string): conn.sendline('cat ~/mama.txt ~/napake.txt') conn.prompt() results['grep_result'] = conn.before - conn.logout() # sledenje syslog conn.sendline('date') conn.prompt() @@ -148,6 +147,7 @@ def task(IP_malishell, 20_file_dirname, mv_src_dir, mv_dst_dir, cowsay_string): conn.sendline('cowsay "{}"'.format(cowsay_string)) conn.prompt() results['cowsay'] = conn.before + conn.logout() #results['curl'] = subprocess.check_output(["cat","/home/student/Desktop/website.txt"]) #results['chkimages'] = subprocess.check_output(["curl www.24ur.com >> dlg.txt && cat dlg.txt | grep -c ","images"]) @@ -172,10 +172,10 @@ def gen_params(user_id, params_meta): homedir = '/home/student/' r = random.Random(user_id) params['file_creator_random_seed'] = str(r.random()) - params['20_file_dirname'] = homedir + kpov_random_helpers.default_generators['dirname'](r) + params['file_rename_dirname'] = homedir + kpov_random_helpers.default_generators['dirname'](r) params['mv_src_dir'] = homedir + "".join([r.choice("abcdefgh") for i in xrange(6)]) params['mv_dst_dir'] = homedir + "".join([r.choice("ijklmnop") for i in xrange(6)]) - params['syslog_n_zmeda'] = r.nextint(5, 15) + params['syslog_n_zmeda'] = str(r.randint(5, 15)) params['cowsay_string'] = kpov_random_helpers.default_generators['short_text'](r) #params['phttp'] = "8080" #params['images'] = subprocess.check_output(["echo","$images"]) @@ -189,12 +189,21 @@ def task_check(results, params): fnames = [] for i in xrange(20): fnames.append("".join([ r.choice("_abcdefghijk") for j in xrange(8)])) - fnames.sort() - print fnames #TO FINISH SCORING WE REQUIRE DICT KEYS AND FUNCTIONS gen_params AND task TO BE FINISHED #POINTS FOR EACH TASK MAY BE ADJUSTED IN THE FUTURE #TASK 1 - print( results['preimenuj']) + # print( results['preimenuj']) + lines = results['preimenuj'].split("\n") + task1_ok = len(lines) == len(fnames) + 4 + task1_ok = task1_ok and lines[0].find(params['file_rename_dirname']) >= 0 + task1_ok = task1_ok and lines[1].strip() == "." + task1_ok = task1_ok and lines[2].strip() == ".." + # print task1_ok + for fname in fnames: + # print task1_ok, fname, results['preimenuj'].find(fname) + task1_ok = task1_ok and results['preimenuj'].find(fname) > 0 + if task1_ok: + score += 2 # premakni datoteke s cim krajsim ukazom fnames = [] for i in xrange(40): @@ -236,18 +245,26 @@ def prepare_disks(templates, params): d = templates['malishell'] r = random.Random(params['file_creator_random_seed']) # rename - d.mkdir(params['20_file_dirname']) + d.mkdir(params['file_rename_dirname']) + d.chown("student", "student", params['file_rename_dirname']) for i in xrange(20): - d.touch(params['20_file_dirname'] + '/' + "".join( - [r.choice("-abcdefghijk") for j in xrange(8)])) + fname = params['file_rename_dirname'] + '/' + "".join( + [r.choice("-abcdefghijk") for j in xrange(8)]) + d.touch(fname) + d.chown("student", "student", fname) # mv ukaz d.mkdir(params['mv_src_dir']) + d.chown("student", "student", params['mv_src_dir']) for i in xrange(40): - d.touch(params['mv_src_dir'] + '/' +"".join( - [r.choice("123456789abcdefghijk") for j in xrange(8)])) + fname = params['mv_src_dir'] + '/' +"".join( + [r.choice("123456789abcdefghijk") for j in xrange(8)]) + d.touch(fname) + d.chown("student", "student", fname) d.mkdir(params['mv_dst_dir']) + d.chown(params['mv_dst_dir']) # grep mama # mama fnames + d.mkdir('/home/student/grep_test_dir') for i in xrange(20): d.write("/home/student/grep_test_dir/" + "".join( [ r.choice("123456789abcdefghijk") for j in xrange(8)]), @@ -267,5 +284,5 @@ def prepare_disks(templates, params): [ r.choice("123456789abcdefghijk") for j in xrange(8)])) # sledenje syslog spammer_source = "#!/bin/sh\n" + int(params['syslog_n_zmeda']) * "logger zmeda\n" - d.write("/usr/local/bin/syslog_spammer") + d.write("/usr/local/bin/syslog_spammer", spammer_source) d.chmod("0775", "/usr/local/bin/syslog_spammer") -- cgit v1.2.1