Skip to content
GitLab
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
994326aa
Commit
994326aa
authored
Oct 23, 2015
by
Gerion Entrup
Browse files
plumber: implement a few methods more, still not usable
parent
df989da0
Changes
3
Hide whitespace changes
Inline
Side-by-side
collector.py
View file @
994326aa
...
...
@@ -18,6 +18,7 @@ from fetcher import Fetcher
Paths
=
queue
.
Queue
(
maxsize
=
10
)
NEW
=
0
;
DEFECT
=
1
;
UPDATE
=
2
NewData
=
namedtuple
(
'NewData'
,
[
'mbid'
,
'path'
])
DefectData
=
namedtuple
(
'DefectData'
,
[
'mbid'
,
'table'
])
class
Collector
(
threading
.
Thread
):
"""
...
...
plumber.py
View file @
994326aa
import
os.path
from
collector
import
Paths
,
DEFECT
,
UPDATE
from
collector
import
Paths
,
DefectData
,
DEFECT
,
UPDATE
class
Plumber
(
threading
.
Thread
):
"""Check and find out how to repair the database."""
...
...
@@ -12,48 +12,59 @@ class Plumber(threading.Thread):
def
run
(
self
):
check_recordings
()
check_artists
()
check_artist_credits
()
check_artist_credit_names
()
check_artists
()
check_release_groups
()
check_releases
()
check_tracks
()
check_mediums
()
check_releases
()
check_release_groups
()
check_integrity_conditions
()
def
check_recordings
()
recordings
=
session
.
query
(
Recording
).
all
()
for
recording
in
recordings
:
#clean out orphaned recordings
if
not
os
.
path
.
isfile
(
recording
.
path
):
delete_recording
(
recording
)
#mbid is the fundamental identifier,
#without it, there is no way to recover
#so delete entity
if
check_mbid
(
recording
.
gid
)
delete_recording
(
recording
)
#check recording
defect
=
recording
.
name
is
None
or
len
(
recording
.
name
)
==
0
defect
|=
recording
.
ftype
is
None
or
len
(
recording
.
name
)
==
0
if
defect
:
Paths
.
put
((
DEFECT
,
recording
.
gid
))
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
check_mbid
(
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
(
recording
)
#check foreign keys
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
):
pass
def
check_release_groups
(
self
):
pass
def
check_releases
(
self
):
pass
def
check_tracks
(
self
):
pass
def
delete_recording
(
recording
):
def
check_mediums
(
self
):
pass
def
check_mbid
(
mbid
):
return
False
def
check_update_time
(
entity
)
print
(
"last_updated:"
)
print
(
entity
.
last_updated
)
print
(
type
(
entity
.
last_updated
)
print
(
type
(
entity
.
last_updated
)
)
sqlitequeue.py
View file @
994326aa
...
...
@@ -12,6 +12,11 @@ class SqliteSession():
ret
=
self
.
_session
.
commit
()
return
ret
def
delete
(
self
,
entry
):
with
lock
:
ret
=
self
.
_session
.
delete
(
entry
)
return
ret
def
query
(
self
,
table
):
return
SqliteQuery
(
table
,
self
.
_session
)
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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