Last active
October 5, 2016 08:37
-
-
Save botcs/aa963f72f201465c25750b7084f89f35 to your computer and use it in GitHub Desktop.
a short compile tester for fixed directory structure repository
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/python3 | |
| import os | |
| import sys | |
| import glob | |
| import shutil | |
| import csv | |
| ######################## | |
| # IMPORTANT! | |
| # The directory structure is hard-coded in the script | |
| # without explicitly passing paths, | |
| # the script will search for ./adatszerk_repo/USER in the directory it was called from | |
| # for each user | |
| ######################## | |
| assert len(sys.argv) > 1, 'At least one subdirectory parameter is required' | |
| # first argument is the name of the script, | |
| # therefore if len(sys.argv) == 1 no arguments were passed explicitly | |
| # 'id.txt' holds user info in (NEPTUN, \t, USER-id) form | |
| # E.g. | |
| ''' | |
| WM2A1V balbe18 | |
| YCQB3S benma7 | |
| I50GCZ farvi1 | |
| CFNRER fulan3 | |
| DLASM2 gobno1 | |
| Y83SUQ mokmi | |
| FDFBH1 nagda4 | |
| IBHJI7 nyaso | |
| ZM6Z9A orbba2 | |
| DFHUZU racam | |
| BFKZJT racfr | |
| MSGFV8 renag | |
| UHDNLA saman2 | |
| X7XKVA szaan40 | |
| HEEM1F totfe2 | |
| Y40B19 vojvi | |
| ''' | |
| with open('id.txt', mode='r') as infile: | |
| reader = csv.reader(infile, delimiter='\t') | |
| user_id = {rows[1]:rows[0] for rows in reader} | |
| if '-u' in sys.argv: | |
| sys.argv.remove('-u') | |
| ######################## | |
| # SVN CHECKOUT | |
| # Call with flag '-u' | |
| ######################## | |
| print('Checking out svn directories...') | |
| if os.path.exists('adatszerk_repo'): | |
| os.system('svn up ./adatszerk_repo/') | |
| else: | |
| os.system("svn co https://wsn.itk.ppke.hu/adatszerk_repo/") | |
| if len(sys.argv) == 2: | |
| print('Only week paramether is given, will check all subdirectories') | |
| subdirs = [] | |
| for user in user_id: | |
| subdirs.append( glob.glob('./adatszerk_repo/' + user + '/')[0] ) | |
| else: | |
| print('Checking the subset of subdirectories') | |
| subdirs = sys.argv[2:] | |
| ######################## | |
| # COMPILATION CHECK | |
| ######################## | |
| # 'week' parameter is where the tester will look for sources in users directory | |
| # E.g. calling './tester.py 02' will look for directories like this: | |
| # ./user123/hazi/02/ | |
| if not os.path.exists('./.ci/'): | |
| os.makedirs('./.ci/') | |
| if not os.path.exists('./.o/'): | |
| os.makedirs('./.o/') | |
| week = sys.argv[1] | |
| flags = '-std=c++11 ' | |
| print('\n\nCompiling sources files with flags:', flags) | |
| success, error, missing = [], [], [] | |
| for sd in subdirs: | |
| user = sd[17:-1] | |
| d = sd + 'hazi/' + week + '/' | |
| print('\n\nCompiling', d) | |
| src = glob.glob(d + '/**/*.cpp', recursive=True) | |
| src += glob.glob(d + '/**/*.hpp', recursive=True) | |
| src += glob.glob(d + '/**/*.h', recursive=True) | |
| if len(src) == 0: | |
| os.system('echo "hianyzo hazi!" > ' + d + 'comment.txt') | |
| missing.append(user) | |
| print(10*'-1' + ' MISSING ' + 10*'-1') | |
| continue | |
| for _ in src: print(' ', _) | |
| src = ' '.join(src) | |
| log = user + '_comp.info' | |
| command = 'g++ ' +\ | |
| flags +\ | |
| src + '* ' +\ | |
| '-o ./.o/' + user + '.o' +\ | |
| '> ./.ci/' + log + ' 2>&1' | |
| # FOR DEBUGGING: uncomment | |
| # print('====>>>>', command) | |
| if os.system(command) == 0: | |
| success.append(user) | |
| print(20*'+' + ' SUCCESS ' + 20*'+') | |
| else: | |
| shutil.copy2('./.ci/' + log, d + log) | |
| error.append(user) | |
| print(21*'x' + ' ERROR ' + 21*'x') | |
| print('\n\n+++++ successfully compilated\t[{}]:'.format(len(success))) | |
| for user in success: print(' ', user_id[user] + '\t' + user) | |
| print('\n\nxxxxx errors in compilation\t[{}]:'.format(len(error))) | |
| for user in error: print(' ', user_id[user] + '\t' + user) | |
| print('\n\n----1 missing source\t[{}]:'.format(len(missing))) | |
| for user in missing: print(' ', user_id[user] + '\t' + user) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment