def checkSpec(spec): # This runs after directory check, so we can try to load the local spec file. try: localSpec = SpecVerifier.load_verified() except: print("Problem finding local spec file. Aborting.") return False if ( localSpec["name"] == spec["name"] and localSpec["publicCode"] == spec["publicCode"] ): return True else: print( "Checking name and public-code in local-spec and server-spec. They disagree. Aborting." ) return False
def __init__(self, db, masterToken): log.debug("Initialising server") try: self.testSpec = SpecVerifier.load_verified() log.info("existing spec loaded") except FileNotFoundError: self.testSpec = None log.error("spec file not found -- use 'plom-build' to create one") raise self.authority = Authority(masterToken) self.DB = db self.API = serverAPI self.Version = __version__ print( "Server launching with masterToken = '{}' {}".format( self.authority.get_master_token(), type(self.authority.get_master_token()), ) ) self.tempDirectory = tempfile.TemporaryDirectory() # Give directory correct permissions. subprocess.check_call(["chmod", "o-r", self.tempDirectory.name]) self.load_users()
def parseAndVerifySpecification(fname): os.makedirs(specdir, exist_ok=True) os.makedirs("sourceVersions", exist_ok=True) print('Parsing and verifying the specification "{}"'.format(fname)) if not os.path.isfile(fname): print('Cannot find "{}" - try "plom-build new"?'.format(fname)) exit(1) sv = SpecVerifier.from_toml_file(fname) sv.verifySpec() sv.checkCodes() sv.saveVerifiedSpec(verbose=True) print( ">>> Note <<<\n" "Before proceeding further, you will need to start the server." '\nSee "plom-server --help" for more information on how to get the server up and running.\n' ) spec = SpecVerifier.load_verified() if spec["numberToName"] > 0: print( ">>> Note <<<\n" 'Your spec indicates that you wish to print named papers.\nWhen the server is running, please process your class list using "plom-build class ".\n' )
def main(use_hex, digits, salt=None): """Make the secret codes and the return-code webpage. args: use_hex (bool): use random hex digits, otherwise an integer without leading zeros. digits (int): length of secret code. salt (str): instead of random, hash from student ID salted with this string. Defaults to None, which means do not do this, use random secret codes. """ # TODO: another case of filesystem access of spec spec = SpecVerifier.load_verified() shortname = spec["name"] longname = html.escape(spec["longName"]) codedReturnDir = Path("codedReturn") reassembles = ["reassembled", "reassembled_ID_but_not_marked"] if os.path.isdir(reassembles[0]) and os.path.isdir(reassembles[1]): print('You have more than one "reassembled*" directory:') print(" decide what you trying to do and run me again.") sys.exit(2) elif os.path.isdir(reassembles[0]): fromdir = reassembles[0] elif os.path.isdir(reassembles[1]): fromdir = reassembles[1] else: print("I cannot find any of the dirs: " + ", ".join(reassembles)) print(" Have you called the `reassemble` command yet?") sys.exit(3) print('We will take pdf files from "{0}".'.format(fromdir)) if codedReturnDir.exists() or os.path.exists("return_codes.csv"): print( 'Directory "{}" and/or "return_codes.csv" already exist:\n' " if you want to re-run this script, delete them first.".format( codedReturnDir ) ) sys.exit(4) os.makedirs(codedReturnDir) print("Generating return codes spreadsheet...") if salt: print('Salt string "{}" can reproduce these return codes'.format(salt)) else: print("These return codes will be random and non-reproducible".format(salt)) sns = csv_add_return_codes( CSVFilename, "return_codes.csv", "StudentID", use_hex, digits, salt ) print('The return codes are in "return_codes.csv"') numfiles = do_renaming(fromdir, codedReturnDir, sns) if numfiles > 0: print("Copied (and renamed) {0} files".format(numfiles)) else: print('no pdf files in "{0}"? Stopping!'.format(fromdir)) sys.exit(5) print("Adding index.html file") from .html_view_test_template import htmlsrc htmlsrc = htmlsrc.replace("__COURSENAME__", longname) htmlsrc = htmlsrc.replace("__TESTNAME__", shortname) htmlsrc = htmlsrc.replace("__CODE_LENGTH__", str(digits)) htmlsrc = htmlsrc.replace("__SID_LENGTH__", str(StudentIDLength)) with open(codedReturnDir / "index.html", "w") as htmlfile: htmlfile.write(htmlsrc) print("All done! Next tasks:") print(' * Copy "{}" to your webserver'.format(codedReturnDir)) print(' * Privately communicate info from "return_codes.csv"') print(" - E.g., see `contrib/plom-return_codes_to_canvas_csv.py`") print(" * Read docs about the security implications of all this.")
__copyright__ = "Copyright (C) 2019-2020 Colin B. Macdonald and others" __credits__ = ["The Plom Project Developers"] __license__ = "AGPL-3.0-or-later" import os import sys import shutil from plom import SpecVerifier from plom.finish import CSVFilename archivename = "{COURSE}_{YEAR}{TERM}_{SHORTNAME}" if __name__ == "__main__": spec = SpecVerifier.load_verified() basename = spec["name"] archivename = archivename.replace("{SHORTNAME}", basename) print("\n\nTODO: THIS SCRIPT NEEDS RETHINKING FOR 0.4!\n\n") # TODO: someday we can get this from spec file? # https://gitlab.com/plom/plom/issues/94 if not len(sys.argv) == 4: print("ERROR: Incorrect command line...") print(__doc__) sys.exit(1) archivename = archivename.replace("{COURSE}", sys.argv[1]) archivename = archivename.replace("{YEAR}", sys.argv[2]) archivename = archivename.replace("{TERM}", sys.argv[3])