Skip to content

Commit a9e0c64

Browse files
authored
Merge pull request #76 from elekto-io/subprocess
Replace all os.system() calls with suprocess.run()
2 parents 01f044b + ef2977e commit a9e0c64

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM python:3.6.12-stretch
1+
FROM python:3.7-stretch
22

33
WORKDIR /app
44

elekto/models/meta.py

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

1717
import os
1818
import random
19+
import subprocess
1920
import flask as F
2021

2122
from datetime import datetime
@@ -38,14 +39,12 @@ def __init__(self, config):
3839
self.BRANCH = config['BRANCH']
3940
self.SECRET = config['SECRET']
4041
self.git = '/usr/bin/git'
41-
self.pref = "/usr/bin/git --git-dir={}/.git --work-tree={}\
42-
".format(self.META, self.META)
4342

4443
def clone(self):
45-
os.system('{} clone -b {} -- {} {}'.format(self.git, self.BRANCH, self.REMOTE, self.META))
44+
subprocess.run([self.git, 'clone', '-b', self.BRANCH, '--', self.REMOTE, self.META], check=True)
4645

4746
def pull(self):
48-
os.system('{} pull --ff-only origin {}'.format(self.pref, self.BRANCH))
47+
subprocess.run([self.git, '--git-dir', '{}/.git'.format(self.META),'--work-tree', self.META, 'pull', '--ff-only', 'origin', self.BRANCH], check=True)
4948

5049

5150
class Election(Meta):

test/test_main.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
# Author(s): Manish Sahani <[email protected]>
1616

1717
import os
18+
import subprocess
1819
import sys
1920
import pytest
2021
import pandas as pd
@@ -37,14 +38,14 @@
3738
def client():
3839
# Generate Database
3940
db = os.path.abspath('./test.db')
40-
os.system('touch {}'.format(db))
41+
subprocess.run(['touch', db], check=True)
4142

4243
with APP.test_client() as client:
4344
with APP.app_context():
4445
migrate(APP.config['DATABASE_URL'])
4546
yield client
4647

47-
os.system('rm {}'.format(db))
48+
os.unlink(db)
4849
# os.system('rm -rf {}'.format(APP.config['META']['PATH']))
4950

5051

0 commit comments

Comments
 (0)