module automation_students.projects_repository#

Inheritance diagram of ensae_teaching_cs.automation_students.projects_repository

Short summary#

module ensae_teaching_cs.automation_students.projects_repository

Some automation helpers to grab mails from students about their projects.

source on GitHub

Classes#

class

truncated documentation

ProjectsRepository

Handle a repository of students projects. See example Récupérer des mails d’étudiants en pièce jointe (1:1). …

Properties#

property

truncated documentation

Groups

Returns all available groups in the repository.

Location

Static Methods#

staticmethod

truncated documentation

create_folders_from_dataframe

Creates a series of folders for groups of students.

get_regex

Retrieves data from file suivi.rst using a regular expression.

match_mail

Tries to match a name among a list of mails.

match_mails

Tries to match a series of names among a list of mails.

Methods#

method

truncated documentation

__init__

Location of the repository.

convert_files

Converts all notebooks and python scripts into HTML for a group.

dump_group_mails

Enumerates all mails sent by or sent to a given group.

enumerate_group_files

Enumerates all files in a group.

enumerate_group_mails

Enumerates all mails sent by or sent to a given group.

get_emails

Retrieves student emails from file suivi.rst.

get_group_location

Returns the local folder associated to a group.

get_sections

Extracts sections from a filename used to follow a group of students.

get_videos

Retrieves student emails from file suivi.rst.

list_mails

Returns the number of mails of a group.

remove_group

Removes a group.

unzip_convert

Unzips files and convert notebooks into HTML.

unzip_files

Unzips files and convert notebooks into HTML.

write_run_command

Writes a command script to run a server for this local content. The server runs the javascripts fetching for local …

write_summary

Produces a summary and uses a Jinja2 template.

zip_group

Zips a group.

Documentation#

Some automation helpers to grab mails from students about their projects.

source on GitHub

class ensae_teaching_cs.automation_students.projects_repository.ProjectsRepository(location, suivi='suivi.rst', fLOG=<function noLOG>)#

Bases : object

Handle a repository of students projects. See example Récupérer des mails d’étudiants en pièce jointe (1:1).

source on GitHub

Location of the repository.

Paramètres:
  • location – location of the repository

  • suivi – name of the file gathering information about each project

source on GitHub

property Groups#

Returns all available groups in the repository.

source on GitHub

property Location#
Renvoie:

location of the repository

source on GitHub

exception MailNotFound#

Bases : Exception

Raises an exception if mail not found.

source on GitHub

__init__(location, suivi='suivi.rst', fLOG=<function noLOG>)#

Location of the repository.

Paramètres:
  • location – location of the repository

  • suivi – name of the file gathering information about each project

source on GitHub

_default_template_summary = '<?xml version="1.0" encoding="utf-8"?>\n<head>\n<meta http-equiv="content-type" content="text/html; charset=utf-8" />\n</head>\n<body>\n<html>\n<head>\n<title>{{ title }}</title>\n<link rel="stylesheet" type="text/css" href="{{ css }}">\n</head>\n<body>\n<h1>{{ title }}</h1>\n<ol type="1">\n{% for ps in groups %}\n    <li><a href="{{ ps["link"] }}">{{ ps["group"] }}</a><small><i>\n        {{ ps["nb"] }} files - {{ format_size(ps["size"]) }} -\n        {% if len(ps["emails"]) > 0 %}\n        last mail {{ ps["emails"][-1]["date"] }} ---{% else %}\n        No mail found. {% endif %}\n        {{ len(ps["attachments"]) }} attachments</i></small>\n    {% if len(ps["attachments"]) + len(ps["links"]) > 0 %}\n        <ul>\n        {% for day, att, data in ps["attachments"] %}\n            <li>att: {{ day }} - <a href="{{ att }}">{{ os.path.split(att)[-1] }}</a></li>\n        {% endfor %}\n        {% for date, from_, url, domain, last in ps["links"] %}\n            <li>link: {{ date }} <a href="{{ url }}">{{ domain }} // {{ last }}</a> from {{ from_ }}</li>\n        {% endfor %}\n        </ul>\n    {% endif %}\n    {% if len(ps["created_files"]) > 0 %}\n        <ul>\n        {% for name, relpath, size in ps["created_files"] %}\n            <li>added: <a href="{{ relpath }}">{{ name }}</a> {{ size }}</li>\n        {% endfor %}\n        </ul>\n    {% endif %}\n    </li>\n{% endfor %}\n</ol>\n</body>\n</html>\n'#
_email_regex = re.compile('[*] *e?mails? *: *([^*+\\n]+)')#
_gitlab_regex = re.compile('[*] *gitlab *: *([^*+\\n]+[.]git)')#
_known_strings = ['xavierdupre.fr', 'doodle', 'ensaenotebook', 'teralab', 'outlook.com', 'gohlke', 'support.google', 'help.github', 'api.jcdecaux']#
_regex_split = re.compile('[-;,. @]')#
_video_regex = re.compile('[*] *videos? *: *([^*\\n]+)')#
convert_files(group)#

Converts all notebooks and python scripts into HTML for a group.

Paramètres:

group – group name

Renvoie:

list of new files

source on GitHub

static create_folders_from_dataframe(df, root, report='suivi.rst', col_student=None, col_group='Groupe', col_subject='Sujet', col_mail='mail', overwrite=False, email_function=None, must_have_email=True, skip_if_nomail=False, skip_names=None, fLOG=<function noLOG>)#

Creates a series of folders for groups of students.

Paramètres:
  • root – where to create the folders

  • col_student – column which contains the student name (firt name + last name), equal to col_mail if None

  • col_group – index of the group (it can be None if each student is a group)

  • col_subject – column which contains the subject

  • col_mail – if there is a column which contains the mail in the input dataframe

  • df – DataFrame

  • email_function – function which infers email from first and last names, see below

  • report – report file

  • overwrite – if False, skip if the report already exists

  • must_have_email – if True, raises an exception if no mail is found

  • skip_if_nomail – skip a name if no mail is found

  • skip_names – less checking for a given set of names

  • fLOG – logging function

Renvoie:

list of creates folders

The function email_function has the following signature:

def email_function(names):
    # part of a names is a list of tokens
    # ...
    return list of mails, skip=boolean

The boolean tells the function to skip this group. email_function can be a list of mails. In that case, this function is replaced by match_mails.

source on GitHub

dump_group_mails(renderer, group, mailbox, subfolder, date=None, skip_function=None, max_dest=5, filename='index_mails.html', overwrite=False, skip_if_empty=False, convert_files=False)#

Enumerates all mails sent by or sent to a given group.

Paramètres:
  • renderer – instance of class EmailMessageListRenderer

  • group – group

  • mailbox – mailbox (see pymmails)

  • subfolder – which subfolder of the mailbox to look into

  • date – date

  • skip_function – if not None, use this function on the header/body to avoid loading the entire message (and skip it)

  • max_dest – maximum number of receivers

  • filename – filename which gathers a link to every mail

  • overwrite – overwrite

  • skip_if_empty – skip if no mail?

  • convert_files – unzip and convert

Renvoie:

list of files (see EmailMessageListRenderer.write)

zip, gz, rar, 7z can be uncompressed. It then convert .py and .ipynb into html.

source on GitHub

enumerate_group_files(group)#

Enumerates all files in a group.

Paramètres:

group – group

Renvoie:

iterator on files

source on GitHub

enumerate_group_mails(group, mailbox, subfolder, date=None, skip_function=None, max_dest=5)#

Enumerates all mails sent by or sent to a given group.

Paramètres:
  • group – group (if None, goes through all mails)

  • mailbox

    mailbox (see pymmails)

  • subfolder – which subfolder of the mailbox to look into

  • date – date

  • skip_function – if not None, use this function on the header/body to avoid loading the entire message (and skip it)

  • max_dest – maximum number of receivers

Renvoie:

iterator on mails

source on GitHub

get_emails(group, skip_if_empty=False)#

Retrieves student emails from file suivi.rst.

Paramètres:
  • group – group

  • skip_if_empty – skip if no mail?

Renvoie:

list of mails

source on GitHub

get_group_location(group)#

Returns the local folder associated to a group.

Paramètres:

group – group name

Renvoie:

local folder

source on GitHub

static get_regex(path, regex, suivi='suivi.rst', skip_if_empty=False)#

Retrieves data from file suivi.rst using a regular expression.

Paramètres:
  • path – sub folder to look into

  • suivi – name of the file suivi.rst

  • skip_if_empty – skip of no mail?

Renvoie:

list of mails

source on GitHub

get_sections(group)#

Extracts sections from a filename used to follow a group of students.

Paramètres:

group – group

Renvoie:

dictionary { section : content }

Example of a file:

rapport
+++++++

* bla 1

extrait
+++++++

::

    paragraphe 1

    paragraphe 2

source on GitHub

get_videos(group)#

Retrieves student emails from file suivi.rst.

Paramètres:

group – group

Renvoie:

list of videos

source on GitHub

list_mails(group)#

Returns the number of mails of a group.

Paramètres:

group – group name

Renvoie:

list of mails

source on GitHub

static match_mail(name, emails, threshold=3, exc=True)#

Tries to match a name among a list of mails.

Paramètres:
  • name – a name (first name last name separated by a space)

  • emails – list of emails

  • threshold – above this threshold, mails and names don’t match

  • exc – raise an Exception if not found

Renvoie:

list of available mails, boolean

The second results is True if no email were found in the list.

source on GitHub

static match_mails(names, emails, threshold=3, exc=True, skip_names=None)#

Tries to match a series of names among a list of mails.

Paramètres:
  • names – list of names (first name last name separated by a space)

  • emails – list of emails

  • threshold – above this threshold, mails and names don’t match

  • exc – raise an Exception if not found

  • skip_names – the second boolean is True is one of the name belongs to this list

Renvoie:

list of available mails, boolean

The second results is True if no email were found in the list.

source on GitHub

remove_group(group)#

Removes a group.

Paramètres:

group – group

Renvoie:

list of removed files

See remove_folder.

source on GitHub

unzip_convert(group)#

Unzips files and convert notebooks into HTML.

Paramètres:

group – group name

Renvoie:

list of new files

source on GitHub

unzip_files(group)#

Unzips files and convert notebooks into HTML.

Paramètres:

group – group name

Renvoie:

list of new filess

source on GitHub

write_run_command(filename=None, renderer=None)#

Writes a command script to run a server for this local content. The server runs the javascripts fetching for local files. The content is available at http://localhost:9000/.

source on GitHub

write_summary(renderer=None, link='index_mails.html', outfile='index.html', title='summary', nolink_if=None)#

Produces a summary and uses a Jinja2 template.

Paramètres:
  • renderer – instance of EmailMessageRenderer), can be None

  • link – look for this file in each folder

  • outfile – output file

  • nolink_if – link containing those strings will be removed (if None, a default set will be assigned)

  • title – title

Renvoie:

summary

The current default template is:

.. runpython::

from ensae_teaching_cs.automation_students.projects_repository import _default_template_summary_template print(_default_template_summary)

source on GitHub

zip_group(group, outfile, addition=None)#

Zips a group.

Paramètres:
  • group – group

  • outfile – output file

  • addition – additional files (sequence)

Renvoie:

list of zipped files

source on GitHub