mirror of
https://git.selfprivacy.org/SelfPrivacy/selfprivacy-rest-api.git
synced 2024-11-25 21:41:27 +00:00
Implemented update check endpoint
This commit is contained in:
parent
205908b46c
commit
fb98fd1e60
57
selfprivacy_api/resources/services/update.py
Normal file
57
selfprivacy_api/resources/services/update.py
Normal file
|
@ -0,0 +1,57 @@
|
|||
#!/usr/bin/env/python3
|
||||
"""Update dispatch module"""
|
||||
import json
|
||||
import os
|
||||
import portalocker
|
||||
import subprocess
|
||||
from flask_restful import Resource, reqparse
|
||||
|
||||
from selfprivacy_api.resources.services import api
|
||||
|
||||
|
||||
class PullRepositoryChanges(Resource):
|
||||
def get(self):
|
||||
"""
|
||||
Pull Repository Changes
|
||||
---
|
||||
tags:
|
||||
- Update
|
||||
security:
|
||||
- bearerAuth: []
|
||||
responses:
|
||||
200:
|
||||
description: Got update
|
||||
201:
|
||||
description: Nothing to update
|
||||
401:
|
||||
description: Unauthorized
|
||||
500:
|
||||
description: Something went wrong
|
||||
"""
|
||||
|
||||
git_pull_command = ["git", "pull"]
|
||||
|
||||
|
||||
os.chdir("/etc/nixos")
|
||||
git_pull_process_descriptor = subprocess.Popen(
|
||||
git_pull_command,
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.STDOUT,
|
||||
shell=False
|
||||
)
|
||||
|
||||
|
||||
git_pull_process_descriptor.communicate()[0]
|
||||
|
||||
if git_pull_process_descriptor.returncode == 0:
|
||||
return {
|
||||
"status": 0,
|
||||
"message": "Update completed successfully"
|
||||
}
|
||||
elif git_pull_process_descriptor.returncode > 0:
|
||||
return {
|
||||
"status": git_pull_process_descriptor.returncode,
|
||||
"message": "Something went wrong"
|
||||
}, 500
|
||||
|
||||
api.add_resource(PullRepositoryChanges, "/update")
|
Loading…
Reference in a new issue