import os import re from string import Template from subprocess import call, Popen, PIPE from time import strftime, sleep, gmtime, mktime from datetime import datetime from locator import module_path g_BaseDir = os.path.normpath(os.path.join(module_path(), '..')) g_TmplDir = os.path.join(g_BaseDir, 'Templates') g_QuickNoteDir = os.path.join(g_BaseDir, 'QuickNotes') g_AhkDir = os.path.join(g_BaseDir, 'AHK') when_mapping = ['', 'Now', 'Next', 'Soon', 'Later', 'Someday', 'WaitingFor'] action_contexts = frozenset(('@Agenda', '@Computer', '@Home', '@Office', '@Online', '@Out', '@Phone', '@Wherever')) g_FixMeTag = '~FIXME' # Tag to use in case of unmatched action context g_DefaultReminderTime = (9, 0, 0) # 9am (H, M, S) g_OpenNoteCmd = [os.path.join(g_AhkDir, 'OpenNote.exe')] g_DryRun = False # Invoke the ENScript.exe Evernote program (modify path if needed) def call_enscript(args): cmd = ['C:\\Program Files (x86)\\Evernote\\Evernote\\ENScript.exe'] cmd.extend(args) if g_DryRun: print cmd else: call(cmd) # Applies template-parameters to template-file
import os import re from string import Template from subprocess import call, Popen, PIPE from time import strftime, sleep, gmtime, mktime from locator import module_path g_BaseDir = os.path.normpath(os.path.join(module_path(), '..')) g_TmplDir = os.path.join(g_BaseDir, 'Templates') g_QuickNoteDir = os.path.join(g_BaseDir, 'QuickNotes') g_AhkDir = os.path.join(g_BaseDir, 'AHK') when_mapping = ['', 'Now', 'Next', 'Soon', 'Later', 'Someday', 'WaitingFor'] action_contexts = frozenset(('@Agenda', '@Computer', '@Home', '@Office', '@Online', '@Out', '@Phone', '@Wherever')) g_FixMeTag = '~FIXME' # Tag to use in case of unmatched action context g_DefaultReminderTime = (9, 0, 0) # 9am (H, M, S) g_OpenNoteCmd = [os.path.join(g_AhkDir, 'OpenNote.exe')] g_DryRun = False # Invoke the ENScript.exe Evernote program (modify path if needed) def call_enscript(args): cmd = ['ENScript.exe'] cmd.extend(args) if g_DryRun: print cmd else: call(cmd)
def get_abs_base_dir_path(): return locator.module_path() + os.sep
def main(): if len(sys.argv) != 2: sys.exit('Usage: {0} <class name>'.format(sys.argv[0])) class_name = sys.argv[1] try: config = GraderConfiguration(on_grading_server=True) except ConfigurationError as e: sys.exit(e) if class_name not in config.students_by_class: sys.exit('No student CSV file for {0}'.format(class_name)) call_action_path = os.path.join(locator.module_path(), 'call_action.sh') if not os.path.isfile(call_action_path): sys.exit('{0} does not exist'.format(call_action_path)) update_flag_queue = Queue() push_monitor = PushMonitor(update_flag_queue) # stores student submission repositories indexed by their # update_flag file paths, which are watched by inotify repos_by_update_flag_path = {} add_update_flag_watches(class_name, config, push_monitor, repos_by_update_flag_path) assignments_path = os.path.join(config.home_dir, class_name, 'assignments') active_assignments = set(os.listdir(assignments_path)) print('Current assignments:') for assignment in active_assignments: print(assignment) last_assignment_poll_time = time() email_queue = Queue() email_thread = Thread(target=process_email_queue, args=(email_queue, class_name, config)) email_thread.start() print('daemon initialized, waiting for pushes') while True: try: if time() - last_assignment_poll_time > 5: current_assignments = set(os.listdir(assignments_path)) last_assignment_poll_time = time() if current_assignments != active_assignments: new_assignments = \ current_assignments.difference(active_assignments) for new_assignment in new_assignments: print('I see a new directory for assignment {0}' .format(new_assignment)) new_assignment_path = os.path.join(assignments_path, new_assignment) print('Path:', new_assignment_path) email_file_path = os.path.join(new_assignment_path, 'email.txt') retries = 0 while (not os.path.isfile(email_file_path) and retries < 10): retries += 1 print('I see no email.txt, retry', retries) sleep(2) if os.path.isfile(email_file_path): print('email.txt exists, adding assignment') add_update_flag_watches(class_name, config, push_monitor, repos_by_update_flag_path, assignment=new_assignment) email_students_new_assignment(class_name, new_assignment, email_file_path, config, email_queue) else: print('No email.txt, skipping assignment') active_assignments = current_assignments update_flag_path = update_flag_queue.get(block=True, timeout=0.5) repo = repos_by_update_flag_path[update_flag_path] assert isinstance(repo, Repository) student = config.students_by_username[repo.student_username] print('{0}: New push from {1}'.format(class_name, student.username)) test_repo_path = os.path.join(assignments_path, repo.assignment, repo.assignment + '_tests.git') reports_repo_path = os.path.join(assignments_path, repo.assignment, repo.assignment + '_reports.git') test_repo = Repository(test_repo_path, repo.assignment, is_bare=True) reports_repo = Repository(reports_repo_path, repo.assignment, is_bare=True) run_tests(repo, test_repo, reports_repo, call_action_path, student, email_queue) except Empty: pass except KeyboardInterrupt: print('Keyboard interrupt caught') break print('Shutting down') email_queue.put(None) emailer_shutdown_time = 10 print('Waiting up to {0} seconds for emailer to shut down' .format(emailer_shutdown_time)) email_thread.join(timeout=emailer_shutdown_time)