Skip to content

Commit

Permalink
adaptating linux
Browse files Browse the repository at this point in the history
  • Loading branch information
alunAlunnnnn committed Sep 24, 2021
1 parent a77748b commit 36414b1
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 6 deletions.
5 changes: 5 additions & 0 deletions _initial_sqlite.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from sys_monitor.utils._db_sqlite import SqliteDB
import click

config = {
"sqlite": {
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions _update_monitor_value.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import click

from sys_monitor._get_sys_information import get_sys_info
from sys_monitor.utils._db_sqlite import SqliteDB

Expand Down
2 changes: 2 additions & 0 deletions sys_monitor_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
Expand Down
16 changes: 13 additions & 3 deletions utils/_db_sqlite.py
Original file line number Diff line number Diff line change
@@ -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:
Expand Down Expand Up @@ -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:
Expand All @@ -132,7 +141,8 @@ def conn(self):

return conn

@cached_property
# @cached_property
# @property
def cur(self):
return self.conn.cursor()

Expand Down
8 changes: 5 additions & 3 deletions utils/_file_process.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import os
from functools import cached_property
# from functools import cached_property


class FileProcessor:
Expand All @@ -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)

Expand Down

0 comments on commit 36414b1

Please sign in to comment.