From 36414b1baa5ee86a75b1a7d23c96f6ca7f734cd9 Mon Sep 17 00:00:00 2001 From: alun <517308447@qq.com> Date: Fri, 24 Sep 2021 15:28:21 +0800 Subject: [PATCH] adaptating linux --- _initial_sqlite.py | 5 +++++ _update_monitor_value.py | 2 ++ sys_monitor_cli.py | 2 ++ utils/_db_sqlite.py | 16 +++++++++++++--- utils/_file_process.py | 8 +++++--- 5 files changed, 27 insertions(+), 6 deletions(-) diff --git a/_initial_sqlite.py b/_initial_sqlite.py index 21d126f..a99b0e7 100644 --- a/_initial_sqlite.py +++ b/_initial_sqlite.py @@ -1,4 +1,5 @@ from sys_monitor.utils._db_sqlite import SqliteDB +import click config = { "sqlite": { @@ -122,6 +123,10 @@ def init_sqlite(db_file): # init sqlite handler sqlite_handler = SqliteDB(db_file) + # click.echo(f"Sqlite {sqlite_handler.cur}") + # click.echo(f"Sqlite {type(sqlite_handler.cur)}") + # click.echo(f"Sqlite {sqlite_handler.cur.__dict__}") + # create tables for table_name, fields in sqlite_config.get("tables").items(): sqlite_handler.create_table(table_name, fields) diff --git a/_update_monitor_value.py b/_update_monitor_value.py index 1c808c3..ebfb717 100644 --- a/_update_monitor_value.py +++ b/_update_monitor_value.py @@ -1,3 +1,5 @@ +import click + from sys_monitor._get_sys_information import get_sys_info from sys_monitor.utils._db_sqlite import SqliteDB diff --git a/sys_monitor_cli.py b/sys_monitor_cli.py index e00b0ae..0ef4034 100644 --- a/sys_monitor_cli.py +++ b/sys_monitor_cli.py @@ -60,9 +60,11 @@ def run(db_file, loop, second): def _run(db_file, loop): if not db_file.endswith(".db"): db_file = f"{db_file}.db" + try: if not loop: click.echo("Start collect system info.") + update_monitor_value_sqlite(db_file) if not loop: click.echo("Success collect system info.") diff --git a/utils/_db_sqlite.py b/utils/_db_sqlite.py index 9020108..6dedf47 100644 --- a/utils/_db_sqlite.py +++ b/utils/_db_sqlite.py @@ -1,6 +1,11 @@ import sqlite3 + +import click + from sys_monitor.utils._file_process import FileProcessor -from functools import cached_property + + +# from functools import cached_property class SqliteDB: @@ -117,11 +122,15 @@ def __str__(self): def __init__(self, sqlite_db_file): self.file_handler = FileProcessor(sqlite_db_file) + self.conn = self.conn() + self.cur = self.conn.cursor() + SqliteDB.instance = self self.tables = [] - @cached_property + # @cached_property + # @property def conn(self): # create sqlite db if not self.file_handler.exists: @@ -132,7 +141,8 @@ def conn(self): return conn - @cached_property + # @cached_property + # @property def cur(self): return self.conn.cursor() diff --git a/utils/_file_process.py b/utils/_file_process.py index c2bffab..35234c8 100644 --- a/utils/_file_process.py +++ b/utils/_file_process.py @@ -1,5 +1,5 @@ import os -from functools import cached_property +# from functools import cached_property class FileProcessor: @@ -23,11 +23,13 @@ def type(self): return "unknown" return None - @cached_property + # @cached_property + @property def dirname(self): return os.path.dirname(self.file) - @cached_property + # @cached_property + @property def basename(self): return os.path.basename(self.file)