コード例 #1
0
ファイル: commands.py プロジェクト: amorton/cass-check
 def _write_report(self, receipt_files):
     """Writes the report to disk for the ``receipt_files`` map of 
     :class:`task.TastReceipt` to list of file paths. 
     """
     
     # Render the report
     
     template = Template(text=pkg_resources.resource_string(
         "cass_check", "templates/report.mako"))
     index_path = os.path.join(self.report_dir, "index.html")
     self.log.info("Writing report index to {index_path}".format(
         index_path=index_path))
     with open(index_path, "w") as f:
         f.write(template.render(receipt_files=receipt_files))
         
     # copy assets
     for asset_name in pkg_resources.resource_listdir("cass_check", 
         "assets/"):
         
         res_name = "assets/{asset_name}".format(asset_name=asset_name)
         dest = os.path.join(self.report_dir, res_name)
         self.log.info("Copying report asset {asset_name} to "\
             "{dest}".format(asset_name=asset_name, dest=dest))
             
         with pkg_resources.resource_stream("cass_check", res_name) as src:
             file_util.ensure_dir(os.path.dirname(dest))
             with open(dest, "w") as f:
                 f.write(src.read())
     
     return index_path
コード例 #2
0
ファイル: commands.py プロジェクト: amorton/cass-check
    def _write_report(self, receipt_files):
        """Writes the report to disk for the ``receipt_files`` map of 
        :class:`task.TastReceipt` to list of file paths. 
        """

        # Render the report

        template = Template(text=pkg_resources.resource_string(
            "cass_check", "templates/report.mako"))
        index_path = os.path.join(self.report_dir, "index.html")
        self.log.info("Writing report index to {index_path}".format(
            index_path=index_path))
        with open(index_path, "w") as f:
            f.write(template.render(receipt_files=receipt_files))

        # copy assets
        for asset_name in pkg_resources.resource_listdir(
                "cass_check", "assets/"):

            res_name = "assets/{asset_name}".format(asset_name=asset_name)
            dest = os.path.join(self.report_dir, res_name)
            self.log.info("Copying report asset {asset_name} to "\
                "{dest}".format(asset_name=asset_name, dest=dest))

            with pkg_resources.resource_stream("cass_check", res_name) as src:
                file_util.ensure_dir(os.path.dirname(dest))
                with open(dest, "w") as f:
                    f.write(src.read())

        return index_path
コード例 #3
0
ファイル: task.py プロジェクト: amorton/cass-check
    def __init__(self, args):
        self.args = args
        self.task_dir = os.path.abspath(os.path.join(self.args.check_dir, self.name))

        file_util.ensure_dir(self.task_dir)
        self.log.debug("Using output dir {self.task_dir} for task " "{self.name}".format(self=self))
        self.receipt = TaskReceipt(self.name, self.task_dir)
コード例 #4
0
def logging_config(access_log=None,
                   debug_log=None,
                   info_log=None,
                   warn_log=None,
                   err_log=None,
                   log_level=None):
    if access_log is not None:
        ensure_dir(os.path.dirname(access_log))
        h = TimedRotatingFileHandler(access_log, "D")
        h.setLevel(logging.INFO)
        h.setFormatter(formatter)
        logging.getLogger("tornado.access").addHandler(h)

    handlers = []

    def add_handler(filename, level):
        ensure_dir(os.path.dirname(filename))
        h = TimedRotatingFileHandler(filename, "D", encoding="utf8")
        h.setLevel(level)
        h.setFormatter(formatter)
        handlers.append(h)

    if debug_log is not None:
        add_handler(debug_log, logging.DEBUG)
    if info_log is not None:
        add_handler(info_log, logging.INFO)
    if warn_log is not None:
        add_handler(warn_log, logging.WARN)
    if err_log is not None:
        add_handler(err_log, logging.ERROR)

    root_logger = logging.root
    root_logger.setLevel(logLevel[log_level])
    for h in handlers:
        root_logger.addHandler(h)
コード例 #5
0
ファイル: task.py プロジェクト: amorton/cass-check
    def __init__(self, args):
        self.args = args
        self.task_dir = os.path.abspath(
            os.path.join(self.args.check_dir, self.name))

        file_util.ensure_dir(self.task_dir)
        self.log.debug("Using output dir {self.task_dir} for task "\
            "{self.name}".format(self=self))
        self.receipt = TaskReceipt(self.name, self.task_dir)
コード例 #6
0
ファイル: scripts.py プロジェクト: amorton/cass-check
def validate_global_args(args):

    log = logging.getLogger(__name__)

    file_util.ensure_dir(args.output_base)

    if not args.check_dir:
        args.check_dir = os.path.join(args.output_base, args.check_name)
    args.check_dir = os.path.abspath(args.check_dir)
    log.info("Output directory is {args.check_dir}".format(args=args))
    file_util.ensure_dir(args.check_dir)

    return
コード例 #7
0
ファイル: scripts.py プロジェクト: amorton/cass-check
def validate_global_args(args):

    log = logging.getLogger(__name__)
        
    file_util.ensure_dir(args.output_base)
    
    if not args.check_dir:
        args.check_dir = os.path.join(args.output_base, args.check_name)
    args.check_dir = os.path.abspath(args.check_dir)
    log.info("Output directory is {args.check_dir}".format(args=args))
    file_util.ensure_dir(args.check_dir)

    return
コード例 #8
0
ファイル: commands.py プロジェクト: amorton/cass-check
 def _on_before_tasks(self):
     """Called before the tasks are created for the command. 
     
     Changes to the args should be made here. For example setting the 
     output dir for this command.
     """
     
     # update the output dir 
     orig_check_dir = self.args.check_dir
     self.args.check_dir = os.path.abspath(os.path.join(
         self.args.check_dir, self.name))
     file_util.ensure_dir(self.args.check_dir)
     
     self.log.debug("For command {command.name} set check_dir to "\
         "{command.args.check_dir}".format(command=self))
     return
コード例 #9
0
ファイル: commands.py プロジェクト: amorton/cass-check
    def _on_before_tasks(self):
        """Called before the tasks are created for the command. 
        
        Changes to the args should be made here. For example setting the 
        output dir for this command.
        """

        # update the output dir
        orig_check_dir = self.args.check_dir
        self.args.check_dir = os.path.abspath(
            os.path.join(self.args.check_dir, self.name))
        file_util.ensure_dir(self.args.check_dir)

        self.log.debug("For command {command.name} set check_dir to "\
            "{command.args.check_dir}".format(command=self))
        return
コード例 #10
0
ファイル: commands.py プロジェクト: amorton/cass-check
 def _copy_receipt_files(self, receipt_files):
     """Copy the files for each receipt in ``receipt_files`` to the 
     tasks/ dir in the report. 
     
     Returns a dict of {receipt : [report_file]} where report_file is 
     a relative path under the report."""
     
     report_files = {}
     for receipt, paths in receipt_files.iteritems():
         report_files[receipt] = []
         
         for src_path in paths:
             _, src_name = os.path.split(src_path)
             rel_path = os.path.join("tasks", src_name)
             dest_path = os.path.join(self.report_dir, rel_path)
             
             file_util.ensure_dir(os.path.dirname(dest_path))
             shutil.copy2(src_path, dest_path)
             report_files[receipt].append(rel_path)
     return report_files
コード例 #11
0
ファイル: commands.py プロジェクト: amorton/cass-check
    def _copy_receipt_files(self, receipt_files):
        """Copy the files for each receipt in ``receipt_files`` to the 
        tasks/ dir in the report. 
        
        Returns a dict of {receipt : [report_file]} where report_file is 
        a relative path under the report."""

        report_files = {}
        for receipt, paths in receipt_files.iteritems():
            report_files[receipt] = []

            for src_path in paths:
                _, src_name = os.path.split(src_path)
                rel_path = os.path.join("tasks", src_name)
                dest_path = os.path.join(self.report_dir, rel_path)

                file_util.ensure_dir(os.path.dirname(dest_path))
                shutil.copy2(src_path, dest_path)
                report_files[receipt].append(rel_path)
        return report_files
コード例 #12
0
ファイル: commands.py プロジェクト: amorton/cass-check
    def __init__(self, args):
        self.log = logging.getLogger("%s.%s" % (__name__, "ReportCommand"))
        self.args = args

        self.report_dir = os.path.join(self.args.check_dir, self.name)
        file_util.ensure_dir(self.report_dir)
コード例 #13
0
 def add_handler(filename, level):
     ensure_dir(os.path.dirname(filename))
     h = TimedRotatingFileHandler(filename, "D", encoding="utf8")
     h.setLevel(level)
     h.setFormatter(formatter)
     handlers.append(h)
コード例 #14
0
ファイル: commands.py プロジェクト: amorton/cass-check
    def __init__(self, args):
        self.log = logging.getLogger("%s.%s" % (__name__, "ReportCommand"))
        self.args = args

        self.report_dir = os.path.join(self.args.check_dir, self.name)
        file_util.ensure_dir(self.report_dir)