Example #1
0
    def get_distribution(self,
                         dist_id,
                         profile_id,
                         build_type,
                         search_cvs=1):

        location = self.find_distribution(dist_id, profile_id, build_type, 1, search_cvs)

        path = self.natify_path(self.module_name)
        if location:
            if location[-4:] == ".rna":
                import archive
                archive.Extract(location)
            else:
                shell.mkdir(os.path.dirname(path))
                shell.cp(location, path)

        cleanup()

        if not os.path.exists(path):
            # FIXME: This error message needs to point to the
            # (so far nonexistant) documentation
            outmsg.send("distribution=\"%s\" not found." % ( self.module_name ))

        return [ self.module_name ]
Example #2
0
def copyIntoStudentDir(assignment: Assignment, studentDir: str):
    for src in assignment.itemsToCopy:
        target = shell.pjoin(studentDir, shell.basename(src))
        if not fileSystemItemEquals(src, target):
            print(f'Copying {src} to {studentDir} ...')
            moveToBackup(target)
            shell.cp(src, studentDir)
Example #3
0
def copyFileIfNotExists(srcDir, path, targetDir):
    srcPath = shell.pjoin(srcDir, path)
    if not shell.isFile(srcPath):
        raise IOError(f'{srcPath} must be a file')
    tgtPath = shell.pjoin(targetDir, path)
    if shell.isDir(tgtPath):
        raise IOError(f'{tgtPath} must not be a directory')
    shell.mkdir(shell.dirname(tgtPath), createParents=True)
    if shell.isFile(tgtPath):
        if not hasSameContent(srcPath, tgtPath):
            raise IOError(f'Target file {tgtPath} already exists with content different than in {srcPath}')
    else:
        shell.cp(srcPath, tgtPath)
Example #4
0
def copyTemplate(studentDir: str, studentId: str, path: str, copy: bool):
    (b, e) = shell.splitExt(shell.basename(path))
    for t in ['_TEMPLATE_', 'TEMPLATE_', '_TEMPLATE', 'TEMPLATE']:
        b = b.replace(t, '')
    b = b + '_' + studentId
    newPath = shell.pjoin(studentDir, b) + e
    if not shell.isFile(newPath):
        if copy:
            note(f"Copying template {path} to {newPath}")
            shell.cp(path, newPath)
            spreadsheet.replaceData(newPath, 'ID', 'STUDENT_ID', studentId)
        else:
            return None
    return newPath
Example #5
0
    def download_distribution(self, dist_id, profile_id, build_type):
        """Download the approperiate distribution into ./distribution so that it can be easily
        found by find_distribution_filesystem"""
        location = self.find_distribution(dist_id, profile_id, build_type, 0)

        if location:
            if string.count(location, tmpdir()):
                p = string.index(location, tmpdir())
                dest = location[:p] + location[p + len(tmpdir()) + 1:]
                shell.mkdir(os.path.dirname(dest))
                shell.cp(location, dest)
        else:
            outmsg.send("distribution=\"%s\" not found." % (self.module_name))

        cleanup()
Example #6
0
def spreadsheetTest(action,
                    check=None,
                    path='test-data/bewertung.xlsx',
                    sheetName=None):
    with shell.tempDir(delete=False, dir='.') as d:
        name = f'test_{uuid.uuid4()}.xlsx'
        p = shell.pjoin(d, name)
        shell.cp(path, p)
        x = action(p)
        if check:
            wb = exc.load_workbook(filename=p)
            if sheetName:
                sheet = wb[sheetName]
            else:
                sheet = wb.active
            check(sheet)
        return x
Example #7
0
    def download_distribution(self,
                              dist_id,
                              profile_id,
                              build_type):
        """Download the approperiate distribution into ./distribution so that it can be easily
        found by find_distribution_filesystem"""
        location = self.find_distribution(dist_id, profile_id, build_type, 0)

        if location:
            if string.count(location, tmpdir()):
                p = string.index(location,tmpdir())
                dest = location[:p]+location[p+len(tmpdir())+1:]
                shell.mkdir(os.path.dirname(dest))
                shell.cp(location, dest)
        else:
            outmsg.send("distribution=\"%s\" not found." % ( self.module_name ))

        cleanup()
Example #8
0
    def get_distribution(self, dist_id, profile_id, build_type, search_cvs=1):

        location = self.find_distribution(dist_id, profile_id, build_type, 1,
                                          search_cvs)

        path = self.natify_path(self.module_name)
        if location:
            if location[-4:] == ".rna":
                import archive
                archive.Extract(location)
            else:
                shell.mkdir(os.path.dirname(path))
                shell.cp(location, path)

        cleanup()

        if not os.path.exists(path):
            # FIXME: This error message needs to point to the
            # (so far nonexistant) documentation
            outmsg.send("distribution=\"%s\" not found." % (self.module_name))

        return [self.module_name]
Example #9
0
    def checkin(self, file, new_name, root, path, tag):
        print "Processing %s" % file
        if not os.path.exists(file):
            print "No such file or directory!"
            return
        setup()
        cvsdir=os.path.join(tmpdir(),"CVS")
        shell.mkdir(cvsdir)
        open(os.path.join(cvsdir,"Root"),"w").write(root+"\n")
        open(os.path.join(cvsdir,"Repository"),"w").write(path+"\n")
        open(os.path.join(cvsdir,"Entries"),"w").write("")
        if tag:
            open(os.path.join(cvsdir,"Tag"),"w").write("T"+tag+os.linesep)

        self.run('cvs update "%s"' % new_name, 1)
        new_path=os.path.join(tmpdir(),new_name)
        exists=os.path.exists(new_path)
        shell.cp(file, new_path)
        if not exists:
            self.run('cvs add -kb "%s"' % new_name, 1)
            
        self.run('cvs commit -m "distribution checkin" "%s"' % new_name)
        cleanup()
Example #10
0
    def checkin(self, file, new_name, root, path, tag):
        print "Processing %s" % file
        if not os.path.exists(file):
            print "No such file or directory!"
            return
        setup()
        cvsdir = os.path.join(tmpdir(), "CVS")
        shell.mkdir(cvsdir)
        open(os.path.join(cvsdir, "Root"), "w").write(root + "\n")
        open(os.path.join(cvsdir, "Repository"), "w").write(path + "\n")
        open(os.path.join(cvsdir, "Entries"), "w").write("")
        if tag:
            open(os.path.join(cvsdir, "Tag"),
                 "w").write("T" + tag + os.linesep)

        self.run('cvs update "%s"' % new_name, 1)
        new_path = os.path.join(tmpdir(), new_name)
        exists = os.path.exists(new_path)
        shell.cp(file, new_path)
        if not exists:
            self.run('cvs add -kb "%s"' % new_name, 1)

        self.run('cvs commit -m "distribution checkin" "%s"' % new_name)
        cleanup()
Example #11
0
    def update(self, tag, module_list, az = None, timestamp = None, nonrecursive = 0, dir = None):

        ### FIXME:
        ### test this!

        if dir:
            odir=os.getcwd()
            try:
                os.chdir(dir)
                ret=self.checkout(tag, module_list, az, timestamp, nonrecursive)
            finally:
                os.chdir(odir)

            return ret

        if az:
            odir=os.getcwd()
            shell.mkdir("cvs_temp")
            os.chdir("cvs_temp")
            self.checkout(tag,module_list, None, timestamp, nonrecursive)
            os.chdir(odir)
            for m in module_list:
                shell.cp(os.path.join(odir, "cvs_temp", m),
                         os.path.join(odir, az))

            shell.rm("cvs_temp")
            return
        
        if nonrecursive:
            e = err.Error()
            e.Set("Nonrecursive not supported by MacCVS")
            raise err.error, e
        
        session_name = self.cvs_session_path[1:-1]
        session_name = os.path.basename(session_name)

        script = ascript.CreateAppleScript(
            'tell application %s' % (self.cvs_path),
            '  activate',
            '  open alias %s' % (self.cvs_session_path),
            '  set thesession to session named "%s"' % (session_name),
            '  set local root of thesession to alias "%s"' % (os.getcwd()),
            '  with timeout of 99999 seconds')

        for module in module_list:
            cmd = 'check out thesession module "%s"' % (module)
            if tag:
                cmd = cmd +' revision "%s"' % (tag)

            if timestamp:
                cmd = cmd +' date "%s"' % (timestamp)

            script.Append(cmd)

        script.Append(
            '  end timeout',
            '  quit',
            'end tell')

        if self.script_save_path == '':
            result = script.CompileAndExecute()
        else:
            script.CompileAndSave(self.script_save_path)

            launch_script = ascript.CreateAppleScript(
                'set scriptobj to (load script file "%s")' % (
                self.script_save_path),
                'tell scriptobj',
                '  run',
                'end tell')

            result = launch_script.CompileAndExecute()

        if result and result != '':
            outmsg.error('cvs checkout error %s' % (result))
Example #12
0
    def __init__(self, dir="."):
        self.dir=dir
        self.new_cvs_dir=None
        self.cvsdir = os.path.join(dir, "CVS")
        subdirs=[]
        entries=[]
        self.use_fake=0


        try:
            files=os.listdir(dir)
        except:
            return

        for e in files:
            if e in ["CVS"]:
                continue

            path = os.path.join(dir, e)
            if os.path.isdir(path):
                ndir = MagicFixDir(path)
                if ndir.cvsdir:
                    subdirs.append(ndir)

        if not os.path.isdir(self.cvsdir):
            if subdirs:
                self.new_cvs_dir=1

                q=subdirs[0].mkparent()
                for n in subdirs:
                    entries.append(n.get_entry())
                    #print "==========="
                    #print n.cvsdir
                    #print n.mkparent()
                    #print q
                    #print "==========="
                    if n.use_fake or n.mkparent() != q:
                        self.use_fake=1

                shell.mkdir(self.cvsdir)
                if self.use_fake:
                    print "Adding faux CVS dir: %s" % self.cvsdir

                    faux=os.path.join(os.environ["BUILD_ROOT"],"lib","faux-cvs","CVS")
                    if os.path.isdir(faux):
                        shell.mkdir(self.cvsdir)
                        shell.cp(os.path.join(faux,"Root"), os.path.join(self.cvsdir,"Root"))
                        shell.cp(os.path.join(faux,"Repository"),
                                 os.path.join(self.cvsdir,"Repository"))
                    else:
                        print "Faux cvs dir missing, skipping"
                        self.cvsdir=None
                        return
                else:
                    print "Adding PARENT CVS dir: %s" % self.cvsdir
                    shell.mkdir(self.cvsdir)
                    open(os.path.join(self.cvsdir,"Root"),"w").write(q[0])
                    open(os.path.join(self.cvsdir,"Repository"),"w").write(q[1])
                    if q[2]:
                        open(os.path.join(self.cvsdir,"Tag"),"w").write(q[2])
                    
                open(os.path.join(self.cvsdir,"Entries"),"w").write(string.join(entries,""))
            else:
                self.cvsdir=None
        else:
            for n in subdirs:
                if n.is_new():
                    entries.append(n.get_entry())

            if entries:
                print "Adding CVS entries in %s" % self.cvsdir
                e=open(os.path.join(self.cvsdir,"Entries"),"a")
                e.write(string.join(entries,""))
Example #13
0
 def cp(self, source_path, destination_path):
     native_source_path = self.native_path(source_path)
     native_destination_path = self.native_path(destination_path)
     shell.cp(native_source_path, native_destination_path)
Example #14
0
def assertFileNotEmpty(path):
    assertExists(path)
    s = shell.readBinaryFile(path, )
    if not s:
        abort(f'File {path} is empty')


def assertEqual(expected, given):
    if expected != given:
        abort(f'Expected {expected}, given {given}')


with shell.tempDir(onException=False) as tmp:
    print(f'tmp={tmp}')
    shell.cp(shell.pjoin(topDir, 'test-data'), tmp)
    with shell.workingDir(shell.pjoin(tmp, 'test-data/submissions')):

        print('### import ###')
        shell.run([checkAssignments, 'import', '../rating-moodle.csv'])
        assertExists('rating.xlsx')

        print('### unzip ###')
        barFoo = 'Bar Foo_1234_assignsubmission_file_/'
        shell.run([checkAssignments, 'unzip'])
        assertExists(barFoo + 'assignment_01.py')

        print('### checkFilenames ###')
        shell.run([checkAssignments, 'checkFilenames'])
        shell.run([checkAssignments, 'fixFilenames'])
Example #15
0
    def __init__(self, dir="."):
        self.dir = dir
        self.new_cvs_dir = None
        self.cvsdir = os.path.join(dir, "CVS")
        subdirs = []
        entries = []
        self.use_fake = 0

        try:
            files = os.listdir(dir)
        except:
            return

        for e in files:
            if e in ["CVS"]:
                continue

            path = os.path.join(dir, e)
            if os.path.isdir(path):
                ndir = MagicFixDir(path)
                if ndir.cvsdir:
                    subdirs.append(ndir)

        if not os.path.isdir(self.cvsdir):
            if subdirs:
                self.new_cvs_dir = 1

                q = subdirs[0].mkparent()
                for n in subdirs:
                    entries.append(n.get_entry())
                    #print "==========="
                    #print n.cvsdir
                    #print n.mkparent()
                    #print q
                    #print "==========="
                    if n.use_fake or n.mkparent() != q:
                        self.use_fake = 1

                shell.mkdir(self.cvsdir)
                if self.use_fake:
                    print "Adding faux CVS dir: %s" % self.cvsdir

                    faux = os.path.join(os.environ["BUILD_ROOT"], "lib",
                                        "faux-cvs", "CVS")
                    if os.path.isdir(faux):
                        shell.mkdir(self.cvsdir)
                        shell.cp(os.path.join(faux, "Root"),
                                 os.path.join(self.cvsdir, "Root"))
                        shell.cp(os.path.join(faux, "Repository"),
                                 os.path.join(self.cvsdir, "Repository"))
                    else:
                        print "Faux cvs dir missing, skipping"
                        self.cvsdir = None
                        return
                else:
                    print "Adding PARENT CVS dir: %s" % self.cvsdir
                    shell.mkdir(self.cvsdir)
                    open(os.path.join(self.cvsdir, "Root"), "w").write(q[0])
                    open(os.path.join(self.cvsdir, "Repository"),
                         "w").write(q[1])
                    if q[2]:
                        open(os.path.join(self.cvsdir, "Tag"), "w").write(q[2])

                open(os.path.join(self.cvsdir, "Entries"),
                     "w").write(string.join(entries, ""))
            else:
                self.cvsdir = None
        else:
            for n in subdirs:
                if n.is_new():
                    entries.append(n.get_entry())

            if entries:
                print "Adding CVS entries in %s" % self.cvsdir
                e = open(os.path.join(self.cvsdir, "Entries"), "a")
                e.write(string.join(entries, ""))
Example #16
0
    def update(self,
               tag,
               module_list,
               az=None,
               timestamp=None,
               nonrecursive=0,
               dir=None):

        ### FIXME:
        ### test this!

        if dir:
            odir = os.getcwd()
            try:
                os.chdir(dir)
                ret = self.checkout(tag, module_list, az, timestamp,
                                    nonrecursive)
            finally:
                os.chdir(odir)

            return ret

        if az:
            odir = os.getcwd()
            shell.mkdir("cvs_temp")
            os.chdir("cvs_temp")
            self.checkout(tag, module_list, None, timestamp, nonrecursive)
            os.chdir(odir)
            for m in module_list:
                shell.cp(os.path.join(odir, "cvs_temp", m),
                         os.path.join(odir, az))

            shell.rm("cvs_temp")
            return

        if nonrecursive:
            e = err.Error()
            e.Set("Nonrecursive not supported by MacCVS")
            raise err.error, e

        session_name = self.cvs_session_path[1:-1]
        session_name = os.path.basename(session_name)

        script = ascript.CreateAppleScript(
            'tell application %s' % (self.cvs_path), '  activate',
            '  open alias %s' % (self.cvs_session_path),
            '  set thesession to session named "%s"' % (session_name),
            '  set local root of thesession to alias "%s"' % (os.getcwd()),
            '  with timeout of 99999 seconds')

        for module in module_list:
            cmd = 'check out thesession module "%s"' % (module)
            if tag:
                cmd = cmd + ' revision "%s"' % (tag)

            if timestamp:
                cmd = cmd + ' date "%s"' % (timestamp)

            script.Append(cmd)

        script.Append('  end timeout', '  quit', 'end tell')

        if self.script_save_path == '':
            result = script.CompileAndExecute()
        else:
            script.CompileAndSave(self.script_save_path)

            launch_script = ascript.CreateAppleScript(
                'set scriptobj to (load script file "%s")' %
                (self.script_save_path), 'tell scriptobj', '  run', 'end tell')

            result = launch_script.CompileAndExecute()

        if result and result != '':
            outmsg.error('cvs checkout error %s' % (result))
Example #17
0
 def cp(self, source_path, destination_path):
     native_source_path = self.native_path(source_path)
     native_destination_path = self.native_path(destination_path)
     shell.cp(native_source_path, native_destination_path)
Example #18
0
checkAssignments = shell.abspath(shell.pjoin(topDir, 'check-assignments'))
if sys.platform == 'win32':
    checkAssignments = checkAssignments + ".bat"

def abort(msg):
    sys.stderr.write(msg + '\n')
    sys.exit(1)

def assertExists(path):
    if not shell.isFile(path):
        abort(f'File {path} does not exist')

with shell.tempDir(onException=False) as tmp:
    print(f'tmp={tmp}')
    shell.cp(shell.pjoin(topDir, 'test-data'), tmp)
    with shell.workingDir(shell.pjoin(tmp, 'test-data/submissions')):

        print('### import ###')
        shell.run([checkAssignments, 'import', '../rating-moodle.csv'])
        assertExists('rating.xlsx')

        print('### unzip ###')
        barFoo = 'Bar Foo_1234_assignsubmission_file_/'
        shell.run([checkAssignments, 'unzip'])
        assertExists(barFoo + 'assignment_01.py')

        print('### addComment ###')
        shell.run([checkAssignments, 'addComment'])
        assertExists(barFoo + 'COMMENTS.txt')