Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Gerion Entrup
brainzfs
Commits
6895794d
Commit
6895794d
authored
Aug 18, 2016
by
Gerion Entrup
Browse files
plumber: dummy implementation of check_recordings
plumber is not functional yet
parent
9f4fdb9a
Changes
2
Hide whitespace changes
Inline
Side-by-side
plumber.py
View file @
6895794d
import
enum
import
fetcher
import
logging
import
os.path
import
queue
import
settings
import
threading
from
collector
import
Collector
from
model
import
Recording
from
utils
import
get_path
class
Action
(
enum
.
Enum
):
check_recordings
=
0
# check if all files of the recordings are accessible
clean_cache
=
1
# clean the fetcher cache
clean_database
=
2
# check all database tables for outdated tables
Actions
=
queue
.
Queue
(
maxsize
=
2
)
from
collector
import
Paths
,
DefectData
,
DEFECT
,
UPDATE
class
Plumber
(
threading
.
Thread
):
"""Check and find out how to repair the database."""
...
...
@@ -8,62 +25,39 @@ class Plumber(threading.Thread):
def
__init__
(
self
,
session_fac
):
super
().
__init__
(
target
=
self
)
self
.
_session
=
session_fac
()
self
.
log
=
logging
.
getLogger
(
'plumber'
)
self
.
_logger
=
logging
.
getLogger
(
'plumber'
)
self
.
_collector
=
Collector
.
get_unthreaded_instance
(
self
.
_session
,
logging
.
getLogger
(
'plumber.collector'
))
def
run
(
self
):
check_recordings
()
check_artist_credits
()
check_artist_credit_names
()
check_artists
()
check_release_groups
()
check_releases
()
check_tracks
()
check_mediums
()
def
check_entitys
(
self
,
table
,
check_fail
,
check_defect
=
lambda
x
:
False
):
for
entity
in
self
.
_session
.
query
(
table
).
all
():
#clean file if necessary
if
check_fail
(
entity
)
or
(
hasattr
(
entity
,
'gid'
)
and
mbid_error
(
entity
.
gid
)):
self
.
_session
.
delete
(
entity
)
#check for defect
if
check_defect
(
entity
):
Paths
.
put
((
DEFECT
,
DefectData
(
mbid
=
entity
.
gid
,
table
=
table
)))
check_update_time
(
entity
)
while
True
:
action
=
Actions
.
get
()
if
action
==
Action
.
check_recordings
:
self
.
check_recordings
()
if
action
==
Action
.
clean_cache
:
fetcher
.
clean_cache
()
if
action
==
Action
.
clean_database
:
pass
self
.
_session
.
close
()
def
check_recordings
(
self
):
check_entitys
(
Recording
,
lambda
x
:
not
os
.
path
.
isfile
(
x
.
path
),
check_defect
=
lambda
x
:
x
.
artist_credit
==
None
)
def
check_artist_credits
(
self
):
check_entitys
(
ArtistCredit
,
lambda
ac
:
self
.
_session
.
query
(
Recording
).
filter
(
ac
==
Recording
.
artist_credit
).
first
()
==
None
)
def
check_artist_credit_names
(
self
):
pass
def
check_artists
(
self
):
recordings
=
self
.
_session
.
query
(
Recording
).
all
()
missing
=
[]
for
recording
in
recordings
:
if
not
os
.
path
.
isfile
(
get_path
(
recording
.
path
)):
missing
.
append
(
recording
)
if
len
(
missing
)
>
len
(
recordings
)
//
2
and
not
settings
.
force_clean
:
self
.
_logger
.
error
(
"Too many files to clean, maybe you want to"
+
"adjust directory_prefix. Otherwise set"
+
"force_clean to True to enforce the cleaning"
+
"process."
)
for
recording
in
missing
:
self
.
clean_recording
(
recording
)
def
clean_recording
(
self
,
recording
):
pass
def
check_release_groups
(
self
):
pass
def
check_releases
(
self
):
pass
def
check_tracks
(
self
):
pass
def
check_mediums
(
self
):
pass
def
mbid_error
(
mbid
):
return
False
def
check_update_time
(
entity
):
def
check_update_time
(
self
,
entity
):
print
(
"last_updated:"
)
print
(
entity
.
last_updated
)
print
(
type
(
entity
.
last_updated
))
settings/__init__.py
View file @
6895794d
...
...
@@ -5,3 +5,4 @@ fetcher_cache_length = 10000
fetcher_cache_age
=
172800
# 48 hours
directory_prefix
=
'/'
force_clean
=
False
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
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 comment