format all code

This commit is contained in:
mcbloch 2024-03-27 18:02:53 +01:00
parent f2c1692f5a
commit cf933684f3
6 changed files with 17 additions and 14 deletions

View file

@ -5,4 +5,4 @@ with open("config.toml", mode="rb") as config_toml:
config = tomllib.load(config_toml)
# pprint(config)
# pprint(config)

View file

@ -12,7 +12,7 @@ def find_metadata(filename):
metadata = {}
start_strings = [ ":::spoiler Gitlab sync\n" , ":::spoiler git drive sync\n" ]
start_strings = [":::spoiler Gitlab sync\n", ":::spoiler git drive sync\n"]
end_str = "\n:::"
for start_str in start_strings:
@ -31,8 +31,6 @@ def find_metadata(filename):
print(metadata)
return metadata
print("Not a valid report")
return None

View file

@ -56,7 +56,6 @@ users: {str: [User]} = {}
def loadusers():
usr = None
for name, data in config["mattermost"]["users"].items():
if "token" in data:

View file

@ -14,7 +14,7 @@ def send_message(file_id, file_info, message):
# channel_id = MMApi().get_channel_id("bestuur-dev")
channel = ChannelApi(
channel_id=channel_id,
user=mattermost_client.users[config['mattermost']['selected_user']],
user=mattermost_client.users[config["mattermost"]["selected_user"]],
)
prefix = ""

View file

@ -71,7 +71,9 @@ def sync_file(drive, repo, path, sync_to):
repo.git.push("-u", "origin", branch_name)
if not drive.mergerequests.list(source_branch=branch_name, state="opened"):
if drive.mergerequests.list(source_branch=branch_name):
print(" Creating a new merge request to update the gitlab document with the new version from CodiMD.")
print(
" Creating a new merge request to update the gitlab document with the new version from CodiMD."
)
drive.mergerequests.create(
{
"source_branch": branch_name,
@ -93,8 +95,9 @@ def sync_file(drive, repo, path, sync_to):
else:
print(" Note has no changes.")
def init_sync():
repo = get_repo()
gl = gitlab.Gitlab("https://git.zeus.gent", private_token=TOKEN)
drive = gl.projects.get(2)
return repo, drive
return repo, drive

View file

@ -92,6 +92,7 @@ def validate_downloaded_files(post_mattermost_hint=True):
return db._load_db()
def sync_files_to_gitlab():
repo, drive = sync_gitlab.init_sync()
for file_id, file_info in db.get_files().items():
@ -99,9 +100,10 @@ def sync_files_to_gitlab():
local_file_path = file_info["local_file_path"]
sync_to = file_info["metadata"]["sync-to"]
try:
sync_gitlab.sync_file(drive, repo, local_file_path, sync_to)
sync_gitlab.sync_file(drive, repo, local_file_path, sync_to)
except Exception as e:
print("Critical error: Failed to sync file to Gitlab")
print("Critical error: Failed to sync file to Gitlab")
def sync_files_to_gitea():
repo, api_handler = sync.init_sync()
@ -110,10 +112,11 @@ def sync_files_to_gitea():
local_file_path = file_info["local_file_path"]
sync_to = file_info["metadata"]["sync-to"]
try:
sync.sync_file(repo, api_handler, local_file_path, sync_to)
sync.sync_file(repo, api_handler, local_file_path, sync_to)
except Exception as e:
print("Critical error: Failed to sync file to Gitea")
traceback.print_exc()
print("Critical error: Failed to sync file to Gitea")
traceback.print_exc()
@hug.get("/sync-mattermost")
def sync_mattermost():