apluslms_file_transfer.server

Submodules

apluslms_file_transfer.server.action_general

apluslms_file_transfer.server.action_general.files_to_update(upload_dir, course_name, upload_file_type, manifest_client, data)[source]

Compare the files between the server and the client, and then get the files to update.

Parameters:
  • upload_dir – the directory path where the course directory located
  • course_name (str) – the name of the course to upload/update
  • upload_file_type (str) – the file type of the uploaded files
  • manifest_client (dict) – the file manifest in the client side
  • data – the initial dictionary containing info to send back to the client
Returns:

the dictionary that contains the manifest of the updated files to send back to the client

Return type:

dict

apluslms_file_transfer.server.action_general.publish_files(upload_dir, course_name, file_type, temp_course_dir, res_data)[source]

Publish the uploaded files into the server

Parameters:
  • upload_dir – the directory path where the course directory located
  • course_name – the name of the course to upload/update
  • file_type – the file type of the uploaded files
  • temp_course_dir – the temporary directory where the uploaded files located
  • data – the initial dictionary that contains the info to send back to the client
Returns:

the dictionary that contains the info to send back to the client

Return type:

dict

apluslms_file_transfer.server.action_general.start_cleanup(static_path, cleanup_time)[source]

The function for cleaning up the redundant directories in the server. The redundant directories are those fail to be published.

Parameters:
  • static_path – the path of the course directories locate in
  • cleanup_time – the time interval (seconds) of the action execution

apluslms_file_transfer.server.auth

apluslms_file_transfer.server.auth.authenticate(jwt_decode, headers, course_name)[source]

Authenticate the request

apluslms_file_transfer.server.auth.jwt_auth(jwt_decode, headers)[source]

Authorize the jwt token in the headers of the request

apluslms_file_transfer.server.django

Functions for the servers built using Django

apluslms_file_transfer.server.django.convert_django_header(key)[source]

Convert the key in the headers into a specific format

Parameters:key (str) – the key to convert in the headers
Returns:the converted key
Return type:str
apluslms_file_transfer.server.django.prepare_decoder()[source]

Return the jwt decoder

apluslms_file_transfer.server.django.setting_in_bytes(name)[source]

Get the configuration value of the server

Parameters:name – the name of the configuration
Returns:the value of the configuration
Return type:bytes
apluslms_file_transfer.server.django.upload_files(request, upload_dir, course_name, res_data)[source]

Upload the files in the posted request to the server

Parameters:
  • upload_dir (str) – the directory path where the course directory located
  • course_name (str) – the name of the course
  • res_data – the initial dictionary containing info to send back to the client
Returns:

the dictionary that contains the manifest of the updated files to send back to the client

Return type:

dict

apluslms_file_transfer.server.flask

Functions for the servers built using Flask

apluslms_file_transfer.server.flask.prepare_decoder(app_instance)[source]

Return the jwt decoder

apluslms_file_transfer.server.flask.setting_in_bytes(app_instance, name)[source]

Get the configuration value of the server

Parameters:
  • app_instance – the Flask object
  • name – the name of the configuration
Returns:

the value of the configuration

Return type:

bytes

apluslms_file_transfer.server.flask.upload_files(upload_dir, course_name, res_data)[source]

Upload the files in the posted request to the server

Parameters:
  • upload_dir (str) – the directory path where the course directory located
  • course_name (str) – the name of the course
  • res_data – the initial dictionary containing info to send back to the client
Returns:

the dictionary that contains the manifest of the updated files to send back to the client

Return type:

dict

apluslms_file_transfer.server.upload_utils

apluslms_file_transfer.server.upload_utils.upload_form_data(file, temp_course_dir, framework='flask')[source]

Upload file data posted by a request with form-data content-type to the temp course directory

Parameters:
  • file – the content of the file
  • temp_course_dir (str) – the temporary directory that the file is uploaded to
  • framework (str) – the framework that the server is built by (‘flask’, ‘django’)
apluslms_file_transfer.server.upload_utils.upload_octet_stream(temp_course_dir, file_data, file_index, chunk_index, last_chunk_flag)[source]

Upload file data posted by a request with octet-stream content-type to the temp course directory. The data may be the complete content of the file or a part of the file.

Parameters:
  • temp_course_dir (str) – the temporary directory that the file is uploaded to
  • file_data – the content of the file data (chunk)
  • file_index (int) – the index of the file in the uploaded file list
  • chunk_index (int) – the index of the uploaded chunk of the file
  • last_chunk_flag (bool) – the flag that indicates whether it is the last chunk of the file

apluslms_file_transfer.server.utils

apluslms_file_transfer.server.utils.create_new_manifest(static_file_path, course_name, temp_course_dir)[source]

Create a json file to store the manifest of the uploaded files

Parameters:
  • static_file_path (str) – the directory path where the course directory located
  • course_name (str) – the name of the course
  • temp_course_dir (str) – the temporary directory that the files are uploaded to
apluslms_file_transfer.server.utils.get_update_files(manifest_srv, manifest_client)[source]

Get list of the files to update

Parameters:
  • manifest_client (dict) – a nested dictionary (dict[file] = {‘size’: , ‘mtime’: }) in the client-side
  • manifest_srv (dict) – a nested dictionary (dict[file] = {‘size’: , ‘mtime’: }) in the server side
Returns:

a nested dict containing the files of newly added, updated and removed

Return type:

dict

apluslms_file_transfer.server.utils.tempdir_path(upload_dir, course_name, pid)[source]

Return the temporary directory that the files are uploaded to

Parameters:
  • upload_dir (str) – the directory path where the course directory located
  • course_name (str) – the name of the course
  • pid (str) – the id of this file deployment process
Returns:

the temporary directory that the files in the client side are uploaded to

apluslms_file_transfer.server.utils.whether_allow_renew(manifest_srv, manifest_client, file_type)[source]

Check whether the version in the client side is newer than that in the server side if the course already exists. If so, the deployment process is allowed to continue, otherwise terminate.

Parameters:
  • manifest_srv (dict) – the file manifest in the server side
  • manifest_client (dict) – the file manifest in the client side
  • file_type (str) – the type of the files
Returns:

the flag that indicates whether the course can be renewed

Return type:

bool