예제 #1
0
파일: clonedb.py 프로젝트: synw/django-dex
 def handle(self, *args, **options):
     try:
         ex = Exporter()
     except Exception as e:
         err.new(e, self.handle, "Can not initialize exporter")
     if options["archive"] is True:
         ex.archive_replicas()
     source = options["source"]
     dest = options["dest"]
     applist = options["applist"]
     if options["migrate"] is not False:
         try:
             call_command("migrate", "--database=" + dest)
         except Exception as e:
             err.new(e, self.handle,
                     "Can not migrate destination database " + dest)
     if applist is not None:
         applist = str.split(options["applist"], ",")
     try:
         ex.set_local()
         ex.clone(source,
                  dest,
                  applist=applist,
                  verbosity=int(options["verbosity"]))
     except Exception as e:
         err.new(e, self.handle, "Can not clone database")
     if err.exists:
         err.throw()
예제 #2
0
def _write_file(slug, html):
    """
    Writes a table's html to a file
    """
    # check directories
    folderpath = safe_join(settings.BASE_DIR, "templates/tabular")
    if not os.path.isdir(folderpath):
        try:
            os.makedirs(folderpath)
        except Exception as e:
            err.new(e)
    endpath = "tables"
    tablesdir_path = safe_join(settings.BASE_DIR,
                               "templates/tabular/" + endpath)
    if not os.path.isdir(tablesdir_path):
        try:
            os.makedirs(tablesdir_path)
        except Exception as e:
            err.new(e)
    # check file
    filepath = tablesdir_path + "/" + slug + ".html"
    #~ write the file
    try:
        filex = open(filepath, "w")
        filex.write(html)
        filex.close()
    except Exception as e:
        err.new(e)
    if err.exists:
        err.throw()
예제 #3
0
 def handle(self, *args, **options):
     """
     Run a generator
     """
     app = options["app"]
     quiet = int(options["quiet"])
     #runall = int(options["all"])
     subgenerator = None
     if "." in app:
         l = app.split(".")
         app = l[0]
         subgenerator = l[1]
     try:
         generator = GENERATORS[app]
         if subgenerator is not None:
             generator = load_generator(app, subgenerator)
             if generator is None:
                 err.new("Subgenerator " + subgenerator + " not found")
                 err.trace()
                 return
     except Exception as e:
         err.new(e, "Generator not found")
         err.report()
         err.throw()
         return
     if quiet > 0:
         print("Running generator", app)
     try:
         generator()
     except Exception as e:
         err.new(e)
     """
     try:
         last_run_q = get_last_run_q()
     except Exception:
         pass
     if runall == 0:
         try:
             events_q = get_events_q()
         except Exception as e:
             err.new(e)
         try:
             events_q = get_changes_events(events_q, last_run_q)
         except Exception as e:
             err.new(e)
     else:
         try:
             events_q = MEvent.objects.all()
         except Exception as e:
             err.new(e)
     try:
         generator(events=events_q)
     except Exception as e:
         err.new(e)
     """
     if err.exists:
         if settings.DEBUG is True:
             err.throw()
         else:
             err.report()
예제 #4
0
 def create(self, slug, dataset, dashboard=None):
     ds = cf.load_data_(dataset, "x", "y")
     if ds is None:
         err.new(self.new,
                 "No dataframe set: please provide one in parameter")
         err.throw()
     html = self._html(slug, ds.df)
     _write_file(slug, html, "datatable", dashboard)
예제 #5
0
 def _save_instance(self, model, instance, dbdest):
     try:
         self._disable_auto_now_fields(model)
         instance.save(using=dbdest, force_insert=True)
     except IntegrityError as e:
         msg = "ERROR inserting", instance, "- ", model.__name__
         err.new(e, self._save_instance, msg)
         err.throw()
     return
예제 #6
0
def rprint(*args):
    msg = ""
    for output in args:
        msg = msg + " " + str(output)
    if settings.DEBUG is True:
        print("[Remote terminal]", strip_tags(msg))
    try:
        publish(msg, event_class="__command__", channel=COMMAND_CHANNEL)
    except Exception as e:
        err.new(e, rprint, "Can not publish message for remote print")
        err.throw()
예제 #7
0
 def simple(self, slug, data, dashboard=None, verbose=True):
     """
     Generates a single sparkline
     """
     html = self._simple_html(data)
     _write_file(slug, html, "sparkline", dashboard)
     if err.exists:
         if settings.DEBUG is True:
             err.trace()
         else:
             err.throw()
     if verbose is True:
         print("[x] Generated sparkline " + slug)
예제 #8
0
 def _progress_html(self, number, progress, legend, unit, thresholds, icon,
                    color):
     """
     Generate html for progress bar number widget
     """
     if unit is None:
         unit = ""
     if thresholds:
         if progress is None:
             err.new(self._progress_html,
                     "Please provide a progress number to use thresholds")
             err.throw()
         color = "green"
         if progress[0] <= thresholds["low"]:
             color = "red"
         elif progress[0] < thresholds["high"] and progress[0] > thresholds[
                 "low"]:
             color = "orange"
     ibg = " bg-" + color
     if icon is None:
         icon = '<span class="info-box-icon' + ibg + \
             '"><i class="fa fa-thumbs-o-up"></i></span>'
     else:
         icon = '<span class="info-box-icon' + ibg + \
             '"><i class="fa fa-' + icon + '"></i></span>'
     if unit != "":
         unit = '<span class="unit">&nbsp;' + unit + '</span>'
     css_class = ""
     wrapper = '<div class="info-box bg-' + color + '">'
     res = wrapper + icon + '\n<div class="info-box-content">'
     if legend is not None:
         res = res + '\n<span class="info-box-text ' + \
             css_class + '">' + legend + '</span>'
     res = res + '\n<span class="info-box-number">' + \
         str(number) + ' ' + unit + '</span>'
     res += '<div class="progress">'
     res += '<div class="progress-bar" style="width:' + \
         str(progress[0]) + '%"></div>'
     res += '</div>'
     res += '<span class="progress-description">' + \
         progress[1] + '</span>'
     res = res + "</div></div>"
     return res
예제 #9
0
 def handle(self, *args, **options):
     app = options["app"]
     # check if module exists
     mod = importlib.util.find_spec(app)
     if mod is None:
         err.new("No module named " + app)
         err.throw()
         return
     # get paths
     origin = os.path.dirname(chartflo.__file__) + "/templates/dashboards"
     dest = os.getcwd() + "/" + app + "/templates/dashboards"
     # check directories
     if not os.path.exists(dest):
         print("Creating directories")
         os.makedirs(dest, exist_ok=True)
     # copy
     print("Copying base templates", "=>", dest)
     try:
         copytree(origin, dest)
     except FileExistsError:
         err.new(
             "The directory",
             app + "/templates/dashboards/base already exists, aborting")
         err.throw()
         return
     # rename stuff
     print("Configuring templates")
     src = dest + "/base"
     des = dest + "/" + app
     shutil.move(src, des)
     # fic imports in files
     config_template(des + "/index.html", app)
     # create dashboard object in the database
     print("Creating dashboard object in the database")
     Dashboard.objects.get_or_create(slug=app, title=app)
     # end msg
     print("[" + colors.green("Ok") + "] Dashboard base template is in",
           app + "/templates/dashboards")
예제 #10
0
 def simple(self,
            slug,
            value,
            legend=None,
            unit=None,
            dashboard=None,
            color="green",
            icon=None,
            verbose=True,
            sparkline=None,
            sparkline_options={}):
     """
     Generates a single number widget
     """
     html = self._simple_html(value, legend, unit, icon, color, sparkline,
                              sparkline_options)
     _write_file(slug, html, "number", dashboard)
     if err.exists:
         if settings.DEBUG is True:
             err.trace()
         else:
             err.throw()
     if verbose is True:
         print("[x] Generated number " + slug)
예제 #11
0
 def progress(self,
              slug,
              value,
              progress,
              legend=None,
              unit=None,
              thresholds={},
              dashboard=None,
              color="green",
              icon=None,
              verbose=True):
     """
     Generates a number widget with a progress bar
     """
     html = self._progress_html(value, progress, legend, unit, thresholds,
                                icon, color)
     _write_file(slug, html, "number", dashboard)
     if err.exists:
         if settings.DEBUG is True:
             err.trace()
         else:
             err.throw()
     if verbose is True:
         print("[x] Generated number " + slug)