mirror of
https://github.com/partitioncloud/partitioncloud-server.git
synced 2025-02-02 13:49:40 +01:00
Take advice from pylint
This commit is contained in:
parent
2d807112c7
commit
11ddbf0169
@ -32,9 +32,10 @@ app.register_blueprint(partition.bp)
|
|||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
result = subprocess.run(["git", "describe", "--tags"], stdout=subprocess.PIPE)
|
result = subprocess.run(["git", "describe", "--tags"], stdout=subprocess.PIPE, check=True)
|
||||||
__version__ = result.stdout.decode('utf8')
|
__version__ = result.stdout.decode('utf8')
|
||||||
except FileNotFoundError: # In case git not found, which would be strange
|
except (FileNotFoundError, subprocess.CalledProcessError):
|
||||||
|
# In case git not found or any platform specific weird error
|
||||||
__version__ = "unknown"
|
__version__ = "unknown"
|
||||||
|
|
||||||
|
|
||||||
@ -94,8 +95,11 @@ def add_user():
|
|||||||
@app.route("/static/search-thumbnails/<uuid>.jpg")
|
@app.route("/static/search-thumbnails/<uuid>.jpg")
|
||||||
@login_required
|
@login_required
|
||||||
def search_thumbnail(uuid):
|
def search_thumbnail(uuid):
|
||||||
|
"""
|
||||||
|
Renvoie l'apercu d'un résultat de recherche
|
||||||
|
"""
|
||||||
db = get_db()
|
db = get_db()
|
||||||
partition = db.execute(
|
part = db.execute(
|
||||||
"""
|
"""
|
||||||
SELECT uuid, url FROM search_results
|
SELECT uuid, url FROM search_results
|
||||||
WHERE uuid = ?
|
WHERE uuid = ?
|
||||||
@ -103,7 +107,7 @@ def search_thumbnail(uuid):
|
|||||||
(uuid,)
|
(uuid,)
|
||||||
).fetchone()
|
).fetchone()
|
||||||
|
|
||||||
if partition is None:
|
if part is None:
|
||||||
abort(404)
|
abort(404)
|
||||||
if not os.path.exists(os.path.join(app.static_folder, "search-thumbnails", f"{uuid}.jpg")):
|
if not os.path.exists(os.path.join(app.static_folder, "search-thumbnails", f"{uuid}.jpg")):
|
||||||
os.system(
|
os.system(
|
||||||
@ -119,9 +123,10 @@ def search_thumbnail(uuid):
|
|||||||
|
|
||||||
@app.context_processor
|
@app.context_processor
|
||||||
def inject_default_variables():
|
def inject_default_variables():
|
||||||
|
"""Inject the version number in the template variables"""
|
||||||
if __version__ == "unknown":
|
if __version__ == "unknown":
|
||||||
return dict(version="")
|
return {"version": ''}
|
||||||
return dict(version=__version__)
|
return {"version": __version__}
|
||||||
|
|
||||||
|
|
||||||
@app.after_request
|
@app.after_request
|
||||||
|
@ -2,8 +2,7 @@
|
|||||||
"""
|
"""
|
||||||
Admin Panel
|
Admin Panel
|
||||||
"""
|
"""
|
||||||
import os
|
from flask import Blueprint, render_template, session
|
||||||
from flask import Blueprint, abort, send_file, render_template, session
|
|
||||||
|
|
||||||
from .db import get_db
|
from .db import get_db
|
||||||
from .auth import admin_required
|
from .auth import admin_required
|
||||||
@ -15,6 +14,9 @@ bp = Blueprint("admin", __name__, url_prefix="/admin")
|
|||||||
@bp.route("/")
|
@bp.route("/")
|
||||||
@admin_required
|
@admin_required
|
||||||
def index():
|
def index():
|
||||||
|
"""
|
||||||
|
Admin panel home page
|
||||||
|
"""
|
||||||
current_user = User(user_id=session.get("user_id"))
|
current_user = User(user_id=session.get("user_id"))
|
||||||
current_user.get_albums() # We need to do that before we close the db
|
current_user.get_albums() # We need to do that before we close the db
|
||||||
db = get_db()
|
db = get_db()
|
||||||
|
@ -6,8 +6,8 @@ import os
|
|||||||
import shutil
|
import shutil
|
||||||
from uuid import uuid4
|
from uuid import uuid4
|
||||||
|
|
||||||
from flask import (Blueprint, abort, flash, redirect, render_template, request,
|
from flask import (Blueprint, abort, flash, redirect, render_template,
|
||||||
send_file, session, current_app)
|
request, session, current_app)
|
||||||
|
|
||||||
from .auth import login_required
|
from .auth import login_required
|
||||||
from .db import get_db
|
from .db import get_db
|
||||||
@ -20,13 +20,10 @@ bp = Blueprint("albums", __name__, url_prefix="/albums")
|
|||||||
@bp.route("/")
|
@bp.route("/")
|
||||||
@login_required
|
@login_required
|
||||||
def index():
|
def index():
|
||||||
|
"""
|
||||||
|
Albums home page
|
||||||
|
"""
|
||||||
user = User(user_id=session.get("user_id"))
|
user = User(user_id=session.get("user_id"))
|
||||||
albums = user.get_albums()
|
|
||||||
|
|
||||||
if user.access_level == 1:
|
|
||||||
max_queries = 10
|
|
||||||
else:
|
|
||||||
max_queries = current_app.config["MAX_ONLINE_QUERIES"]
|
|
||||||
|
|
||||||
return render_template("albums/index.html", user=user)
|
return render_template("albums/index.html", user=user)
|
||||||
|
|
||||||
@ -34,6 +31,9 @@ def index():
|
|||||||
@bp.route("/search", methods=["POST"])
|
@bp.route("/search", methods=["POST"])
|
||||||
@login_required
|
@login_required
|
||||||
def search_page():
|
def search_page():
|
||||||
|
"""
|
||||||
|
Résultats de recherche
|
||||||
|
"""
|
||||||
if "query" not in request.form or request.form["query"] == "":
|
if "query" not in request.form or request.form["query"] == "":
|
||||||
flash("Aucun terme de recherche spécifié.")
|
flash("Aucun terme de recherche spécifié.")
|
||||||
return redirect("/albums")
|
return redirect("/albums")
|
||||||
@ -98,14 +98,18 @@ def album(uuid):
|
|||||||
|
|
||||||
@bp.route("/<uuid>/qr")
|
@bp.route("/<uuid>/qr")
|
||||||
def qr_code(uuid):
|
def qr_code(uuid):
|
||||||
|
"""
|
||||||
|
Renvoie le QR Code d'un album
|
||||||
|
"""
|
||||||
return get_qrcode(f"/albums/{uuid}")
|
return get_qrcode(f"/albums/{uuid}")
|
||||||
|
|
||||||
|
|
||||||
@bp.route("/create-album", methods=["POST"])
|
@bp.route("/create-album", methods=["POST"])
|
||||||
@login_required
|
@login_required
|
||||||
def create_album():
|
def create_album():
|
||||||
current_user = User(user_id=session.get("user_id"))
|
"""
|
||||||
|
Création d'un album
|
||||||
|
"""
|
||||||
name = request.form["name"]
|
name = request.form["name"]
|
||||||
db = get_db()
|
db = get_db()
|
||||||
error = None
|
error = None
|
||||||
@ -145,7 +149,6 @@ def create_album():
|
|||||||
"status": "ok",
|
"status": "ok",
|
||||||
"uuid": uuid
|
"uuid": uuid
|
||||||
}
|
}
|
||||||
else:
|
|
||||||
return redirect(f"/albums/{uuid}")
|
return redirect(f"/albums/{uuid}")
|
||||||
|
|
||||||
flash(error)
|
flash(error)
|
||||||
@ -155,6 +158,9 @@ def create_album():
|
|||||||
@bp.route("/<uuid>/join")
|
@bp.route("/<uuid>/join")
|
||||||
@login_required
|
@login_required
|
||||||
def join_album(uuid):
|
def join_album(uuid):
|
||||||
|
"""
|
||||||
|
Rejoindre un album
|
||||||
|
"""
|
||||||
user = User(user_id=session.get("user_id"))
|
user = User(user_id=session.get("user_id"))
|
||||||
try:
|
try:
|
||||||
user.join_album(uuid)
|
user.join_album(uuid)
|
||||||
@ -169,6 +175,9 @@ def join_album(uuid):
|
|||||||
@bp.route("/<uuid>/quit")
|
@bp.route("/<uuid>/quit")
|
||||||
@login_required
|
@login_required
|
||||||
def quit_album(uuid):
|
def quit_album(uuid):
|
||||||
|
"""
|
||||||
|
Quitter un album
|
||||||
|
"""
|
||||||
user = User(user_id=session.get("user_id"))
|
user = User(user_id=session.get("user_id"))
|
||||||
album = Album(uuid=uuid)
|
album = Album(uuid=uuid)
|
||||||
users = album.get_users()
|
users = album.get_users()
|
||||||
@ -182,13 +191,15 @@ def quit_album(uuid):
|
|||||||
|
|
||||||
user.quit_album(uuid)
|
user.quit_album(uuid)
|
||||||
flash("Album quitté.")
|
flash("Album quitté.")
|
||||||
return redirect(f"/albums")
|
return redirect("/albums")
|
||||||
|
|
||||||
|
|
||||||
@bp.route("/<uuid>/delete", methods=["GET", "POST"])
|
@bp.route("/<uuid>/delete", methods=["GET", "POST"])
|
||||||
@login_required
|
@login_required
|
||||||
def delete_album(uuid):
|
def delete_album(uuid):
|
||||||
db = get_db()
|
"""
|
||||||
|
Supprimer un album
|
||||||
|
"""
|
||||||
album = Album(uuid=uuid)
|
album = Album(uuid=uuid)
|
||||||
user = User(user_id=session.get("user_id"))
|
user = User(user_id=session.get("user_id"))
|
||||||
|
|
||||||
@ -218,6 +229,9 @@ def delete_album(uuid):
|
|||||||
@bp.route("/<album_uuid>/add-partition", methods=["POST"])
|
@bp.route("/<album_uuid>/add-partition", methods=["POST"])
|
||||||
@login_required
|
@login_required
|
||||||
def add_partition(album_uuid):
|
def add_partition(album_uuid):
|
||||||
|
"""
|
||||||
|
Ajouter une partition à un album (par upload)
|
||||||
|
"""
|
||||||
db = get_db()
|
db = get_db()
|
||||||
user = User(user_id=session.get("user_id"))
|
user = User(user_id=session.get("user_id"))
|
||||||
album = Album(uuid=album_uuid)
|
album = Album(uuid=album_uuid)
|
||||||
@ -281,7 +295,10 @@ def add_partition(album_uuid):
|
|||||||
file = request.files["file"]
|
file = request.files["file"]
|
||||||
file.save(f"partitioncloud/partitions/{partition_uuid}.pdf")
|
file.save(f"partitioncloud/partitions/{partition_uuid}.pdf")
|
||||||
else:
|
else:
|
||||||
shutil.copyfile(f"partitioncloud/search-partitions/{search_uuid}.pdf", f"partitioncloud/partitions/{partition_uuid}.pdf")
|
shutil.copyfile(
|
||||||
|
f"partitioncloud/search-partitions/{search_uuid}.pdf",
|
||||||
|
f"partitioncloud/partitions/{partition_uuid}.pdf"
|
||||||
|
)
|
||||||
|
|
||||||
os.system(
|
os.system(
|
||||||
f'/usr/bin/convert -thumbnail\
|
f'/usr/bin/convert -thumbnail\
|
||||||
@ -290,14 +307,6 @@ def add_partition(album_uuid):
|
|||||||
partitioncloud/partitions/{partition_uuid}.pdf[0] \
|
partitioncloud/partitions/{partition_uuid}.pdf[0] \
|
||||||
partitioncloud/static/thumbnails/{partition_uuid}.jpg'
|
partitioncloud/static/thumbnails/{partition_uuid}.jpg'
|
||||||
)
|
)
|
||||||
|
|
||||||
album_id = db.execute(
|
|
||||||
"""
|
|
||||||
SELECT id FROM album
|
|
||||||
WHERE uuid = ?
|
|
||||||
""",
|
|
||||||
(album.uuid,)
|
|
||||||
).fetchone()["id"]
|
|
||||||
db.commit()
|
db.commit()
|
||||||
|
|
||||||
album.add_partition(partition_uuid)
|
album.add_partition(partition_uuid)
|
||||||
@ -311,7 +320,6 @@ def add_partition(album_uuid):
|
|||||||
"status": "ok",
|
"status": "ok",
|
||||||
"uuid": partition_uuid
|
"uuid": partition_uuid
|
||||||
}
|
}
|
||||||
else:
|
|
||||||
flash(f"Partition {request.form['name']} ajoutée")
|
flash(f"Partition {request.form['name']} ajoutée")
|
||||||
return redirect(f"/albums/{album.uuid}")
|
return redirect(f"/albums/{album.uuid}")
|
||||||
|
|
||||||
@ -319,6 +327,9 @@ def add_partition(album_uuid):
|
|||||||
@bp.route("/add-partition", methods=["POST"])
|
@bp.route("/add-partition", methods=["POST"])
|
||||||
@login_required
|
@login_required
|
||||||
def add_partition_from_search():
|
def add_partition_from_search():
|
||||||
|
"""
|
||||||
|
Ajout d'une partition (depuis la recherche)
|
||||||
|
"""
|
||||||
user = User(user_id=session.get("user_id"))
|
user = User(user_id=session.get("user_id"))
|
||||||
error = None
|
error = None
|
||||||
|
|
||||||
@ -355,7 +366,7 @@ def add_partition_from_search():
|
|||||||
|
|
||||||
return redirect(f"/albums/{album.uuid}")
|
return redirect(f"/albums/{album.uuid}")
|
||||||
|
|
||||||
elif request.form["partition-type"] == "online_search":
|
if request.form["partition-type"] == "online_search":
|
||||||
return render_template(
|
return render_template(
|
||||||
"albums/add-partition.html",
|
"albums/add-partition.html",
|
||||||
album=album,
|
album=album,
|
||||||
@ -363,6 +374,5 @@ def add_partition_from_search():
|
|||||||
user=user
|
user=user
|
||||||
)
|
)
|
||||||
|
|
||||||
else:
|
|
||||||
flash("Type de partition inconnu.")
|
flash("Type de partition inconnu.")
|
||||||
return redirect("/albums")
|
return redirect("/albums")
|
@ -4,18 +4,9 @@ Authentification module
|
|||||||
"""
|
"""
|
||||||
import functools
|
import functools
|
||||||
|
|
||||||
from flask import (
|
from flask import (Blueprint, flash, g, redirect, render_template,
|
||||||
Blueprint,
|
request, session, url_for, current_app)
|
||||||
flash,
|
|
||||||
g,
|
|
||||||
redirect,
|
|
||||||
render_template,
|
|
||||||
request,
|
|
||||||
session,
|
|
||||||
url_for,
|
|
||||||
flash,
|
|
||||||
current_app
|
|
||||||
)
|
|
||||||
from werkzeug.security import check_password_hash, generate_password_hash
|
from werkzeug.security import check_password_hash, generate_password_hash
|
||||||
|
|
||||||
from .db import get_db
|
from .db import get_db
|
||||||
@ -117,7 +108,8 @@ def register():
|
|||||||
except db.IntegrityError:
|
except db.IntegrityError:
|
||||||
# The username was already taken, which caused the
|
# The username was already taken, which caused the
|
||||||
# commit to fail. Show a validation error.
|
# commit to fail. Show a validation error.
|
||||||
error = f"Le nom d'utilisateur {username} est déjà pris. Vous souhaitez peut-être vous connecter"
|
error = f"Le nom d'utilisateur {username} est déjà pris. \
|
||||||
|
Vous souhaitez peut-être vous connecter"
|
||||||
else:
|
else:
|
||||||
# Success, go to the login page.
|
# Success, go to the login page.
|
||||||
return redirect(url_for("auth.login"))
|
return redirect(url_for("auth.login"))
|
||||||
|
@ -1,3 +1,6 @@
|
|||||||
|
"""
|
||||||
|
Classe Album
|
||||||
|
"""
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from ..db import get_db
|
from ..db import get_db
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
import os
|
import os
|
||||||
|
|
||||||
from flask import current_app
|
|
||||||
|
|
||||||
from ..db import get_db
|
from ..db import get_db
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
import os
|
import os
|
||||||
from flask import current_app
|
|
||||||
|
|
||||||
from ..db import get_db
|
from ..db import get_db
|
||||||
from .user import User
|
from .user import User
|
||||||
@ -61,7 +60,7 @@ class Partition():
|
|||||||
|
|
||||||
def update(self, name=None, author="", body=""):
|
def update(self, name=None, author="", body=""):
|
||||||
if name is None:
|
if name is None:
|
||||||
return Exception("name cannot be None")
|
raise Exception("name cannot be None")
|
||||||
|
|
||||||
db = get_db()
|
db = get_db()
|
||||||
db.execute(
|
db.execute(
|
||||||
|
@ -226,5 +226,4 @@ class User():
|
|||||||
if len(colors) == 0:
|
if len(colors) == 0:
|
||||||
integer = hash(self.username) % 16777215
|
integer = hash(self.username) % 16777215
|
||||||
return "#" + str(hex(integer))[2:]
|
return "#" + str(hex(integer))[2:]
|
||||||
else:
|
|
||||||
return f"var({colors[hash(self.username) %len(colors)]})"
|
return f"var({colors[hash(self.username) %len(colors)]})"
|
@ -16,13 +16,3 @@ def get_db():
|
|||||||
g.db.row_factory = sqlite3.Row
|
g.db.row_factory = sqlite3.Row
|
||||||
|
|
||||||
return g.db
|
return g.db
|
||||||
|
|
||||||
|
|
||||||
def close_db(e=None):
|
|
||||||
"""If this request connected to the database, close the
|
|
||||||
connection.
|
|
||||||
"""
|
|
||||||
db = g.pop("db", None)
|
|
||||||
|
|
||||||
if db is not None:
|
|
||||||
db.close()
|
|
||||||
|
@ -2,15 +2,12 @@
|
|||||||
"""
|
"""
|
||||||
Groupe module
|
Groupe module
|
||||||
"""
|
"""
|
||||||
import os
|
from flask import (Blueprint, abort, flash, redirect, render_template,
|
||||||
|
request, session)
|
||||||
from flask import (Blueprint, abort, flash, redirect, render_template, request,
|
|
||||||
send_file, session, current_app)
|
|
||||||
|
|
||||||
from .auth import login_required
|
from .auth import login_required
|
||||||
from .db import get_db
|
from .db import get_db
|
||||||
from .utils import User, Album, get_all_partitions, Groupe, new_uuid, get_qrcode, format_uuid
|
from .utils import User, Album, Groupe, new_uuid, get_qrcode, format_uuid
|
||||||
from . import search
|
|
||||||
|
|
||||||
bp = Blueprint("groupe", __name__, url_prefix="/groupe")
|
bp = Blueprint("groupe", __name__, url_prefix="/groupe")
|
||||||
|
|
||||||
@ -61,8 +58,6 @@ def album_qr_code(uuid):
|
|||||||
@bp.route("/create-groupe", methods=["POST"])
|
@bp.route("/create-groupe", methods=["POST"])
|
||||||
@login_required
|
@login_required
|
||||||
def create_groupe():
|
def create_groupe():
|
||||||
current_user = User(user_id=session.get("user_id"))
|
|
||||||
|
|
||||||
name = request.form["name"]
|
name = request.form["name"]
|
||||||
db = get_db()
|
db = get_db()
|
||||||
error = None
|
error = None
|
||||||
@ -102,7 +97,6 @@ def create_groupe():
|
|||||||
"status": "ok",
|
"status": "ok",
|
||||||
"uuid": uuid
|
"uuid": uuid
|
||||||
}
|
}
|
||||||
else:
|
|
||||||
return redirect(f"/groupe/{uuid}")
|
return redirect(f"/groupe/{uuid}")
|
||||||
|
|
||||||
flash(error)
|
flash(error)
|
||||||
@ -139,13 +133,12 @@ def quit_groupe(uuid):
|
|||||||
|
|
||||||
user.quit_groupe(groupe.uuid)
|
user.quit_groupe(groupe.uuid)
|
||||||
flash("Groupe quitté.")
|
flash("Groupe quitté.")
|
||||||
return redirect(f"/albums")
|
return redirect("/albums")
|
||||||
|
|
||||||
|
|
||||||
@bp.route("/<uuid>/delete", methods=["POST"])
|
@bp.route("/<uuid>/delete", methods=["POST"])
|
||||||
@login_required
|
@login_required
|
||||||
def delete_groupe(uuid):
|
def delete_groupe(uuid):
|
||||||
db = get_db()
|
|
||||||
groupe = Groupe(uuid=uuid)
|
groupe = Groupe(uuid=uuid)
|
||||||
user = User(user_id=session.get("user_id"))
|
user = User(user_id=session.get("user_id"))
|
||||||
|
|
||||||
@ -220,7 +213,6 @@ def create_album(groupe_uuid):
|
|||||||
"status": "ok",
|
"status": "ok",
|
||||||
"uuid": uuid
|
"uuid": uuid
|
||||||
}
|
}
|
||||||
else:
|
|
||||||
return redirect(f"/groupe/{groupe.uuid}/{uuid}")
|
return redirect(f"/groupe/{groupe.uuid}/{uuid}")
|
||||||
|
|
||||||
flash(error)
|
flash(error)
|
||||||
|
@ -15,7 +15,6 @@ bp = Blueprint("partition", __name__, url_prefix="/partition")
|
|||||||
|
|
||||||
@bp.route("/<uuid>")
|
@bp.route("/<uuid>")
|
||||||
def partition(uuid):
|
def partition(uuid):
|
||||||
db = get_db()
|
|
||||||
try:
|
try:
|
||||||
partition = Partition(uuid=uuid)
|
partition = Partition(uuid=uuid)
|
||||||
except LookupError:
|
except LookupError:
|
||||||
@ -29,7 +28,6 @@ def partition(uuid):
|
|||||||
|
|
||||||
@bp.route("/<uuid>/attachments")
|
@bp.route("/<uuid>/attachments")
|
||||||
def attachments(uuid):
|
def attachments(uuid):
|
||||||
db = get_db()
|
|
||||||
try:
|
try:
|
||||||
partition = Partition(uuid=uuid)
|
partition = Partition(uuid=uuid)
|
||||||
except LookupError:
|
except LookupError:
|
||||||
@ -105,13 +103,11 @@ def add_attachment(uuid):
|
|||||||
"status": "ok",
|
"status": "ok",
|
||||||
"uuid": attachment_uuid
|
"uuid": attachment_uuid
|
||||||
}
|
}
|
||||||
else:
|
|
||||||
return redirect(f"/partition/{partition.uuid}/attachments")
|
return redirect(f"/partition/{partition.uuid}/attachments")
|
||||||
|
|
||||||
|
|
||||||
@bp.route("/attachment/<uuid>.<filetype>")
|
@bp.route("/attachment/<uuid>.<filetype>")
|
||||||
def attachment(uuid, filetype):
|
def attachment(uuid, filetype):
|
||||||
db = get_db()
|
|
||||||
try:
|
try:
|
||||||
attachment = Attachment(uuid=uuid)
|
attachment = Attachment(uuid=uuid)
|
||||||
except LookupError:
|
except LookupError:
|
||||||
@ -129,7 +125,6 @@ def attachment(uuid, filetype):
|
|||||||
@bp.route("/<uuid>/edit", methods=["GET", "POST"])
|
@bp.route("/<uuid>/edit", methods=["GET", "POST"])
|
||||||
@login_required
|
@login_required
|
||||||
def edit(uuid):
|
def edit(uuid):
|
||||||
db = get_db()
|
|
||||||
try:
|
try:
|
||||||
partition = Partition(uuid=uuid)
|
partition = Partition(uuid=uuid)
|
||||||
except LookupError:
|
except LookupError:
|
||||||
@ -169,7 +164,6 @@ def edit(uuid):
|
|||||||
@bp.route("/<uuid>/details", methods=["GET", "POST"])
|
@bp.route("/<uuid>/details", methods=["GET", "POST"])
|
||||||
@admin_required
|
@admin_required
|
||||||
def details(uuid):
|
def details(uuid):
|
||||||
db = get_db()
|
|
||||||
try:
|
try:
|
||||||
partition = Partition(uuid=uuid)
|
partition = Partition(uuid=uuid)
|
||||||
except LookupError:
|
except LookupError:
|
||||||
|
@ -56,8 +56,8 @@ def download_search_result(element):
|
|||||||
try:
|
try:
|
||||||
urllib.request.urlretrieve(url, f"partitioncloud/search-partitions/{uuid}.pdf")
|
urllib.request.urlretrieve(url, f"partitioncloud/search-partitions/{uuid}.pdf")
|
||||||
|
|
||||||
except (urllib.error.HTTPError, urllib.error.URLError) as e:
|
except (urllib.error.HTTPError, urllib.error.URLError):
|
||||||
with open(f"partitioncloud/search-partitions/{uuid}.pdf",'a') as f:
|
with open(f"partitioncloud/search-partitions/{uuid}.pdf", 'a', encoding="utf8") as f:
|
||||||
pass # Create empty file
|
pass # Create empty file
|
||||||
|
|
||||||
|
|
||||||
@ -112,7 +112,6 @@ def online_search(query, num_queries):
|
|||||||
thread.join()
|
thread.join()
|
||||||
|
|
||||||
for element in partitions:
|
for element in partitions:
|
||||||
pass
|
|
||||||
uuid = element["uuid"]
|
uuid = element["uuid"]
|
||||||
url = element["url"]
|
url = element["url"]
|
||||||
if os.stat(f"partitioncloud/search-partitions/{uuid}.pdf").st_size == 0:
|
if os.stat(f"partitioncloud/search-partitions/{uuid}.pdf").st_size == 0:
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
#!/usr/bin/python3
|
#!/usr/bin/python3
|
||||||
import os
|
|
||||||
import io
|
import io
|
||||||
import random
|
import random
|
||||||
import string
|
import string
|
||||||
|
@ -15,7 +15,7 @@ def get_sqlite_data(*args):
|
|||||||
con = sqlite3.connect("instance/partitioncloud.sqlite")
|
con = sqlite3.connect("instance/partitioncloud.sqlite")
|
||||||
cur = con.cursor()
|
cur = con.cursor()
|
||||||
data = cur.execute(*args)
|
data = cur.execute(*args)
|
||||||
new_data = [i for i in data]
|
new_data = list(data)
|
||||||
con.close()
|
con.close()
|
||||||
return new_data
|
return new_data
|
||||||
|
|
||||||
|
@ -92,7 +92,7 @@ def mass_rename():
|
|||||||
(album[0], album[1], utils.format_uuid(album[2]))
|
(album[0], album[1], utils.format_uuid(album[2]))
|
||||||
)
|
)
|
||||||
except sqlite3.IntegrityError:
|
except sqlite3.IntegrityError:
|
||||||
uuid = new_uuid()
|
uuid = utils.new_uuid()
|
||||||
print(f"{Fore.RED}Collision on {album[1]}{Style.RESET_ALL} ({album[2][:10]} renaming to {uuid})")
|
print(f"{Fore.RED}Collision on {album[1]}{Style.RESET_ALL} ({album[2][:10]} renaming to {uuid})")
|
||||||
utils.run_sqlite_command(
|
utils.run_sqlite_command(
|
||||||
"""
|
"""
|
||||||
@ -112,7 +112,7 @@ def mass_rename():
|
|||||||
(groupe[0], groupe[1], utils.format_uuid(groupe[2]))
|
(groupe[0], groupe[1], utils.format_uuid(groupe[2]))
|
||||||
)
|
)
|
||||||
except sqlite3.IntegrityError:
|
except sqlite3.IntegrityError:
|
||||||
uuid = new_uuid()
|
uuid = utils.new_uuid()
|
||||||
print(f"{Fore.RED}Collision on {groupe[1]}{Style.RESET_ALL} ({groupe[2][:10]} renaming to {uuid})")
|
print(f"{Fore.RED}Collision on {groupe[1]}{Style.RESET_ALL} ({groupe[2][:10]} renaming to {uuid})")
|
||||||
utils.run_sqlite_command(
|
utils.run_sqlite_command(
|
||||||
"""
|
"""
|
||||||
|
@ -11,7 +11,7 @@ from hooks import v1
|
|||||||
|
|
||||||
def get_version(v: str) -> (int, int, int):
|
def get_version(v: str) -> (int, int, int):
|
||||||
"""Returns a tuple (major, minor, patch from the string v{major}.{minor}.{patch})"""
|
"""Returns a tuple (major, minor, patch from the string v{major}.{minor}.{patch})"""
|
||||||
assert (v[0] == 'v') # Check if the version is correctly formatted
|
assert v[0] == 'v' # Check if the version is correctly formatted
|
||||||
return tuple(map(int, v[1:].split('.')))
|
return tuple(map(int, v[1:].split('.')))
|
||||||
|
|
||||||
|
|
||||||
@ -48,9 +48,8 @@ def get_hooks(current, target):
|
|||||||
def compare(v1: str, v2: str):
|
def compare(v1: str, v2: str):
|
||||||
if is_newer(v2[0], v1[0]):
|
if is_newer(v2[0], v1[0]):
|
||||||
return -1
|
return -1
|
||||||
elif is_newer(v1[0], v2[0]):
|
if is_newer(v1[0], v2[0]):
|
||||||
return 1
|
return 1
|
||||||
else:
|
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
applied_hooks = []
|
applied_hooks = []
|
||||||
@ -104,12 +103,12 @@ def apply_hooks(hooks):
|
|||||||
|
|
||||||
def migrate(current, target, skip_backup=False, prog_name="scripts/migration.py"):
|
def migrate(current, target, skip_backup=False, prog_name="scripts/migration.py"):
|
||||||
""""""
|
""""""
|
||||||
print(f"Trying to migrate from {args.current} to {args.target}")
|
print(f"Trying to migrate from {current} to {target}")
|
||||||
|
|
||||||
assert is_newer(args.target, args.current)
|
assert is_newer(target, current)
|
||||||
|
|
||||||
applied_hooks = get_hooks(args.current, args.target)
|
applied_hooks = get_hooks(current, target)
|
||||||
if (len(applied_hooks) == 0):
|
if len(applied_hooks) == 0:
|
||||||
print(f"{Fore.GREEN}No hook to apply{Style.RESET_ALL}")
|
print(f"{Fore.GREEN}No hook to apply{Style.RESET_ALL}")
|
||||||
exit(0)
|
exit(0)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user