Skip to content

Commit

Permalink
Merge pull request #76 from elekto-io/subprocess
Browse files Browse the repository at this point in the history
Replace all os.system() calls with suprocess.run()
  • Loading branch information
jberkus authored Oct 6, 2022
2 parents 01f044b + ef2977e commit a9e0c64
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM python:3.6.12-stretch
FROM python:3.7-stretch

WORKDIR /app

Expand Down
7 changes: 3 additions & 4 deletions elekto/models/meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import os
import random
import subprocess
import flask as F

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

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

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


class Election(Meta):
Expand Down
5 changes: 3 additions & 2 deletions test/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
# Author(s): Manish Sahani <[email protected]>

import os
import subprocess
import sys
import pytest
import pandas as pd
Expand All @@ -37,14 +38,14 @@
def client():
# Generate Database
db = os.path.abspath('./test.db')
os.system('touch {}'.format(db))
subprocess.run(['touch', db], check=True)

with APP.test_client() as client:
with APP.app_context():
migrate(APP.config['DATABASE_URL'])
yield client

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


Expand Down

0 comments on commit a9e0c64

Please sign in to comment.