Skip to content

Commit 87f7fdc

Browse files
committed
Simplify sync by cloning in a temporary directory
See elekto-io#72 and elekto-io#73
1 parent 01f044b commit 87f7fdc

File tree

3 files changed

+8
-11
lines changed

3 files changed

+8
-11
lines changed

console

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,8 @@ if __name__ == "__main__":
8181

8282
print('# ----------- Syncing the meta with the database ----------- #')
8383

84-
if not os.path.exists(backend.META) or not os.path.isdir(backend.META):
85-
backend.clone()
84+
backend.clone()
8685

87-
backend.pull()
8886

8987
print(sync(SESSION, meta.Election.all()))
9088
exit()

elekto/controllers/webhook.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,5 @@
2727
@csrf.exempt
2828
def webhook_sync():
2929
backend = meta.Meta(APP.config['META'])
30-
if not os.path.exists(backend.META) or not os.path.isdir(backend.META):
31-
backend.clone()
32-
else:
33-
backend.pull()
30+
backend.clone()
3431
return sync(SESSION, meta.Election.all())

elekto/models/meta.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
import os
1818
import random
19+
import subprocess
20+
import tempfile
1921
import flask as F
2022

2123
from datetime import datetime
@@ -32,7 +34,9 @@ class Meta:
3234
"""
3335

3436
def __init__(self, config):
35-
self.META = os.path.abspath(config['PATH'])
37+
# keep this, as it ties the directory to the object lifecycle
38+
self.TMPDIR = tempfile.TemporaryDirectory("elekto")
39+
self.META = self.TMPDIR.name
3640
self.ELECDIR = config['ELECDIR']
3741
self.REMOTE = config['REMOTE']
3842
self.BRANCH = config['BRANCH']
@@ -42,10 +46,8 @@ def __init__(self, config):
4246
".format(self.META, self.META)
4347

4448
def clone(self):
45-
os.system('{} clone -b {} -- {} {}'.format(self.git, self.BRANCH, self.REMOTE, self.META))
49+
subprocess.check_call('{} clone -b {} -- {} {}'.format(self.git, self.BRANCH, self.REMOTE, self.META))
4650

47-
def pull(self):
48-
os.system('{} pull --ff-only origin {}'.format(self.pref, self.BRANCH))
4951

5052

5153
class Election(Meta):

0 commit comments

Comments
 (0)