Bläddra i källkod

Start integrating git

master
Dylan Baker 5 år sedan
förälder
incheckning
ee04fe9452
7 ändrade filer med 132 tillägg och 25 borttagningar
  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 Visa fil

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

+ 9
- 23
Pipfile.lock Visa fil

1
 {
1
 {
2
     "_meta": {
2
     "_meta": {
3
         "hash": {
3
         "hash": {
4
-            "sha256": "4389fadf9b02e4cf8b8de26830e9ffa003e4414fe29778e11d1a07862e19c8da"
4
+            "sha256": "2fc31fe49a97d00c3e1f88f1aacb9aaaa7348bd39cc4e09df5a42018eb09a640"
5
         },
5
         },
6
         "pipfile-spec": 6,
6
         "pipfile-spec": 6,
7
         "requires": {
7
         "requires": {
88
             "index": "pypi",
88
             "index": "pypi",
89
             "version": "==0.1.0"
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
         "itsdangerous": {
91
         "itsdangerous": {
107
             "hashes": [
92
             "hashes": [
108
                 "sha256:321b033d07f2a4136d3ec762eac9f16a10ccd60f53c0c91af90217ace7ba1f19",
93
                 "sha256:321b033d07f2a4136d3ec762eac9f16a10ccd60f53c0c91af90217ace7ba1f19",
196
             "index": "pypi",
181
             "index": "pypi",
197
             "version": "==2.6.0"
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
         "six": {
192
         "six": {
200
             "hashes": [
193
             "hashes": [
201
                 "sha256:3350809f0555b11f552448330d0b52d5f24c91a322ea4a15ef22629740f3761c",
194
                 "sha256:3350809f0555b11f552448330d0b52d5f24c91a322ea4a15ef22629740f3761c",
203
             ],
196
             ],
204
             "version": "==1.12.0"
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
         "werkzeug": {
199
         "werkzeug": {
214
             "hashes": [
200
             "hashes": [
215
                 "sha256:c3fd7a7d41976d9f44db327260e263132466836cef6f91512889ed60ad26557c",
201
                 "sha256:c3fd7a7d41976d9f44db327260e263132466836cef6f91512889ed60ad26557c",

+ 31
- 1
assets/scss/style.scss Visa fil

3
 $black:       #000000;
3
 $black:       #000000;
4
 $white:       #ffffff;
4
 $white:       #ffffff;
5
 $blue:        #496893;
5
 $blue:        #496893;
6
-$red:         #ff0000;
6
+$red:         #d9534f;
7
 $light-gray:  #f5f5f5;
7
 $light-gray:  #f5f5f5;
8
 $medium-gray: #c8c8c8;
8
 $medium-gray: #c8c8c8;
9
 
9
 
46
   margin-bottom: 15px;
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
 /* layout */
79
 /* layout */
50
 
80
 
51
 .container {
81
 .container {

+ 16
- 0
yird/app.py Visa fil

2
 
2
 
3
 from flask_webpack import Webpack
3
 from flask_webpack import Webpack
4
 
4
 
5
+from yird.services.git import GitService
6
+
5
 from yird.services.posts import PostsService
7
 from yird.services.posts import PostsService
6
 
8
 
7
 from yird.settings import Settings
9
 from yird.settings import Settings
27
     }
29
     }
28
 
30
 
29
 
31
 
32
+@app.context_processor
33
+def inject_git_status():
34
+    return GitService.get_status()
35
+
36
+
30
 @app.route('/admin')
37
 @app.route('/admin')
31
 def index():
38
 def index():
32
     posts = PostsService.get_posts()
39
     posts = PostsService.get_posts()
61
 @app.route('/admin/generate')
68
 @app.route('/admin/generate')
62
 def generate():
69
 def generate():
63
     PostsService.generate_posts()
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
     return redirect(url_for('index'))
80
     return redirect(url_for('index'))
65
 
81
 
66
 if __name__ == "__main__":
82
 if __name__ == "__main__":

+ 47
- 0
yird/services/git.py Visa fil

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 Visa fil

27
           </a>
27
           </a>
28
         </li>
28
         </li>
29
       </ul>
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
     </header>
40
     </header>
31
     <main class="main">
41
     <main class="main">
32
       {% block content %}{% endblock %}
42
       {% block content %}{% endblock %}

+ 18
- 0
yird/templates/repo/index.html.j2 Visa fil

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 %}

Laddar…
Avbryt
Spara