forked from AdminTL/gestion_personnage_TL
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request AdminTL#95 from mathben/generate_project_archive_#60
[AdminTL#60] Admin: Add admin setting page and feature to download archive project
- Loading branch information
Showing
8 changed files
with
168 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{% extends "_base.html" %} | ||
|
||
{% block content %} | ||
|
||
<div ng-controller="setting_ctrl" ng-cloak> | ||
<h1>Configuration du site et ses paramètres</h1> | ||
<h2>Générateur d'archive du projet</h2> | ||
<p>Cet outil permet de télécharger le projet dans un fichier format zip et l'exécuter dans un autre environnement.</p> | ||
<div> | ||
<a ng-click="download_archive()" class="btn btn-lg btn-success" role="button"> | ||
<span class="fa fa-spinner fa-spin" ng-show="model_setting.is_downloading_archive"></span> Télécharger le fichier archive. | ||
</a> | ||
<a ng-show="model_setting.downloading_archive.status.enabled" ng-style="model_setting.downloading_archive.status.is_error ? {'color': 'red'} : {'color': 'green'}"> | ||
{{! model_setting.downloading_archive.status.text }} | ||
</a> | ||
</div> | ||
</div> | ||
|
||
{% end %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
#!/usr/bin/env python3 | ||
# -*- coding: utf-8 -*- | ||
|
||
import io | ||
import zipfile | ||
import os | ||
|
||
|
||
class ProjectArchive(object): | ||
def __init__(self, parser): | ||
# self._error = None | ||
self._parser = parser | ||
|
||
actual_path_dir = os.path.dirname(os.path.realpath(__file__)) | ||
self._root_project_path = os.path.normpath(os.path.join(actual_path_dir, os.pardir, os.pardir, os.pardir)) | ||
self._project_name = "gestion_personnage_TL" | ||
self._ignore_directory = [".git", ".idea", "__pycache__"] | ||
self._ignore_file = [".gitmodules", ".gitignore"] | ||
|
||
def generate_archive(self): | ||
# debug_writing_file = [] | ||
# Append all data in buffer | ||
buffer = io.BytesIO() | ||
with zipfile.ZipFile(buffer, mode="w", compression=zipfile.ZIP_DEFLATED) as zip_mem: | ||
for root, dirs, files in os.walk(self._root_project_path): | ||
# Ignore directory | ||
ignore_dir = False | ||
for exclude_path in self._ignore_directory: | ||
if exclude_path in root: | ||
ignore_dir = True | ||
break | ||
if ignore_dir: | ||
continue | ||
|
||
for file in files: | ||
# Ignore file | ||
if file in self._ignore_file: | ||
continue | ||
|
||
file_path = os.path.join(root, file) | ||
file_rel_path = file_path[len(self._root_project_path) + 1:] | ||
zip_file_path = os.path.join(self._project_name, file_rel_path) | ||
# Write file in buffer with zip | ||
with open(file_path, mode="r+b") as obj_file: | ||
zip_mem.writestr(zip_file_path, obj_file.read()) | ||
# debug_writing_file.append((file_path, zip_file_path)) | ||
|
||
io_buffer = buffer.getvalue() | ||
return io_buffer | ||
|
||
# def has_error(self): | ||
# """ | ||
# | ||
# :return: If contain error. | ||
# """ | ||
# return bool(self._error) | ||
# | ||
# def get_error(self, create_object=True, force_error=False): | ||
# """ | ||
# | ||
# :param create_object: if return dict with key "error" or return the message in string | ||
# :param force_error: if activate, generate an unknown error message. | ||
# :return: information about error. | ||
# """ | ||
# msg = self._error | ||
# if not msg and force_error: | ||
# msg = "Unknown error." | ||
# | ||
# if create_object: | ||
# return {"error": msg} | ||
# return msg |
21 changes: 21 additions & 0 deletions
21
src/web/resources/js/tl_module/setting_ctrl/setting_ctrl.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// Formulaire de Traitre-Lame | ||
"use strict"; | ||
|
||
characterApp.controller("setting_ctrl", ["$scope", "$q", "$http", "$window", /*"$timeout",*/ function ($scope, $q, $http, $window) { | ||
$scope.model_setting = { | ||
is_ctrl_ready: false, | ||
|
||
is_downloading_archive: false, | ||
downloading_archive: { | ||
status: { | ||
enabled: false, | ||
is_error: false, | ||
text: "" | ||
} | ||
} | ||
}; | ||
|
||
$scope.download_archive = function () { | ||
window.open("/cmd/archive/generate_project", "_blank", ""); | ||
} | ||
}]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters