Browse Source

Better logging, there's no need for args here

pull/549/head
parent
commit
776838b685
Signed by: hristoast GPG Key ID: 5FC7664AD47AA1C5
  1. 2
      Makefile
  2. 49
      bin/seed_db.py

2
Makefile

@ -35,7 +35,7 @@ refreshdb:
sudo -u momwdb dropdb momwdb && sudo -u momwdb createdb momwdb
seeddb:
$(proj_dir)/bin/seed_db.py --full
$(proj_dir)/bin/seed_db.py
reset: clean refreshdb migrate seeddb

49
bin/seed_db.py

@ -1,4 +1,5 @@
#!/usr/bin/env python3
import logging
import sys
import os
import pendulum
@ -61,28 +62,32 @@ def user_factory():
def main():
def _run(arg, func, earg=None):
if "--{}".format(arg) in sys.argv or "--full" in sys.argv:
print("Running {}() ...".format(func.__name__), end=" ")
if earg:
func(earg)
else:
func()
print("Seed Done!")
print("... Starting {} db seed ...".format(settings.PROJECT_NAME.upper()))
_run("site", site_factory)
_run("user", user_factory)
_run("blog-cat", blog_category_factory)
_run("blog-tag", blog_tag_factory)
_run("blog-entry", blog_entry_factory)
_run("media", media_factory)
_run("mod-cat", mod_cats)
_run("mod-tag", mod_tags)
_run("mods", mods)
_run("mod-plugins", mod_plugins)
_run("mod-lists", mod_lists)
print("... Finished {} db seed!".format(settings.PROJECT_NAME.upper()))
logging.basicConfig(
format="%(asctime)s : %(message)s", level=logging.INFO, stream=sys.stdout
)
logger = logging.getLogger()
info = logger.info
def run(func, earg=None):
info("Running {}() ...".format(func.__name__))
if earg:
func(earg)
else:
func()
info("Starting {} db seed ...".format(settings.PROJECT_NAME.upper()))
run(site_factory)
run(user_factory)
run(blog_category_factory)
run(blog_tag_factory)
run(blog_entry_factory)
run(media_factory)
run(mod_cats)
run(mod_tags)
run(mods)
run(mod_plugins)
run(mod_lists)
info("Finished {} db seed!".format(settings.PROJECT_NAME.upper()))
if __name__ == "__main__":

Loading…
Cancel
Save