Skip to content
This repository was archived by the owner on May 29, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion ringo/scripts/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
22 changes: 14 additions & 8 deletions ringo/scripts/fixture.py
Original file line number Diff line number Diff line change
@@ -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


Expand All @@ -8,7 +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):
Expand All @@ -17,10 +19,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])
39 changes: 24 additions & 15 deletions ringo/scripts/helpers.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,40 @@
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 = 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 = 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
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
'waitress',
'babel',
'formbar',
'invoke',
'dogpile.cache',
'passlib',
'python-dateutil',
Expand Down