Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
Owo Sugiana
/
payment-report
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit eb31b078
authored
Jul 26, 2022
by
Owo Sugiana
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
Bug fixed thread di Windows
1 parent
ffcd6afc
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
21 deletions
payment_report/scripts/log2db.py
payment_report/scripts/log2db.py
View file @
eb31b07
...
@@ -44,23 +44,24 @@ class Pantau(FileSystemEventHandler):
...
@@ -44,23 +44,24 @@ class Pantau(FileSystemEventHandler):
set_log_file
(
event
.
src_path
)
set_log_file
(
event
.
src_path
)
def
save_log
(
line
):
def
read_log
(
log_file
,
db_url
):
line
=
line
.
rstrip
()
def
save_log
(
line
):
match
=
REGEX
.
search
(
line
)
line
=
line
.
rstrip
()
if
not
match
:
match
=
REGEX
.
search
(
line
)
return
if
not
match
:
print
([
line
])
return
db_session
=
my_registry
[
'db_session'
]
print
([
line
])
line_id
=
sha256
(
line
.
encode
(
'utf-8'
))
.
hexdigest
()
line_id
=
sha256
(
line
.
encode
(
'utf-8'
))
.
hexdigest
()
row
=
LogFile
(
line_id
=
line_id
,
line
=
line
)
row
=
LogFile
(
line_id
=
line_id
,
line
=
line
)
try
:
try
:
with
transaction
.
manager
:
with
transaction
.
manager
:
db_session
.
add
(
row
)
db_session
.
add
(
row
)
except
IntegrityError
:
except
IntegrityError
:
return
return
def
read_log
(
log_file
):
engine
=
create_engine
(
db_url
)
factory
=
sessionmaker
(
bind
=
engine
)
db_session
=
factory
()
with
BacaFile
(
log_file
)
as
f
:
with
BacaFile
(
log_file
)
as
f
:
while
True
:
while
True
:
line
=
f
.
readline
()
line
=
f
.
readline
()
...
@@ -78,10 +79,7 @@ def main(argv=sys.argv[1:]):
...
@@ -78,10 +79,7 @@ def main(argv=sys.argv[1:]):
option
=
pars
.
parse_args
(
argv
)
option
=
pars
.
parse_args
(
argv
)
conf
=
ConfigParser
()
conf
=
ConfigParser
()
conf
.
read
(
option
.
conf
)
conf
.
read
(
option
.
conf
)
engine
=
create_engine
(
conf
.
get
(
'main'
,
'db_url'
))
db_url
=
conf
.
get
(
'main'
,
'db_url'
)
factory
=
sessionmaker
(
bind
=
engine
)
my_registry
[
'db_session'
]
=
db_session
=
factory
()
register
(
db_session
)
log_dir
=
conf
.
get
(
'main'
,
'log_dir'
)
log_dir
=
conf
.
get
(
'main'
,
'log_dir'
)
handler
=
Pantau
()
handler
=
Pantau
()
observer
=
Observer
()
observer
=
Observer
()
...
@@ -98,7 +96,7 @@ def main(argv=sys.argv[1:]):
...
@@ -98,7 +96,7 @@ def main(argv=sys.argv[1:]):
log_file
=
my_registry
[
'log_file'
]
log_file
=
my_registry
[
'log_file'
]
del
my_registry
[
'log_file'
]
del
my_registry
[
'log_file'
]
my_registry
[
'last_log_file'
]
=
log_file
my_registry
[
'last_log_file'
]
=
log_file
thread
=
Process
(
target
=
read_log
,
args
=
(
log_file
,))
thread
=
Process
(
target
=
read_log
,
args
=
(
log_file
,
db_url
))
my_registry
[
'read_log'
]
=
thread
my_registry
[
'read_log'
]
=
thread
print
(
'Start read file ...'
)
print
(
'Start read file ...'
)
thread
.
start
()
thread
.
start
()
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment