Browse Source

Better logging, there's no need for args here

tags/3.16
parent
commit
776838b685
Signed by: hristoast <me@hristos.triantafillou.us> GPG Key ID: 5FC7664AD47AA1C5
2 changed files with 28 additions and 23 deletions
  1. +1
    -1
      Makefile
  2. +27
    -22
      bin/seed_db.py

+ 1
- 1
Makefile View File

@@ -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



+ 27
- 22
bin/seed_db.py View File

@@ -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