瀏覽代碼

walle 2.0 alpha - 增加info

walle 6 年之前
父節點
當前提交
e4e3143b8d
共有 3 個文件被更改,包括 25 次插入7 次删除
  1. 1 0
      requirements/prod.txt
  2. 23 7
      walle/api/general.py
  3. 1 0
      walle/config/settings.py

+ 1 - 0
requirements/prod.txt

@@ -40,3 +40,4 @@ celery==3.1.18
 pycrypto==2.6.1
 pytz==2015.6
 requests==2.7.0
+GitPython==2.1.11

+ 23 - 7
walle/api/general.py

@@ -8,22 +8,22 @@
     :author: wushuiyong@walle-web.io
 """
 
-import os
-from flask import request, abort, session, current_app
-from flask_login import current_user, login_required
+import platform
+
+from flask import abort
+from git import Repo
 from walle.api.api import SecurityResource
-from walle.model.record import RecordModel
 from walle.model.menu import MenuModel
+from walle.model.record import RecordModel
 from walle.model.user import UserModel
 from walle.service import emails
 from walle.service.deployer import Deployer
-from walle.service.rbac.role import *
-from werkzeug.utils import secure_filename
 from walle.service.extensions import permission
+from walle.service.rbac.role import *
 
 
 class GeneralAPI(SecurityResource):
-    actions = ['menu', 'websocket']
+    actions = ['menu', 'websocket', 'info']
 
     # TODO 更细致的检查
     @permission.upper_reporter
@@ -87,3 +87,19 @@ class GeneralAPI(SecurityResource):
             'command': ret,
             'record': record,
         })
+
+    def info(self):
+        try:
+            repo = Repo(current_app.config.get('PROJECT_ROOT'))
+            branch = str(repo.active_branch)
+            commit = 'ba4ca13d'
+        except Exception as e:
+            branch, commit = ''
+
+        return self.render_json(data={
+            'version': current_app.config.get('VERSION'),
+            'branch': branch,
+            'commit': commit,
+            'server': platform.platform(),
+            'python': platform.python_version(),
+        })

+ 1 - 0
walle/config/settings.py

@@ -6,6 +6,7 @@ from datetime import timedelta
 
 class Config(object):
     """Base configuration."""
+    VERSION = '2.0.0'
 
     SECRET_KEY = os.environ.get('WALLE_SECRET', 'secret-key')
     APP_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir))