module automation_students.git_helper
#
Short summary#
module ensae_teaching_cs.automation_students.git_helper
Some automation helpers to grab mails from students about projects.
Functions#
function |
truncated documentation |
---|---|
Creates a series of folders for groups of students. |
|
Extracts sections from a filename used to follow a group of students. |
|
Changes the origin of the repository. The url and the password refer to the new repository. |
|
Private function, analyse the output. |
|
Clones a project from a git repository in a non empty local folder, it requires GIT to be installed … |
|
From a git repository, it requires GIT to be installed and uses the command line. |
|
Builds a url (starting with https) and add the user and the password to skip the authentification. |
Documentation#
Some automation helpers to grab mails from students about projects.
- ensae_teaching_cs.automation_students.git_helper.create_folders_from_dataframe(df, root, report='suivi.rst', col_student='Eleves', col_group='Groupe', col_subject='Sujet', overwrite=False, email_function=None)#
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)
col_group – index of the grou
col_subject – column which contains the subject
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
- Renvoie:
list of creates folders
The function email_function has the following signature:
def email_function(first_name, last_name): # ....
- ensae_teaching_cs.automation_students.git_helper.get_sections(path, suivi='suivi.rst')#
Extracts sections from a filename used to follow a group of students.
- Paramètres:
path – where to find filename
suivi – file, RST format, section are followed by
+++++
- Renvoie:
dictionary { section : content }
Example of a file:
rapport +++++++ * bla 1 extrait +++++++ :: paragraphe 1 paragraphe 2
- ensae_teaching_cs.automation_students.git_helper.git_change_remote_origin(local_folder, url_https, user=None, password=None, add_fetch=False, timeout=10, fLOG=<function noLOG>)#
Changes the origin of the repository. The url and the password refer to the new repository.
- Paramètres:
local_folder – local folder
url_https – url, example
https://gitlab.server/folder/project_name
user – part 1 of the credentials
password – part 2 of the credentials
timeout – timeout for the command line
add_fetch – add instruction
fetch
fLOG – logging function
- Renvoie:
something
The function runs the instruction:
git remote remove origin git remote add origin url
- ensae_teaching_cs.automation_students.git_helper.git_check_error(out, err, fLOG)#
Private function, analyse the output.
- ensae_teaching_cs.automation_students.git_helper.git_clone(local_folder, url_https, user=None, password=None, timeout=60, init=True, fLOG=<function noLOG>)#
Clones a project from a git repository in a non empty local folder, it requires GIT to be installed and uses the command line.
- Paramètres:
local_folder – local folder of the project
url_https – url, example
https://gitlab.server/folder/project_name
user – part 1 of the credentials
password – part 2 of the credentials
timeout – timeout for the command line
init – see below (True, use fetch, False, use clone)
fLOG – logging function
- Renvoie:
local_folder
If the reposity has already been cloned, it does not do it again. We assume that git can be run without giving its full location.
The function executes the following commands (if init is True):
cd [folder] git init git remote add origin [https://user.password@server/project.git] git fetch
Otherwise, it does:
cd [folder] git clone origin [https://user.password@server/project.git] git fetch
A folder will be created.
Clone many folders in one row
eleves = "project1;project2;..." root = r"destination" for el in eleves.split(";"): cl = el.lower().replace(".","-") fold = os.path.join(root, el) if not os.path.exists(fold): print("clone", el) url = "https://<gitlab>/<group>/{0}.git".format(cl) git_clone( fold, url,user=user,password=password, init=False,fLOG=print)
- ensae_teaching_cs.automation_students.git_helper.git_commit_all(local_folder, url_https, message, user=None, password=None, timeout=300, fLOG=<function noLOG>)#
From a git repository, it requires GIT to be installed and uses the command line.
- Paramètres:
local_folder – local folder of the project
url_https – url, example
https://gitlab.server/folder/project_name
message – message for the commit
user – part 1 of the credentials
password – part 2 of the credentials
timeout – timeout for the command line
fLOG – logging function
- Renvoie:
None
If the reposity has already been cloned, it does not do it again. We assume that git can be run without giving its full location.
The function executes the following commands:
cd [folder] git add -A git commit -m "[message]" git push -u origin master
- ensae_teaching_cs.automation_students.git_helper.git_first_commit_all_projects(local_folder, user=None, password=None, timeout=300, suivi='suivi.rst', fLOG=<function noLOG>)#
- Paramètres:
local_folder – folder
user – part 1 of the credentials
password – part 2 of the credentials
timeout – timeout for the command line
suivi – file to open to get the gitlab account
fLOG – logging function
- Renvoie:
None or ( local_folder, gitlab )
- ensae_teaching_cs.automation_students.git_helper.git_url_user_password(url_https, user, password)#
Builds a url (starting with https) and add the user and the password to skip the authentification.
- Paramètres:
url_https – example
https://gitlab.server/folder/project_name
user – part 1 of the credentials
password – part 2 of the credentials
- Renvoie:
url