From df12af99891b376f04235d5774ea9c8435a6254f Mon Sep 17 00:00:00 2001 From: Maximilian Krambach Date: Tue, 25 Jul 2017 16:46:15 +0200 Subject: [PATCH 1/3] remove invoke from code and dependency --- ringo/scripts/db.py | 1 - ringo/scripts/fixture.py | 23 ++++++++++++++--------- ringo/scripts/helpers.py | 39 ++++++++++++++++++++++----------------- setup.py | 1 - 4 files changed, 36 insertions(+), 28 deletions(-) diff --git a/ringo/scripts/db.py b/ringo/scripts/db.py index e089d6ad..d74d973d 100644 --- a/ringo/scripts/db.py +++ b/ringo/scripts/db.py @@ -6,7 +6,6 @@ from sqlalchemy import engine_from_config import transaction -from invoke import run from alembic.config import Config from alembic import command diff --git a/ringo/scripts/fixture.py b/ringo/scripts/fixture.py index b307f976..05c27faa 100644 --- a/ringo/scripts/fixture.py +++ b/ringo/scripts/fixture.py @@ -1,4 +1,4 @@ -from invoke import run +from subprocess import Popen, PIPE from ringo.scripts.helpers import get_db, get_package_name, get_fixtures @@ -8,8 +8,9 @@ def handle_fixture_load_command(args): print "Loading data in %s" % db for fixture, modul in get_fixtures(args.app, args.path): print "Loading fixture %s" % fixture - run("%s-admin db loaddata --loadbyid --config %s %s %s" % (appname, args.config, modul, fixture)) - + command_name = appname + "-admin" + cmd = Popen([command_name,"db","loaddata","--loadbyid","--config", + args.config,modul,fixture]) def handle_fixture_save_command(args): appname = get_package_name(args.config) @@ -17,10 +18,14 @@ def handle_fixture_save_command(args): print "Saving data in %s" % db for fixture, modul in get_fixtures(args.app, args.path): print "Saving fixture %s" % fixture - try: - run("%s-admin db savedata --include-relations --config %s %s > %s" % (appname, args.config, modul, fixture), hide="stderr") - except: + command_name = appname + "-admin" + cmd = Popen([command_name, "db", "savedata", "--include-relations", + "--config", args.config, modul, fixture], stderr=PIPE]) + stdout, stderr = cmd.communicate() + if stderr: print "Ups... Trying again without relations included" - run("%s-admin db savedata --config %s %s > %s" % (appname, args.config, modul, fixture)) - run("python -m json.tool %s > %s.tmp" % (fixture, fixture)) - run("mv %s.tmp %s" % (fixture, fixture)) + cmd = Popen([command_name, "db", "savedata", "--config", + args.config, modul, fixture], stderr=PIPE]) + cmd = Popen(["python", "-m", "json.tool", fixture, ">", + fixture + ".tmp"]) + cmd = Popen(["mv", fixture + ".tmp", fixture]) diff --git a/ringo/scripts/helpers.py b/ringo/scripts/helpers.py index 3f372133..464ae211 100644 --- a/ringo/scripts/helpers.py +++ b/ringo/scripts/helpers.py @@ -1,31 +1,36 @@ import os -from invoke import run +from subprocess import PIPE, Popen import pkg_resources def get_package_location(name): return pkg_resources.get_distribution(name).location def get_package_name(config_file): - result = run("sed -n 's|^use = egg:\\([[:graph:]]*\\).*|\\1|p' %s | head -1" % config_file, hide="out") - return result.stdout.strip() - + process = subprocess.Popen(["sed", + "-n", + "'s|^use = egg:\\([[:graph:]]*\\).*|\\1|p'", + config_file], + stdout=PIPE) + stdout, stderr = process.communicate() + return stdout def get_db(config_file): - result = run("sed -n 's|^sqlalchemy.url.*//.*@.*/\\([[:graph:]]*\\).*|\\1|p' %s" % config_file, hide="out") - return result.stdout.strip() - + process = subprocess.Popen(["sed", + "-n", + "'s|^sqlalchemy.url.*//.*@.*/\\([[:graph:]]*\\).*|\\1|p'", + config_file], + stdout=PIPE) + stdout, stderr = process.communicate() + return stdout def get_fixtures(appname, path=None): - if path: - try: - result = run("ls %s/*.json" % path, hide="out").stdout.strip() - except Exception as e: - return [] - else: - apppath = os.path.join(get_package_location(appname), appname) - result = run("ls %s/fixtures/*.json" - % apppath, hide="out").stdout.strip() + files = [] + if not path: + path = os.path.join(get_package_location(appname), appname) + for file_ in os.listdir(path): + if file_.endswith(".json"): + files.append(file_) fixtures = [] - for fixture in sorted(result.split("\n")): + for fixture in sorted(files): fixtures.append((fixture, "_".join(fixture.split("_")[1:]).split(".")[0])) return fixtures diff --git a/setup.py b/setup.py index a1987c2a..8864595b 100644 --- a/setup.py +++ b/setup.py @@ -21,7 +21,6 @@ 'waitress', 'babel', 'formbar', - 'invoke', 'dogpile.cache', 'passlib', 'python-dateutil', From 6e47b12a36afcdc60960bcbd1f3b7845ee652ed0 Mon Sep 17 00:00:00 2001 From: Maximilian Krambach Date: Tue, 25 Jul 2017 18:18:44 +0200 Subject: [PATCH 2/3] fixed some syntax and indentation errors --- ringo/scripts/fixture.py | 5 +++-- ringo/scripts/helpers.py | 24 ++++++++++++++---------- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/ringo/scripts/fixture.py b/ringo/scripts/fixture.py index 05c27faa..9c53f448 100644 --- a/ringo/scripts/fixture.py +++ b/ringo/scripts/fixture.py @@ -12,6 +12,7 @@ def handle_fixture_load_command(args): cmd = Popen([command_name,"db","loaddata","--loadbyid","--config", args.config,modul,fixture]) + def handle_fixture_save_command(args): appname = get_package_name(args.config) db = get_db(args.config) @@ -20,12 +21,12 @@ def handle_fixture_save_command(args): print "Saving fixture %s" % fixture command_name = appname + "-admin" cmd = Popen([command_name, "db", "savedata", "--include-relations", - "--config", args.config, modul, fixture], stderr=PIPE]) + "--config", args.config, modul, fixture], stderr=PIPE) stdout, stderr = cmd.communicate() if stderr: print "Ups... Trying again without relations included" cmd = Popen([command_name, "db", "savedata", "--config", - args.config, modul, fixture], stderr=PIPE]) + args.config, modul, fixture], stderr=PIPE) cmd = Popen(["python", "-m", "json.tool", fixture, ">", fixture + ".tmp"]) cmd = Popen(["mv", fixture + ".tmp", fixture]) diff --git a/ringo/scripts/helpers.py b/ringo/scripts/helpers.py index 464ae211..c3e8179d 100644 --- a/ringo/scripts/helpers.py +++ b/ringo/scripts/helpers.py @@ -2,27 +2,31 @@ from subprocess import PIPE, Popen import pkg_resources + def get_package_location(name): return pkg_resources.get_distribution(name).location + def get_package_name(config_file): - process = subprocess.Popen(["sed", - "-n", - "'s|^use = egg:\\([[:graph:]]*\\).*|\\1|p'", - config_file], - stdout=PIPE) + process = Popen(["sed", + "-n", + "'s|^use = egg:\\([[:graph:]]*\\).*|\\1|p'", + config_file], + stdout=PIPE) stdout, stderr = process.communicate() return stdout + def get_db(config_file): - process = subprocess.Popen(["sed", - "-n", - "'s|^sqlalchemy.url.*//.*@.*/\\([[:graph:]]*\\).*|\\1|p'", - config_file], - stdout=PIPE) + process = Popen(["sed", + "-n", + "'s|^sqlalchemy.url.*//.*@.*/\\([[:graph:]]*\\).*|\\1|p'", + config_file], + stdout=PIPE) stdout, stderr = process.communicate() return stdout + def get_fixtures(appname, path=None): files = [] if not path: From 0eb8aa8f27a1db54e550bc0aa8e7a9cd923bb56a Mon Sep 17 00:00:00 2001 From: Maximilian Krambach Date: Wed, 26 Jul 2017 12:32:54 +0200 Subject: [PATCH 3/3] removing duplicate quotes in helpers.py --- ringo/scripts/helpers.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ringo/scripts/helpers.py b/ringo/scripts/helpers.py index c3e8179d..8cea0b2b 100644 --- a/ringo/scripts/helpers.py +++ b/ringo/scripts/helpers.py @@ -10,7 +10,7 @@ def get_package_location(name): def get_package_name(config_file): process = Popen(["sed", "-n", - "'s|^use = egg:\\([[:graph:]]*\\).*|\\1|p'", + "s|^use = egg:\\([[:graph:]]*\\).*|\\1|p", config_file], stdout=PIPE) stdout, stderr = process.communicate() @@ -20,7 +20,7 @@ def get_package_name(config_file): def get_db(config_file): process = Popen(["sed", "-n", - "'s|^sqlalchemy.url.*//.*@.*/\\([[:graph:]]*\\).*|\\1|p'", + "s|^sqlalchemy.url.*//.*@.*/\\([[:graph:]]*\\).*|\\1|p", config_file], stdout=PIPE) stdout, stderr = process.communicate()