Browse Source

Start integrating git

master
Dylan Baker 5 years ago
parent
commit
ee04fe9452
7 changed files with 132 additions and 25 deletions
  1. 1
    1
      Pipfile
  2. 9
    23
      Pipfile.lock
  3. 31
    1
      assets/scss/style.scss
  4. 16
    0
      yird/app.py
  5. 47
    0
      yird/services/git.py
  6. 10
    0
      yird/templates/layout.html.j2
  7. 18
    0
      yird/templates/repo/index.html.j2

+ 1
- 1
Pipfile View File

@@ -8,11 +8,11 @@ verify_ssl = true
8 8
 [packages]
9 9
 flask = "*"
10 10
 wtforms = "*"
11
-gitpython = "*"
12 11
 markdown = "*"
13 12
 pytest = "*"
14 13
 pytest-cov = "*"
15 14
 flask-webpack = "*"
15
+sh = "*"
16 16
 
17 17
 [requires]
18 18
 python_version = "3.7"

+ 9
- 23
Pipfile.lock View File

@@ -1,7 +1,7 @@
1 1
 {
2 2
     "_meta": {
3 3
         "hash": {
4
-            "sha256": "4389fadf9b02e4cf8b8de26830e9ffa003e4414fe29778e11d1a07862e19c8da"
4
+            "sha256": "2fc31fe49a97d00c3e1f88f1aacb9aaaa7348bd39cc4e09df5a42018eb09a640"
5 5
         },
6 6
         "pipfile-spec": 6,
7 7
         "requires": {
@@ -88,21 +88,6 @@
88 88
             "index": "pypi",
89 89
             "version": "==0.1.0"
90 90
         },
91
-        "gitdb2": {
92
-            "hashes": [
93
-                "sha256:83361131a1836661a155172932a13c08bda2db3674e4caa32368aa6eb02f38c2",
94
-                "sha256:e3a0141c5f2a3f635c7209d56c496ebe1ad35da82fe4d3ec4aaa36278d70648a"
95
-            ],
96
-            "version": "==2.0.5"
97
-        },
98
-        "gitpython": {
99
-            "hashes": [
100
-                "sha256:563221e5a44369c6b79172f455584c9ebbb122a13368cc82cb4b5addff788f82",
101
-                "sha256:8237dc5bfd6f1366abeee5624111b9d6879393d84745a507de0fda86043b65a8"
102
-            ],
103
-            "index": "pypi",
104
-            "version": "==2.1.11"
105
-        },
106 91
         "itsdangerous": {
107 92
             "hashes": [
108 93
                 "sha256:321b033d07f2a4136d3ec762eac9f16a10ccd60f53c0c91af90217ace7ba1f19",
@@ -196,6 +181,14 @@
196 181
             "index": "pypi",
197 182
             "version": "==2.6.0"
198 183
         },
184
+        "sh": {
185
+            "hashes": [
186
+                "sha256:ae3258c5249493cebe73cb4e18253a41ed69262484bad36fdb3efcb8ad8870bb",
187
+                "sha256:b52bf5833ed01c7b5c5fb73a7f71b3d98d48e9b9b8764236237bdc7ecae850fc"
188
+            ],
189
+            "index": "pypi",
190
+            "version": "==1.12.14"
191
+        },
199 192
         "six": {
200 193
             "hashes": [
201 194
                 "sha256:3350809f0555b11f552448330d0b52d5f24c91a322ea4a15ef22629740f3761c",
@@ -203,13 +196,6 @@
203 196
             ],
204 197
             "version": "==1.12.0"
205 198
         },
206
-        "smmap2": {
207
-            "hashes": [
208
-                "sha256:0555a7bf4df71d1ef4218e4807bbf9b201f910174e6e08af2e138d4e517b4dde",
209
-                "sha256:29a9ffa0497e7f2be94ca0ed1ca1aa3cd4cf25a1f6b4f5f87f74b46ed91d609a"
210
-            ],
211
-            "version": "==2.0.5"
212
-        },
213 199
         "werkzeug": {
214 200
             "hashes": [
215 201
                 "sha256:c3fd7a7d41976d9f44db327260e263132466836cef6f91512889ed60ad26557c",

+ 31
- 1
assets/scss/style.scss View File

@@ -3,7 +3,7 @@
3 3
 $black:       #000000;
4 4
 $white:       #ffffff;
5 5
 $blue:        #496893;
6
-$red:         #ff0000;
6
+$red:         #d9534f;
7 7
 $light-gray:  #f5f5f5;
8 8
 $medium-gray: #c8c8c8;
9 9
 
@@ -46,6 +46,36 @@ body {
46 46
   margin-bottom: 15px;
47 47
 }
48 48
 
49
+.error {
50
+  align-items: center;
51
+  color: $white;
52
+  display: flex;
53
+  font-size: 14px;
54
+  padding: 10px;
55
+}
56
+
57
+.error {
58
+  background: $red;
59
+}
60
+
61
+.error__message {
62
+  flex: 1;
63
+}
64
+
65
+.error__button {
66
+  background: $white;
67
+  border: none;
68
+  color: $black;
69
+  cursor: pointer;
70
+  font-family: $body-font-family;
71
+  font-size: 14px;
72
+  padding: 5px 10px;
73
+
74
+  &:hover {
75
+    background: $light-gray;
76
+  }
77
+}
78
+
49 79
 /* layout */
50 80
 
51 81
 .container {

+ 16
- 0
yird/app.py View File

@@ -2,6 +2,8 @@ from flask import Flask, redirect, render_template, request, url_for
2 2
 
3 3
 from flask_webpack import Webpack
4 4
 
5
+from yird.services.git import GitService
6
+
5 7
 from yird.services.posts import PostsService
6 8
 
7 9
 from yird.settings import Settings
@@ -27,6 +29,11 @@ def inject_site_name():
27 29
     }
28 30
 
29 31
 
32
+@app.context_processor
33
+def inject_git_status():
34
+    return GitService.get_status()
35
+
36
+
30 37
 @app.route('/admin')
31 38
 def index():
32 39
     posts = PostsService.get_posts()
@@ -61,6 +68,15 @@ def update_post(post_id):
61 68
 @app.route('/admin/generate')
62 69
 def generate():
63 70
     PostsService.generate_posts()
71
+
72
+
73
+@app.route('/admin/repo', methods=["GET"])
74
+def repo():
75
+    return render_template('repo/index.html.j2')
76
+
77
+@app.route('/admin/repo', methods=["POST"])
78
+def git_init():
79
+    GitService.init()
64 80
     return redirect(url_for('index'))
65 81
 
66 82
 if __name__ == "__main__":

+ 47
- 0
yird/services/git.py View File

@@ -0,0 +1,47 @@
1
+import re
2
+import sh
3
+
4
+from yird.settings import Settings
5
+
6
+
7
+class GitService:
8
+    git = sh.git.bake(_cwd=Settings().YIRD_PATH)
9
+
10
+    @classmethod
11
+    def get_status(cls):
12
+        files = []
13
+        initialized = False
14
+        try:
15
+            status = cls.git.status("-s", "-uall").strip()
16
+
17
+            for line in status.split("\n"):
18
+                if line[0:9] == "\x1b[31mM\x1b[m":
19
+                    files.append({
20
+                        "filename": line[10:],
21
+                        "status": "modified"
22
+                    })
23
+                elif line[0:9] == "\x1b[32mM\x1b[m":
24
+                    files.append({
25
+                        "filename": line[10:],
26
+                        "status": "added and modified"
27
+                    })
28
+                elif line[0:10] == "\x1b[31m??\x1b[m":
29
+                    files.append({
30
+                        "filename": line[11:],
31
+                        "status": "untracked"
32
+                    })
33
+
34
+            initialized = True
35
+        except sh.ErrorReturnCode_128 as e:
36
+            if re.search('not a git repository', str(e)):
37
+                initialized = False
38
+        return {
39
+            "git": {
40
+                "initialized": initialized,
41
+                "file_statuses": files
42
+            }
43
+        }
44
+
45
+    @classmethod
46
+    def init(cls):
47
+        cls.git.init()

+ 10
- 0
yird/templates/layout.html.j2 View File

@@ -27,6 +27,16 @@
27 27
           </a>
28 28
         </li>
29 29
       </ul>
30
+      {% if not git.initialized %}
31
+        <div class="error">
32
+          <p class="error__message">
33
+            Your YIRD_PATH has not been initialized as a git repository.
34
+          </p>
35
+          <form class="error__form" method="post" action="{{ url_for('git_init') }}">
36
+            <input class="error__button" type="submit" value="Initialize">
37
+          </form>
38
+        </p>
39
+      {% endif %}
30 40
     </header>
31 41
     <main class="main">
32 42
       {% block content %}{% endblock %}

+ 18
- 0
yird/templates/repo/index.html.j2 View File

@@ -0,0 +1,18 @@
1
+{% extends "layout.html.j2" %}
2
+{% block content %}
3
+<div class="repo">
4
+  <h3 class="heading">git repo</h3>
5
+  <table class="file_statuses">
6
+    {% for file in git.file_statuses %}
7
+      <tr>
8
+        <td class="file_statuses__status file_statuses__status--{{ file.status|replace('_', '-') }}">
9
+          {{ file.status }}
10
+        </td>
11
+        <td class="file_statuses__filename">
12
+          {{ file.filename }}
13
+        </td>
14
+      </tr>
15
+    {% endfor %}
16
+  </table>
17
+</div>
18
+{% endblock %}

Loading…
Cancel
Save