Skip to content

Commit 179f99a

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

File tree

4 files changed

+8
-15
lines changed

4 files changed

+8
-15
lines changed

config.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,10 @@
8383
# application via gitops, see the design documentation [/docs/DESIGN.md] for
8484
# more detailed information on working.
8585
# - REMOTE : Remote repository url
86-
# - PATH : Where the meta repository is cloned (if development is local)
8786
# - DEPLOYMENT : mode of deployment (local, sidecar)
8887
META = {
8988
'REMOTE': env('META_REPO'),
9089
'ELECDIR': env('ELECTION_DIR'),
91-
'PATH': env('META_PATH', 'meta'),
9290
'DEPLOYMENT': env('META_DEPLOYMENT', 'local'),
9391
'BRANCH': env('META_BRANCH', 'main'),
9492
'SECRET': env('META_SECRET')

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 & 6 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,20 +34,18 @@ 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']
3943
self.SECRET = config['SECRET']
4044
self.git = '/usr/bin/git'
41-
self.pref = "/usr/bin/git --git-dir={}/.git --work-tree={}\
42-
".format(self.META, self.META)
4345

4446
def clone(self):
45-
os.system('{} clone -b {} -- {} {}'.format(self.git, self.BRANCH, self.REMOTE, self.META))
47+
subprocess.check_call([self.git, 'clone', '-b', self.BRANCH, '--', self.REMOTE, self.META])
4648

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

5050

5151
class Election(Meta):

0 commit comments

Comments
 (0)