Esempio n. 1
0
def create_course(config_file, course):
    """
    Create the course 'course'.

    @type config_file: string
    @param config_file: path to the configuration file
    @type course: string
    @param course: course name
    @rtype: None
    @raise ValueError: The course already exists.

    """
    config_obj = ProjectGlobal(config_file)
    if not config_obj.config.has_key(course):
        course = ProjectAdminCourse(config_file, course)
        user = raw_input("Username [usually your UNIX login]: ")
        directory = raw_input("Full path to the course directory: ")
        group = raw_input("Group: ")
        try:
            try:
                os.makedirs(directory) # We could supply the mode here, but it might get
                                       #ignored on some systems. We'll do it here instead
            except OSError, e:
                # We don't want to abort of the directory already exists
                if e.errno == 17:
                    print e
                    print 'Continuing'
                else:
                    sys.exit(e)
            os.chmod(directory, 0755)
            chown(directory, user, group)
            os.chmod(config_file, 0644)
            chown(config_file, user, group)
        except OSError, e:
            print e
Esempio n. 2
0
def create_project(config_file, course, project):
    """
    Create the project 'project'.

    @type config_file: string
    @param config_file: path to the configuration file
    @type course: string
    @param course: course name
    @type project: string
    @param project project name
    @rtype: None

    """
    project_obj = ProjectProject(config_file, course, project)
    user = project_obj.course['user']
    group = project_obj.course['group']
    directory = project_obj.project['directory']
    os.makedirs(directory)
    if project_obj.course['group_managed']:
        chmod(directory, 0773)
        chgrp(directory, group)
    else:
        chmod(directory, 0733)
        chown(directory, user, group)
    description = raw_input("[Optional] Project description: ")
    project_obj.write(True, description)
    project_obj.add_manager(whoami)
Esempio n. 3
0
def create_project(config_file, course, project):
    """
    Create the project 'project'.

    @type config_file: string
    @param config_file: path to the configuration file
    @type course: string
    @param course: course name
    @type project: string
    @param project project name
    @rtype: None

    """
    project_obj = ProjectProject(config_file, course, project)
    user = project_obj.course['user']
    group = project_obj.course['group']
    directory = project_obj.project['directory']
    os.makedirs(directory)
    if project_obj.course['group_managed']:
        chmod(directory, 0773)
        chgrp(directory, group)
    else:
        chmod(directory, 0733)
        chown(directory, user, group)
    description = raw_input("[Optional] Project description: ")
    project_obj.write(True, description)
    project_obj.add_manager(whoami)
Esempio n. 4
0
def archive_course(config_file, course, ret_path=False):
    """
    Archive the course in .tar.gz format.

    @type config_file: string
    @param config_file: path to the configuration file
    @type course: string
    @param course: course name
    @type ret_path: bool
    @param ret_path: Do we return the archive's path?
    @rtype: string
    @return: Path to the archive.
    @raise ValueError: The user enters anything but 'YES' at the prompt.
    @raise ValueError: The course does not exist.

    """
    config_obj = ProjectGlobal(config_file)
    if config_obj.config.has_key(course):
        config_obj = ProjectAdminCourse(config_file, course)
        if raw_input("If you really want to archive this course and erase it "+
                "from the configuration file, enter 'yes' in capital " +
                "letters: ") == 'YES':
            archive_path = os.path.normpath(os.path.join(
                    config_obj.course['directory'],
                    os.pardir,
                    course + '-' + str(datetime.datetime.now().year) +
                             '.tar.gz'))
            tar = tarfile.open(archive_path, 'w:gz')
            tar.add(config_obj.course['directory'], course + '-' +
                    str(datetime.datetime.now().year))
            tar.close()
            if config_obj.course['group_managed']:
                os.chmod(archive_path, 0660)
            else:
                os.chmod(archive_path, 0600)
            chown(archive_path, config_obj.course['user'], config_obj.course['group'])
            shutil.rmtree(config_obj.course['directory'], ignore_errors=True)
            del config_obj.config[course]
            # We need to check that Global has the key 'default', otherwise we
            # get a KeyError if it doesn't.
            if ((config_obj.config['Global'].has_key('default')) and
                    (config_obj.config['Global']['default'] == course)):
                config_obj.config['Global']['default'] = ''
            config_obj.config.write()
            if ret_path:
                return archive_path
        else:
            raise ValueError("Aborting and keeping course %s unarchived" %
                    course)
Esempio n. 5
0
                if e.errno == 17:
                    print e
                    print 'Continuing'
                else:
                    sys.exit(e)
            os.chmod(directory, 0755)
            chown(directory, user, group)
            os.chmod(config_file, 0644)
            chown(config_file, user, group)
        except OSError, e:
            print e
        course.write(user, directory, group)
        # We want to set the default course for the per course config.
        global_course_conf = ProjectGlobal(course.course['projlist'])
        global_course_conf.set_default(course.course.name)
        chown(course.course['projlist'], user, group)
        os.chmod(course.course['projlist'], 0644)
    else:
        raise ValueError ('The course %s already exists, aborting' % course)

def delete_course(config_file, course):
    """
    Delete the course 'course'.

    @type config_file: string
    @param config_file: path to the configuration file
    @type course: string
    @param course: course name
    @rtype: None
    @raise ValueError: The user enters anything but 'YES' at the prompt.
    @raise ValueError: The course does not exist.
Esempio n. 6
0
     except KeyError, e:
         print "Group does not exist. Please try again."
     else:
         break
 try:
     try:
         os.makedirs(directory) # We could supply the mode here, but it might get
                                #ignored on some systems. We'll do it here instead
     except OSError, e:
         # We don't want to abort of the directory already exists
         if e.errno == errno.EEXIST:
             print e
             print 'Continuing'
         else:
             sys.exit(e)
     chown(directory, user, group)
     chown(config_file, user, group)
     if group_managed:
         os.chmod(directory, 0775)
     else:
         os.chmod(directory, 0755)
         print "Please make sure the account %s" % user +\
               " is a member of the group %s." % group
 except OSError, e:
     print e
 course.write(user, directory, group, group_managed)
 # We want to set the default course for the per course config.
 global_course_conf = ProjectGlobal(course.course['projlist'])
 global_course_conf.set_default(course.course.name)
 chown(course.course['projlist'], user, group)
 if group_managed: