[vmchecker-dev] [PATCH] moved vmcheckerpaths in a separate module

Alexandru Moșoi brtzsnr at gmail.com
Sat Mar 28 11:51:53 EET 2009


---
 .gitignore               |    1 +
 bin/db_gentest.py        |   16 ++++---
 bin/initialise_course.py |   72 ++++++++++++++----------------
 bin/misc.py              |  109 +++++-----------------------------------------
 bin/queue_manager.py     |    2 +-
 bin/submit.py            |    6 +-
 bin/update_db.py         |   92 ++++++++++++++++++++-------------------
 bin/view_grades.py       |   26 ++++++++---
 bin/vmcheckerpaths.py    |   80 +++++++++++++++++++++++++++++++++
 9 files changed, 206 insertions(+), 198 deletions(-)
 create mode 100644 bin/vmcheckerpaths.py

diff --git a/.gitignore b/.gitignore
index 52e4e61..17d8f51 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,3 @@
 *.pyc
 *.pyo
+*.patch
diff --git a/bin/db_gentest.py b/bin/db_gentest.py
index bd99e90..675e9fd 100755
--- a/bin/db_gentest.py
+++ b/bin/db_gentest.py
@@ -1,28 +1,32 @@
 #!/usr/bin/python
 
-""" The script generates a test tree for checked homeworks """
+"""The script generates a test tree for checked homeworks."""
 
 
 __author__ = 'Gheorghe Claudiu-Dan, claudiugh at gmail.com'
 
 
-import misc
 import os
 import logging
 
-logging.basicConfig(level=logging.DEBUG)
-logger = logging.getLogger("vmchecker.db_gentest")
+import misc
+import vmcheckerpaths
+
 
 NO_OF_HWS = 10
 NO_OF_STUDENTS = 100
 GRADE = 10
 GRADE_FILENAME = 'NOTA'
 
+
 if __name__ == "__main__":
-    root = misc.vmcheckerPaths.dir_checked
+    logging.basicConfig(level=logging.DEBUG)
+    logger = logging.getLogger('vmchecker.db_gentest')
+
+    root = vmcheckerpaths.dir_checked()
     
     if not os.path.exists(root):
-        logger.error(" %s directory does not exist " % root)
+        logger.error('%s directory does not exist' % root)
         exit()
     
     for hw_index in range(0,NO_OF_HWS):
diff --git a/bin/initialise_course.py b/bin/initialise_course.py
index 97958d4..efd7e3d 100755
--- a/bin/initialise_course.py
+++ b/bin/initialise_course.py
@@ -1,67 +1,60 @@
 #! /usr/bin/env python2.5
-# Initialises the directory path for one course 
+# -*- coding: utf-8 -*-
+"""Initialises the directory path for one course"""
 
-__author__ = """ Ana Savu, <ana.savu86 at gmail.com>
-             Lucian Adrian Grijincu <lucian.grijincu at gmail.com>"""
+__author__ = """Ana Savu, <ana.savu86 at gmail.com>
+                Lucian Adrian Grijincu <lucian.grijincu at gmail.com>"""
 
 
 import os
 import sqlite3
-import misc
 import sys
 import logging
-
 from subprocess import check_call, CalledProcessError
 
-
-
-logging.basicConfig(level=logging.DEBUG)
-logger = logging.getLogger("vmchecker.initialise_course")
+import misc
+import vmcheckerpaths
 
 
 def _mkdir_if_not_exist(path):
     if not(os.path.isdir(path)):
         os.mkdir(path)
     else:
-        logger.info("Skipping existing directory %s" % path)
+        logger.info('Skipping existing directory %s' % path)
+
 
 def _create_paths(paths):
     for path in paths:
         _mkdir_if_not_exist(path)
 
-def create_tester_paths():
-    """ Create all paths used by vmchecker on the storer machine""" 
-    tester_paths = misc.vmcheckerPaths.tester_paths
-    _create_paths(tester_paths)
-
 
+def create_tester_paths():
+    """Create all paths used by vmchecker on the storer machine"""
+    _create_paths(vmcheckerpaths.tester_paths())
 
 
 def create_storer_paths():
-    """ Create all paths used by vmchecker on the storer machine""" 
-    storer_paths = misc.vmcheckerPaths.storer_paths
-    _create_paths(storer_paths)
+    """Create all paths used by vmchecker on the storer machine"""
+    _create_paths(vmcheckerpaths.storer_paths)
 
 
 def create_storer_git_repo():
-    """ Create the repo for the assignments on the storer """
-
+    """Creates the repo for the assignments on the storer."""
     # first make teh destination directory
-    rel_repo_path = misc.config().get("DEFAULT", "Repository")
-    abs_repo_path = misc.vmcheckerPaths.abs_path(rel_repo_path)
+    rel_repo_path = misc.config().get('DEFAULT', 'Repository')
+    abs_repo_path = vmcheckerpaths.abspath(rel_repo_path)
     _mkdir_if_not_exist(abs_repo_path)
     
-    
     # then, if missing, initialize a git repo in it.
-    repo_path_git = os.path.join(abs_repo_path, ".git")
+    repo_path_git = os.path.join(abs_repo_path, '.git')
     if not(os.path.isdir(repo_path_git)):
         # no git repo found in the dir.
         try:
             e = os.environ
-            e["GIT_DIR"] = repo_path_git
+            e['GIT_DIR'] = repo_path_git
             check_call(['git', 'init'], env=e)
         except CalledProcessError:
-            logging.error("cannot create git repo in %s" % repo_path_git)
+            logging.error('cannot create git repo in %s' % repo_path_git)
 
 
 def create_db_tables(db_path):
@@ -88,40 +81,43 @@ def create_db_tables(db_path):
 
 def create_db():
     # check for DB existance
-    db_file = misc.vmcheckerPaths.db_file
-    if None == db_file:
-        create_db(db_file)
+    db_file = vmcheckerpaths.db_file()
+    if not os.path.isfile(db_file):
+        create_db_tables(db_file)
     else:
-        logger.info("Skipping existing Sqlite3 DB file %s" % db_file)
-
-        
+        logger.info('Skipping existing Sqlite3 DB file %s' % db_file)
 
 
 def main_storer():
     create_storer_paths()
     create_storer_git_repo()
     create_db()
-    logger.info(" -- storer init done setting up paths and db file.")
+    logger.info(' -- storer init done setting up paths and db file.')
+
 
 def main_tester():
     create_tester_paths()
-    logger.info(" -- tester init done setting up paths and db file.")
+    logger.info(' -- tester init done setting up paths and db file.')
+
 
 def usage():
     print("""Usage: 
 \t%s storer - initialize storer machine
 \t%s tester - initialize tester machine
-\t%s --help - print this message""" % (sys.argv[0], sys.argv[0], sys.argv[0]))
+\t%s --help - print this message"""% (sys.argv[0], sys.argv[0], sys.argv[0]))
 
 if __name__ == '__main__':
+    logging.basicConfig(level=logging.DEBUG)
+    logger = logging.getLogger("vmchecker.initialise_course")
+
     if (len(sys.argv) < 2):
         usage()
         exit(1)
-    if   cmp(sys.argv[1], "storer") == 0:
+    if cmp(sys.argv[1], 'storer') == 0:
         main_storer()
-    elif cmp(sys.argv[1], "tester") == 0:
+    elif cmp(sys.argv[1], 'tester') == 0:
         main_tester()
-    elif cmp(sys.argv[1], "--help") == 0:
+    elif cmp(sys.argv[1], '--help') == 0:
         usage()
     else:
         usage()
diff --git a/bin/misc.py b/bin/misc.py
index f08f85f..60d5f22 100644
--- a/bin/misc.py
+++ b/bin/misc.py
@@ -1,46 +1,46 @@
 #! /usr/bin/env python2.5
 # -*- coding: utf-8 -*-
-# vim: set expandtab :
+
+
 from __future__ import with_statement
 
-__author__ = 'Alexandru Mosoi <brtzsnr at gmail.com>'
+__author__ = 'Alexandru Moșoi <brtzsnr at gmail.com>'
 
 
 import fcntl
 import os
 import socket
 import struct
-
 import ConfigParser
 
+import vmcheckerpaths
 
-DATE_FORMAT = '%Y.%m.%d %H:%M:%S'
-VMCHECKER_INI = 'vmchecker_storer.ini'
 
+DATE_FORMAT = '%Y.%m.%d %H:%M:%S'
 _config = None
 
 
-
 def config():
     """Returns a RawConfigParse containing vmchecker's configuration."""
     global _config
     if _config is None:
         _config = ConfigParser.RawConfigParser()
-        with open(vmcheckerPaths.config_file) as handle:
+        with open(vmcheckerpaths.config_file()) as handle:
             _config.readfp(handle)
     return _config
 
 
 def relative_path(*args):
     """Joins the arguments and returns a path relative to root"""
-    return os.path.join(vmcheckerPaths.root, os.path.join(*args))
+    return os.path.join(vmcheckerpaths.root(), os.path.join(*args))
 
 
 def repository(assignment):
     """Returns repository where sources for assignment are stored.
  
     NOTE: Full path where they are actually stored is
-    `repository/assignment'"""
+    `repository/assignment'
+    """
     return relative_path(config().get(assignment, 'Repository'))
 
 
@@ -49,98 +49,11 @@ def get_ip_address(ifname):
     in standard dotted notation.
 
     Source from:
-        http://code.activestate.com/recipes/439094/"""
+        http://code.activestate.com/recipes/439094/
+    """
     s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
     return socket.inet_ntoa(fcntl.ioctl(
         s.fileno(),
         0x8915,  # SIOCGIFADDR
         struct.pack('256s', ifname[:15]))[20:24])
 
-#todo
-def db_file():
-    """ The name of the DataBase file 
-    @return
-        - absolute path of config file
-        - None if the path isn't a file"""
-    path = vmcheckerPaths.db_file
-    if os.path.isfile(path):
-        return path
-    else:
-        return None
-
-
-class VmcheckerPaths(object):
-    """ All paths related to vmchecker. """
-    def __init__(self):
-        pass
-
-    def abs_path(self, relative):
-        return os.path.normpath(os.path.join(self.root, relative))
-
-    @property
-    def root(self):
-        assert 'VMCHECKER_ROOT' in os.environ, (
-            'VMCHECKER_ROOT environment variable not defined')
-        return os.path.abspath(os.environ['VMCHECKER_ROOT'])
-
-    @property
-    def tester_paths(self):
-        """ A list of all the paths relevant to the tester machine."""
-        return [self.dir_queue]
-
-    @property
-    def storer_paths(self):
-        """ A list of all the paths relevant to the storer machine."""
-        return [self.dir_unchecked, self.dir_checked,
-                self.dir_backup, self.dir_tests]
-
-    @property
-    def dir_unchecked(self):
-        """ The absolute path of the unchecked homeworks
-        are kept.
-        This path is valid on the storer machine."""
-        return self.abs_path("unchecked")
-
-    @property
-    def dir_checked(self):
-        """ The absolute path of the checked homeworks
-        are kept.
-        This path is valid on the storer machine."""
-        return self.abs_path("checked")
-
-    @property
-    def dir_tests(self):
-        """ The absolute path of the test archives for the
-        homeworks are kept.
-        This path is valid on the storer machine."""
-        return self.abs_path("tests")
-
-    @property
-    def dir_queue(self):
-        """ The absolute path of the task queue directory.
-        This path is valid on the tester machine."""
-        return self.abs_path("queue")
-
-    @property
-    def dir_backup(self):
-        """ The absolute path of the directory where backups
-        of tasks are kept.
-        This path is valid on the storer machine."""
-        return self.abs_path("back")
-
-    @property
-    def db_file(self):
-        """ The absolute path of the database file """
-        return self.abs_path("vmchecker.db")
-
-    @property
-    def config_file(self):
-        """Returns absolute path for config file 'VMCHECKER_INI'"""
-        path = self.abs_path(VMCHECKER_INI)
-        assert os.path.isfile(path), '%s (%s) is not a file' % (
-            VMCHECKER_INI, path)
-        return path
-
-
-
-vmcheckerPaths = VmcheckerPaths()
diff --git a/bin/queue_manager.py b/bin/queue_manager.py
index a0ded79..fe6ef13 100755
--- a/bin/queue_manager.py
+++ b/bin/queue_manager.py
@@ -35,7 +35,7 @@ def _process_job(path, name):
 def main():
     wm = WatchManager()
     notifier = Notifier(wm, _QueueManager())
-    wm.add_watch(misc.vmcheckerPaths.dir_queue, EventsCodes.ALL_FLAGS['IN_CLOSE_WRITE'])
+    wm.add_watch(vmcheckerpaths.dir_queue(), EventsCodes.ALL_FLAGS['IN_CLOSE_WRITE'])
     notifier.loop(callback=lambda self: self.proc_fun())
 
 
diff --git a/bin/submit.py b/bin/submit.py
index a1af1e5..489a0e6 100755
--- a/bin/submit.py
+++ b/bin/submit.py
@@ -110,14 +110,14 @@ def submit_assignment(assignment_config):
     fd = mkstemp(
             suffix='.zip',
             prefix='%s_%s_%s_' % (course, assignment, user),
-            dir=misc.vmcheckerPaths.dir_unchecked)
+            dir=vmcheckerpaths.dir_unchecked())
     print >>sys.stderr, 'Creating zip package at `%s\'' % fd[1]
 
     # adds the files to
     with os.fdopen(fd[0], 'w+b') as handler:
         zip = ZipFile(handler, 'w')
         zip.write(assignment_config, 'config')   # assignment config
-        zip.write(misc.vmcheckerPaths.config_file, 'global')  # global vmchecker config
+        zip.write(vmcheckerpaths.config_file(), 'global')  # global vmchecker config
         zip.write(archive, 'archive.zip')        # assignment archive
         zip.write(tests, 'tests.zip')            # the archive containing tests
         zip.write(penalty, 'penalty')            # penalty script
@@ -126,7 +126,7 @@ def submit_assignment(assignment_config):
 
     # sends homework to tester
     submit = misc.config().get(assignment, 'Submit')
-    submit = join(misc.vmcheckerPaths.abs_path(submit))
+    submit = join(vmcheckerpaths.abs_path(submit))
     check_call((submit, fd[1]))
 
 
diff --git a/bin/update_db.py b/bin/update_db.py
index 6caea1b..18e61a5 100644
--- a/bin/update_db.py
+++ b/bin/update_db.py
@@ -1,44 +1,22 @@
 #! /usr/bin/env python2.5
+# -*- coding: utf-8 -*-
 
 from __future__ import with_statement
-__author__ = 'Gheorghe Claudiu-Dan, claudiugh at gmail.com'
+
+__author__ = 'Gheorghe Claudiu-Dan <claudiugh at gmail.com>'
 
 import sqlite3
 import os
 import time 
 import stat 
-import misc 
 import logging
 
+import misc 
+import vmcheckerpaths
 
 
-logging.basicConfig(level=logging.DEBUG)
-logger = logging.getLogger("vmchecker.initialise_course")
-
 GRADE_VALUE_FILE = 'nota'
 
-vmchk_root = misc.vmcheckerPaths.root
-db_path = misc.vmcheckerPaths.db_file
-cwd = os.getcwd()
-checked_root = misc.vmcheckerPaths.dir_checked
-
-if not cwd.startswith(checked_root):
-    logger.error("Error: working directory [%s] not in the VMCHECKER_ROOT [%s] subtree." % 
-                 (cwd, checked_root))
-    exit()
-
-if None == db_path:
-    logger.error("Error: DB file [%s] doesn't exist" % db_path)
-    exit()
-    
-db_conn = sqlite3.connect(db_path)
-db_conn.isolation_level = None  # this is for autocommiting updates 
-db_cursor = db_conn.cursor()
-
-##################################################
-#
-#  DB routines  
-# 
 
 def DB_get_hw(hw_name):
     """ Get a homework entry 
@@ -53,18 +31,20 @@ def DB_get_hw(hw_name):
     else:
         return result[0]
 
+
 def DB_save_hw(hw_name):
     """ If the homework identified by (hw_name)  
     exists then update the DB, else insert a new entry """
     global db_cursor
+
     id_hw = DB_get_hw(hw_name)
     if None == id_hw:
         db_cursor.execute('INSERT INTO teme (nume) values (?)', (hw_name,))
         db_cursor.execute('SELECT last_insert_rowid();');
         (id_hw,) = db_cursor.fetchone()
-        return id_hw
-    else:
-        return id_hw
+
+    return id_hw
+
 
 def DB_get_student(student_name):
     """ Get a student entry 
@@ -74,11 +54,12 @@ def DB_get_student(student_name):
     global db_cursor
     db_cursor.execute('SELECT id FROM studenti WHERE nume = ?;', (student_name,))
     result = db_cursor.fetchone()
-    if None == result:
+    if result is None:
         return result
     else:
         return result[0]
 
+
 def DB_save_student(student_name):
     """ If the student identified by (student_name)  
     exists then update the DB, else insert a new entry """
@@ -90,6 +71,7 @@ def DB_save_student(student_name):
         (id_student,) = db_cursor.fetchone()
     return id_student
 
+
 def DB_get_grade(id_hw, id_student):
     """ Get a grade entry 
     @return 
@@ -103,6 +85,7 @@ def DB_get_grade(id_hw, id_student):
     else:
         return result
 
+
 def DB_save_grade(id_hw, id_student, grade, data):
     """ If the grade identified by (id_hw, id_student) 
     exists then update the DB, else insert a new entry """
@@ -113,8 +96,6 @@ def DB_save_grade(id_hw, id_student, grade, data):
     else:       
         db_cursor.execute('UPDATE note set nota = ?, data = ? where id = ?', (grade, data, id_grade))
 
-#        
-#################################################
 
 def update_hws(path):
     """ For each dentry from path, launch the next 
@@ -128,6 +109,7 @@ def update_hws(path):
             #print hw_name
             update_students(path_hw, id_hw)
 
+
 def update_students(path, id_hw):
     """ For each dentry from path, 
     launch the update_grade() routine"""
@@ -140,8 +122,10 @@ def update_students(path, id_hw):
             #print "\t ", student_name,
             update_grade(path_student, id_hw, id_student)
 
+
 def grade_modification_time(grade_filename):
-    return time.strftime("%Y-%m-%d %H-%M-%S", time.gmtime(os.path.getmtime(grade_filename)))
+    return time.strftime(misc.DATE_FORMAT, time.gmtime(os.path.getmtime(grade_filename)))
+
 
 def get_grade_value(grade_filename):
     """ read an integer from the first line of the file """
@@ -150,11 +134,12 @@ def get_grade_value(grade_filename):
             return int(f.readline())
         except ValueError:
             return -1;
+
     
 def update_grade(path, id_hw, id_student):
-    """ Reads the grade's value only if the file containing the
+    """Reads the grade's value only if the file containing the
     value was modified since the last update of the DB for this
-    submission. """
+    submission."""
     grade_filename = os.path.join(path, GRADE_VALUE_FILE)
     if not os.path.exists(grade_filename):
         logger.error("File [%s] for grade value does not exist " % grade_filename)
@@ -168,8 +153,7 @@ def update_grade(path, id_hw, id_student):
             # update information from DB
             DB_save_grade(id_hw, id_student, grade_value, data_modif)
             print path, " UPDATED "
-#    else:
-#        print " "
+
 
 def main():
     # determine the level 
@@ -177,32 +161,50 @@ def main():
     LEVEL_STUDENTI = 1
     LEVEL_GRADE = 2
 
-    path = cwd
+    path = os.getcwd()
     level = LEVEL_HWS
-    while path != checked_root:    
+    while path != vmcheckerpaths.dir_checked():    
         (path, tail) = os.path.split(path)
         level = level + 1
 
     if level == LEVEL_HWS:
-        update_hws(cwd)
+        update_hws(os.getcwd())
     elif level == LEVEL_STUDENTI:
         # get the name for homework
-        (head, nume_hw) = os.path.split(cwd)
+        (head, nume_hw) = os.path.split(os.getcwd())
         # get the id 
         id_hw = DB_save_hw(nume_hw)
-        update_students(cwd, id_hw)
+        update_students(os.getcwd(), id_hw)
     elif level == LEVEL_GRADE:
         # get the  names from the path 
-        (head, nume_student) = os.path.split(cwd)
+        (head, nume_student) = os.path.split(os.getcwd())
         (head, nume_hw) = os.path.split(head)
         # get the DB identifiers 
         id_hw = DB_save_hw(nume_hw)
         id_student = DB_save_student(nume_student)
-        update_grade(cwd, id_hw, id_student)
+        update_grade(os.getcwd(), id_hw, id_student)
 
         db_cursor.close() 
         db_conn.close() 
 
 
 if __name__ == '__main__':
+    logging.basicConfig(level=logging.DEBUG)
+    logger = logging.getLogger("vmchecker.initialise_course")
+
+    if not os.getcwd().startswith(vmcheckerpaths.dir_checked()):
+        logger.error("Error: working directory [%s] not in the VMCHECKER_ROOT [%s] subtree." % 
+                     (os.getcwd(), vmcheckerpaths.dir_checked()))
+        exit()
+
+    if not os.path.isfile(vmcheckerpaths.db_file()):
+        logger.error("Error: DB file [%s] doesn't exist" % db_path)
+        exit()
+
+    # TODO: rename for better encapsulation
+    global db_conn, db_cursor
+    db_conn = sqlite3.connect(db_path)
+    db_conn.isolation_level = None  # this is for autocommiting updates 
+    db_cursor = db_conn.cursor()
+
     main()
diff --git a/bin/view_grades.py b/bin/view_grades.py
index fb7547b..769119f 100755
--- a/bin/view_grades.py
+++ b/bin/view_grades.py
@@ -1,7 +1,9 @@
 #! /usr/bin/env python2.5
+#! /usr/bin/env python2.5
+# -*- coding: utf-8 -*-
+
+"""Generates a HTML table containing the students' grades.
 
-"""
-The script generates a HTML table that contains the grade for each student and for each homework
 The layout can be modified by editing the following CSS elements: 
 
 table#hw-results-table {}           
@@ -10,30 +12,35 @@ table#hw-results-table tr.tr-even {}/* even rows from table */
 table#hw-results-table td.hw-h {}   /* home heading row */
 table#hw-results-table td.st-h {}   /* student heading column */
 table#hw-results-table td.grade {}  /* the grade cell */
-
 """
 
-__author__ = 'Gheorghe Claudiu-Dan, claudiugh at gmail.com'
+__author__ = 'Gheorghe Claudiu-Dan <claudiugh at gmail.com>'
 
 
 import sqlite3
-import misc
 import os
 import urllib
 import logging
 
+
+import misc
+import vmcheckerpaths
+
+
 logging.basicConfig(level=logging.DEBUG)
 logger = logging.getLogger("vmchecker.db_gentest")
 
 
-db_path = misc.vmcheckerPaths.db_file
-if None == db_path:
+db_path = vmcheckerpaths.db_file()
+if not os.path.isfile(db_path):
     logger.error("DB file %s does not exist" % db_path)
     exit()
 
+
 db_conn = sqlite3.connect(db_path)
 db_cursor = db_conn.cursor()
 
+
 def get_db_content():
     """ Retrieve all the information needed from the DB    
     @return
@@ -61,6 +68,7 @@ def get_db_content():
         
     return (results, hws)
 
+
 def href(target, text, title='Click pentru detalii'):
     """ Generate a HTML anchor with target, text, and title attributes
     @return
@@ -68,6 +76,7 @@ def href(target, text, title='Click pentru detalii'):
     """
     return "<a href='%s' title='%s'>%s</a>" % (target, title, text)
 
+
 def cpl_hack(student_name, hw_name, result):
     # TODO(alexandru): replace with something less specifi
     if result == '-1':
@@ -75,6 +84,7 @@ def cpl_hack(student_name, hw_name, result):
     return "<a href=\"Teme/nota.php?user=%s&homework=%s\">%s</a>" % (
         urllib.quote(student_name), urllib.quote(hw_name), result)
 
+
 def gen_html(results, hws):
     # table header 
     html = "<table id='hw-results-table'> <tr> <td > Nume </td> "
@@ -104,6 +114,7 @@ def gen_html(results, hws):
     html += ' </table>'
     return html 
 
+
 def main():
     (results, hws) = get_db_content()
     # send to the stdout all the HTML content 
@@ -111,5 +122,6 @@ def main():
     db_cursor.close()
     db_conn.close()
 
+
 if __name__ == '__main__':
     main()
diff --git a/bin/vmcheckerpaths.py b/bin/vmcheckerpaths.py
new file mode 100644
index 0000000..3bdeccc
--- /dev/null
+++ b/bin/vmcheckerpaths.py
@@ -0,0 +1,80 @@
+# -*- coding: utf-8 -*-
+"""All paths related to vmchecker."""
+
+
+__author__ = 'Lucian Adrian Grijincu <lucian.grijincu at gmail.com>'
+
+
+import os
+
+
+VMCHECKER_INI = 'vmchecker_storer.ini'
+
+
+def abspath(relative):
+    return os.path.normpath(os.path.join(root(), relative))
+
+
+def root():
+    assert 'VMCHECKER_ROOT' in os.environ, (
+            'VMCHECKER_ROOT environment variable not defined')
+    return os.path.abspath(os.environ['VMCHECKER_ROOT'])
+
+
+def tester_paths():
+    """A list of all the paths relevant to the tester machine."""
+    return [dir_queue()]
+
+
+def storer_paths():
+    """A list of all the paths relevant to the storer machine."""
+    return [dir_unchecked(), dir_checked(),
+            dir_backup(), dir_tests()]
+
+
+def dir_unchecked():
+    """The absolute path of the unchecked homeworks.
+
+    This path is valid on the storer machine."""
+    return abspath('unchecked')
+
+
+def dir_checked():
+    """The absolute path of the checked homeworks.
+
+    This path is valid on the storer machine."""
+    return abspath('checked')
+
+
+def dir_tests():
+    """The absolute path of the test archives.
+
+    This path is valid on the storer machine."""
+    return abspath('tests')
+
+
+def dir_queue():
+    """The absolute path of the task queue directory.
+    This path is valid on the tester machine."""
+    return abspath('queue')
+
+
+def dir_backup():
+    """The absolute path of the directory where backups
+    of tasks are kept.
+    This path is valid on the storer machine."""
+    return abspath('back')
+
+
+def db_file():
+    """The absolute path of the database file """
+    return abspath('vmchecker.db')
+
+
+def config_file():
+    """Returns absolute path for config file 'VMCHECKER_INI'"""
+    path = abspath(VMCHECKER_INI)
+    assert os.path.isfile(path), '%s (%s) is not a file' % (
+        VMCHECKER_INI, path)
+    return path
+
-- 
1.6.2



More information about the vmchecker-dev mailing list