Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
D
dcpman
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
dcp
dcpman
Commits
95f6a6a6
Commit
95f6a6a6
authored
10 years ago
by
nimrod
Browse files
Options
Downloads
Patches
Plain Diff
- Correcting warnings generated by running flake8.
parent
fe0c4929
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
fabfile.py
+18
-14
18 additions, 14 deletions
fabfile.py
source/dcp.py
+149
-145
149 additions, 145 deletions
source/dcp.py
source/manager.py
+54
-52
54 additions, 52 deletions
source/manager.py
with
221 additions
and
211 deletions
fabfile.py
+
18
−
14
View file @
95f6a6a6
#!/usr/bin/env python
#!/usr/bin/env python
from
fabric.api
import
task
,
local
,
settings
from
fabric.api
import
task
,
local
,
settings
@task
@task
def
publish
():
def
publish
():
local
(
'
git dch -R
'
)
local
(
'
git dch -R
'
)
...
@@ -10,10 +11,12 @@ def publish ():
...
@@ -10,10 +11,12 @@ def publish ():
local
(
'''
fab -f $REPREPRO_BASE_DIR/fabfile.py publish
'''
)
local
(
'''
fab -f $REPREPRO_BASE_DIR/fabfile.py publish
'''
)
clean
()
clean
()
@task
@task
def
build
():
def
build
():
local
(
'''
dpkg-buildpackage -us -uc
'''
)
local
(
'''
dpkg-buildpackage -us -uc
'''
)
@task
@task
def
clean
():
def
clean
():
with
settings
(
warn_only
=
True
):
with
settings
(
warn_only
=
True
):
...
@@ -23,6 +26,7 @@ def clean ():
...
@@ -23,6 +26,7 @@ def clean ():
debian/dcpman debian/files
'''
)
debian/dcpman debian/files
'''
)
local
(
'''
rm fabfile.pyc
'''
)
local
(
'''
rm fabfile.pyc
'''
)
@task
@task
def
push
():
def
push
():
local
(
'''
git push --all gitdaemon
'''
)
local
(
'''
git push --all gitdaemon
'''
)
This diff is collapsed.
Click to expand it.
source/dcp.py
+
149
−
145
View file @
95f6a6a6
...
@@ -8,18 +8,20 @@ from xml.dom.minidom import parse
...
@@ -8,18 +8,20 @@ from xml.dom.minidom import parse
import
sys
import
sys
import
vlc
import
vlc
class
Asset
(
object
):
class
Asset
(
object
):
'''
A simple asset that
'
s part of whole DCP package.
'''
'''
A simple asset that
'
s part of whole DCP package.
'''
def
verifySize
(
self
):
def
verifySize
(
self
):
'''
verify that the size of the file is correct, if present.
'''
'''
verify that the size of the file is correct, if present.
'''
try
:
try
:
return
exists
(
self
.
fullpath
)
and
stat
(
self
.
fullpath
).
st_size
==
self
.
size
return
exists
(
self
.
fullpath
)
and
stat
(
self
.
fullpath
).
st_size
==
\
self
.
size
except
AttributeError
:
except
AttributeError
:
return
True
return
True
def
verifyHash
(
self
):
def
verifyHash
(
self
):
'''
verify that the hash is correct, if present.
'''
'''
verify that the hash is correct, if present.
'''
if
hasattr
(
self
,
'
hash
'
)
==
False
:
if
not
hasattr
(
self
,
'
hash
'
):
return
True
return
True
# from os import stat
# from os import stat
# try:
# try:
...
@@ -40,7 +42,7 @@ class Asset (object):
...
@@ -40,7 +42,7 @@ class Asset (object):
'''
Copies the file to the destination directory and verifies the hash
'''
Copies the file to the destination directory and verifies the hash
during.
'''
during.
'''
newfilepath
=
destination
+
'
/
'
+
self
.
filename
newfilepath
=
destination
+
'
/
'
+
self
.
filename
if
hasattr
(
self
,
'
hash
'
)
==
False
:
if
not
hasattr
(
self
,
'
hash
'
):
copyfile
(
self
.
fullpath
,
newfilepath
)
copyfile
(
self
.
fullpath
,
newfilepath
)
self
.
fullpath
=
newfilepath
self
.
fullpath
=
newfilepath
self
.
rootpath
=
destination
self
.
rootpath
=
destination
...
@@ -67,7 +69,7 @@ class Asset (object):
...
@@ -67,7 +69,7 @@ class Asset (object):
media
.
parse
()
media
.
parse
()
self
.
duration
=
media
.
get_duration
()
self
.
duration
=
media
.
get_duration
()
def
__init__
(
self
,
rootpath
,
filename
,
id
=
None
,
hash
=
None
,
size
=
None
,
\
def
__init__
(
self
,
rootpath
,
filename
,
id
=
None
,
hash
=
None
,
size
=
None
,
packinglist
=
False
,
type
=
None
):
packinglist
=
False
,
type
=
None
):
'''
Initialize an asset, has to have a filename and path.
'''
'''
Initialize an asset, has to have a filename and path.
'''
self
.
rootpath
=
rootpath
self
.
rootpath
=
rootpath
...
@@ -75,13 +77,13 @@ class Asset (object):
...
@@ -75,13 +77,13 @@ class Asset (object):
filename
=
filename
[
8
:]
filename
=
filename
[
8
:]
self
.
filename
=
filename
self
.
filename
=
filename
self
.
fullpath
=
rootpath
+
'
/
'
+
filename
self
.
fullpath
=
rootpath
+
'
/
'
+
filename
if
id
!=
None
:
if
id
is
not
None
:
self
.
id
=
id
self
.
id
=
id
if
hash
!=
None
:
if
hash
is
not
None
:
self
.
hash
=
hash
self
.
hash
=
hash
if
size
!=
None
:
if
size
is
not
None
:
self
.
size
=
size
self
.
size
=
size
if
type
!=
None
:
if
type
is
not
None
:
self
.
type
=
type
self
.
type
=
type
self
.
packinglist
=
packinglist
self
.
packinglist
=
packinglist
...
@@ -93,24 +95,21 @@ class DCP:
...
@@ -93,24 +95,21 @@ class DCP:
the correct hash.
'''
the correct hash.
'''
for
asset
in
self
.
assets
:
for
asset
in
self
.
assets
:
try
:
try
:
if
asset
.
verifySize
()
==
False
:
if
not
asset
.
verifySize
():
return
False
return
False
except
BaseException
as
e
:
except
BaseException
as
e
:
raise
RuntimeError
(
'
Failed size comparisement for
'
+
\
raise
RuntimeError
(
'
Failed size comparisement for
'
+
asset
.
filename
)
from
e
asset
.
filename
)
from
e
#Sort the assets by size before calculating hashes, for performance.
'''
Sort the assets by size before calculating hashes, for
def
sortkey
(
x
):
performance.
'''
try
:
self
.
assets
.
sort
(
key
=
lambda
x
:
try
:
return
x
.
size
except
return
x
.
size
AttributeError
:
return
0
)
except
AttributeError
:
return
0
self
.
assets
.
sort
(
key
=
sortkey
)
for
asset
in
self
.
assets
:
for
asset
in
self
.
assets
:
try
:
try
:
if
asset
.
verifyHash
()
==
False
:
if
not
asset
.
verifyHash
():
return
False
return
False
except
BaseException
as
e
:
except
BaseException
as
e
:
raise
RuntimeError
(
'
Failed hash calculation for
'
+
\
raise
RuntimeError
(
'
Failed hash calculation for
'
+
asset
.
filename
)
from
e
asset
.
filename
)
from
e
return
True
return
True
...
@@ -130,13 +129,16 @@ class DCP:
...
@@ -130,13 +129,16 @@ class DCP:
for
element
in
assetmap
:
for
element
in
assetmap
:
id
=
element
.
getElementsByTagName
(
'
Id
'
)[
0
].
firstChild
.
data
id
=
element
.
getElementsByTagName
(
'
Id
'
)[
0
].
firstChild
.
data
id
=
id
.
split
(
'
:
'
)[
-
1
]
id
=
id
.
split
(
'
:
'
)[
-
1
]
filename
=
element
.
getElementsByTagName
(
'
Path
'
)[
0
].
firstChild
.
data
filename
=
element
.
getElementsByTagName
(
'
Path
'
)[
0
]
\
packinglist
=
len
(
element
.
getElementsByTagName
(
'
PackingList
'
))
>
0
.
firstChild
.
data
packinglist
=
len
(
element
.
getElementsByTagName
(
'
PackingList
'
))
>
0
if
packinglist
:
if
packinglist
:
self
.
assets
.
append
(
Asset
(
self
.
directory
,
filename
,
\
self
.
assets
.
append
(
Asset
(
self
.
directory
,
filename
,
id
=
id
,
packinglist
=
packinglist
,
type
=
'
text/xml
'
))
id
=
id
,
packinglist
=
packinglist
,
type
=
'
text/xml
'
))
else
:
else
:
self
.
assets
.
append
(
Asset
(
self
.
directory
,
filename
,
\
self
.
assets
.
append
(
Asset
(
self
.
directory
,
filename
,
id
=
id
,
packinglist
=
packinglist
))
id
=
id
,
packinglist
=
packinglist
))
except
BaseException
as
e
:
except
BaseException
as
e
:
raise
RuntimeError
(
'
Failed to parse assetmap file
'
)
from
e
raise
RuntimeError
(
'
Failed to parse assetmap file
'
)
from
e
...
@@ -148,7 +150,7 @@ class DCP:
...
@@ -148,7 +150,7 @@ class DCP:
elif
'
VOLINDEX
'
in
listdir
(
self
.
directory
):
elif
'
VOLINDEX
'
in
listdir
(
self
.
directory
):
filename
=
'
VOLINDEX
'
filename
=
'
VOLINDEX
'
else
:
else
:
#
raise RuntimeError
('Couldn\'t find volindex file')
'''
raise RuntimeError(
'
Couldn
\'
t find volindex file
'
)
'''
return
return
self
.
assets
.
append
(
Asset
(
self
.
directory
,
filename
,
type
=
'
text/xml
'
))
self
.
assets
.
append
(
Asset
(
self
.
directory
,
filename
,
type
=
'
text/xml
'
))
...
@@ -157,21 +159,25 @@ class DCP:
...
@@ -157,21 +159,25 @@ class DCP:
try
:
try
:
pkls
=
(
parse
(
x
.
fullpath
)
for
x
in
self
.
assets
if
x
.
packinglist
)
pkls
=
(
parse
(
x
.
fullpath
)
for
x
in
self
.
assets
if
x
.
packinglist
)
for
pkl
in
pkls
:
for
pkl
in
pkls
:
if
hasattr
(
self
,
'
signed
'
)
==
False
:
if
not
hasattr
(
self
,
'
signed
'
):
self
.
signed
=
len
(
pkl
.
getElementsByTagName
(
'
Signer
'
))
>
0
self
.
signed
=
len
(
pkl
.
getElementsByTagName
(
'
Signer
'
))
>
0
try
:
try
:
if
hasattr
(
self
,
'
name
'
)
==
False
:
if
not
hasattr
(
self
,
'
name
'
):
self
.
name
=
pkl
.
getElementsByTagName
\
self
.
name
=
pkl
\
(
'
AnnotationText
'
)[
0
].
firstChild
.
data
.
strip
()
.
getElementsByTagName
(
'
AnnotationText
'
)[
0
]
\
.
firstChild
.
data
.
strip
()
except
:
except
:
pass
pass
for
element
in
pkl
.
getElementsByTagName
(
'
Asset
'
):
for
element
in
pkl
.
getElementsByTagName
(
'
Asset
'
):
id
=
element
.
getElementsByTagName
(
'
Id
'
)[
0
].
firstChild
.
data
id
=
element
.
getElementsByTagName
(
'
Id
'
)[
0
].
firstChild
.
data
id
=
id
.
split
(
'
:
'
)[
-
1
]
id
=
id
.
split
(
'
:
'
)[
-
1
]
hash
=
element
.
getElementsByTagName
(
'
Hash
'
)[
0
].
firstChild
.
data
hash
=
element
.
getElementsByTagName
(
'
Hash
'
)[
0
]
\
type
=
element
.
getElementsByTagName
(
'
Type
'
)[
0
].
firstChild
.
data
.
firstChild
.
data
size
=
int
(
element
.
getElementsByTagName
(
'
Size
'
)[
0
].
firstChild
.
data
)
type
=
element
.
getElementsByTagName
(
'
Type
'
)[
0
]
\
asset
=
[
x
for
x
in
self
.
assets
if
hasattr
(
x
,
'
id
'
)
and
\
.
firstChild
.
data
size
=
int
(
element
.
getElementsByTagName
(
'
Size
'
)[
0
]
.
firstChild
.
data
)
asset
=
[
x
for
x
in
self
.
assets
if
hasattr
(
x
,
'
id
'
)
and
x
.
id
==
id
][
0
]
x
.
id
==
id
][
0
]
asset
.
hash
=
hash
asset
.
hash
=
hash
asset
.
size
=
size
asset
.
size
=
size
...
@@ -183,15 +189,16 @@ class DCP:
...
@@ -183,15 +189,16 @@ class DCP:
def
_find_cpl
(
self
):
def
_find_cpl
(
self
):
'''
Goes through the xml files, finds the CPL and extracts the data from
'''
Goes through the xml files, finds the CPL and extracts the data from
it.
'''
it.
'''
for
asset
in
[
x
for
x
in
self
.
assets
if
hasattr
(
x
,
'
type
'
)
and
x
.
type
.
find
(
'
xml
'
)
>
-
1
]:
for
asset
in
[
x
for
x
in
self
.
assets
if
hasattr
(
x
,
'
type
'
)
and
x
elements
=
(
parse
(
asset
.
fullpath
)).
getElementsByTagName
\
.
type
.
find
(
'
xml
'
)
>
-
1
]:
(
'
CompositionPlaylist
'
)
elements
=
(
parse
(
asset
.
fullpath
))
\
.
getElementsByTagName
(
'
CompositionPlaylist
'
)
if
len
(
elements
)
>
0
:
if
len
(
elements
)
>
0
:
try
:
try
:
self
.
cpl_id
=
elements
[
0
]
.
getElementsByTagName
\
self
.
cpl_id
=
elements
[
0
]
\
(
'
Id
'
)[
0
].
firstChild
.
data
.
getElementsByTagName
(
'
Id
'
)[
0
].
firstChild
.
data
self
.
cpl_date
=
elements
[
0
]
.
getElementsByTagName
\
self
.
cpl_date
=
elements
[
0
]
\
(
'
IssueDate
'
)[
0
].
firstChild
.
data
.
getElementsByTagName
(
'
IssueDate
'
)[
0
].
firstChild
.
data
except
:
except
:
pass
pass
...
@@ -202,7 +209,7 @@ class DCP:
...
@@ -202,7 +209,7 @@ class DCP:
self
.
_add_volindex
()
self
.
_add_volindex
()
self
.
_parse_packinglist
()
self
.
_parse_packinglist
()
try
:
try
:
self
.
duration
=
max
([
x
.
duration
for
x
in
self
.
assets
if
hasattr
\
self
.
duration
=
max
([
x
.
duration
for
x
in
self
.
assets
if
hasattr
(
x
,
'
duration
'
)])
(
x
,
'
duration
'
)])
except
:
except
:
self
.
duration
=
'
Unknown
'
self
.
duration
=
'
Unknown
'
...
@@ -213,30 +220,27 @@ class DCP:
...
@@ -213,30 +220,27 @@ class DCP:
for
asset
in
self
.
assets
:
for
asset
in
self
.
assets
:
totalsize
=
stat
(
asset
.
fullpath
).
st_size
totalsize
=
stat
(
asset
.
fullpath
).
st_size
try
:
try
:
if
asset
.
verifySize
()
==
False
:
if
not
asset
.
verifySize
():
return
False
return
False
except
BaseException
as
e
:
except
BaseException
as
e
:
raise
RuntimeError
(
'
Failed size comparisement for
'
+
\
raise
RuntimeError
(
'
Failed size comparisement for
'
asset
.
filename
)
from
e
+
asset
.
filename
)
from
e
freespace
=
statvfs
(
destination
).
f_bavail
*
statvfs
\
freespace
=
statvfs
(
destination
).
f_bavail
\
(
destination
).
f_bsize
*
statvfs
(
destination
).
f_bsize
if
freespace
<
totalsize
:
if
freespace
<
totalsize
:
return
False
return
False
#Sort the assets by size before calculating hashes, for performance.
'''
Sort the assets by size before calculating hashes, for
def
sortkey
(
x
):
performance.
'''
try
:
self
.
assets
.
sort
(
key
=
lambda
x
:
try
:
return
x
.
size
except
return
x
.
size
AttributeError
:
return
0
)
except
AttributeError
:
return
0
self
.
assets
.
sort
(
key
=
sortkey
)
newdirectory
=
destination
+
'
/
'
+
basename
(
self
.
directory
)
newdirectory
=
destination
+
'
/
'
+
basename
(
self
.
directory
)
mkdir
(
newdirectory
)
mkdir
(
newdirectory
)
for
asset
in
self
.
assets
:
for
asset
in
self
.
assets
:
try
:
try
:
if
asset
.
copyAndVerify
(
newdirectory
)
==
False
:
if
not
asset
.
copyAndVerify
(
newdirectory
):
return
False
return
False
except
BaseException
as
e
:
except
BaseException
as
e
:
raise
RuntimeError
(
'
Failed hash calculation for
'
+
\
raise
RuntimeError
(
'
Failed hash calculation for
'
+
asset
.
filename
)
from
e
asset
.
filename
)
from
e
self
.
directory
=
newdirectory
self
.
directory
=
newdirectory
return
True
return
True
...
...
This diff is collapsed.
Click to expand it.
source/manager.py
+
54
−
52
View file @
95f6a6a6
...
@@ -5,8 +5,9 @@ try:
...
@@ -5,8 +5,9 @@ try:
from
dcpman.dcp
import
DCP
from
dcpman.dcp
import
DCP
except
:
except
:
from
dcp
import
DCP
from
dcp
import
DCP
'''
autogenerated file from Qt Designer to setup the window.
'''
try
:
try
:
from
dcpman
import
ui
#autogenerated file from Qt Designer to setup the window
from
dcpman
import
ui
except
:
except
:
import
ui
import
ui
import
sys
import
sys
...
@@ -14,6 +15,7 @@ from os.path import basename
...
@@ -14,6 +15,7 @@ from os.path import basename
import
syslog
import
syslog
import
time
import
time
class
verifyThread
(
QtCore
.
QThread
):
class
verifyThread
(
QtCore
.
QThread
):
'''
A seperate thread to verify the DCP(IO intensive).
'''
A seperate thread to verify the DCP(IO intensive).
...
@@ -27,11 +29,11 @@ class verifyThread (QtCore.QThread):
...
@@ -27,11 +29,11 @@ class verifyThread (QtCore.QThread):
result
=
dcp
.
verify
()
result
=
dcp
.
verify
()
if
result
:
if
result
:
window
.
verifyLine
.
setText
(
'
OK
'
)
window
.
verifyLine
.
setText
(
'
OK
'
)
syslog
.
syslog
(
syslog
.
LOG_INFO
,
time
.
ctime
()
+
\
syslog
.
syslog
(
syslog
.
LOG_INFO
,
time
.
ctime
()
+
directoryname
+
'
verification succeeded.
'
)
directoryname
+
'
verification succeeded.
'
)
else
:
else
:
window
.
verifyLine
.
setText
(
'
Corrupted!
'
)
window
.
verifyLine
.
setText
(
'
Corrupted!
'
)
syslog
.
syslog
(
syslog
.
LOG_INFO
,
time
.
ctime
()
+
\
syslog
.
syslog
(
syslog
.
LOG_INFO
,
time
.
ctime
()
+
directoryname
+
'
verification failed.
'
)
directoryname
+
'
verification failed.
'
)
except
BaseException
as
exception
:
except
BaseException
as
exception
:
window
.
verifyLine
.
setText
(
str
(
exception
))
window
.
verifyLine
.
setText
(
str
(
exception
))
...
@@ -53,7 +55,7 @@ if __name__ == '__main__':
...
@@ -53,7 +55,7 @@ if __name__ == '__main__':
app
=
QtGui
.
QApplication
(
sys
.
argv
)
app
=
QtGui
.
QApplication
(
sys
.
argv
)
icon
=
QtGui
.
QIcon
(
'
/usr/share/icons/oxygen/16x16/apps/kmplayer.png
'
)
icon
=
QtGui
.
QIcon
(
'
/usr/share/icons/oxygen/16x16/apps/kmplayer.png
'
)
app
.
setWindowIcon
(
icon
)
app
.
setWindowIcon
(
icon
)
directory
=
QtGui
.
QFileDialog
.
getExistingDirectory
(
\
directory
=
QtGui
.
QFileDialog
.
getExistingDirectory
(
caption
=
'
Please select the location of the DCP
'
)
caption
=
'
Please select the location of the DCP
'
)
directoryname
=
basename
(
directory
)
directoryname
=
basename
(
directory
)
mainwindow
=
QtGui
.
QMainWindow
()
mainwindow
=
QtGui
.
QMainWindow
()
...
@@ -64,19 +66,19 @@ if __name__ == '__main__':
...
@@ -64,19 +66,19 @@ if __name__ == '__main__':
dcp
=
DCP
(
directory
)
dcp
=
DCP
(
directory
)
try
:
try
:
window
.
nameLine
.
setText
(
dcp
.
name
)
window
.
nameLine
.
setText
(
dcp
.
name
)
syslog
.
syslog
(
syslog
.
LOG_INFO
,
time
.
ctime
()
+
directoryname
+
\
syslog
.
syslog
(
syslog
.
LOG_INFO
,
time
.
ctime
()
+
directoryname
+
'
parsed.
'
)
'
parsed.
'
)
except
AttributeError
as
exception
:
except
AttributeError
as
exception
:
window
.
nameLine
.
setText
(
basename
(
directory
))
window
.
nameLine
.
setText
(
basename
(
directory
))
syslog
.
syslog
(
syslog
.
LOG_INFO
,
time
.
ctime
()
+
directoryname
+
\
syslog
.
syslog
(
syslog
.
LOG_INFO
,
time
.
ctime
()
+
directoryname
+
exception
)
exception
)
if
dcp
.
signed
:
if
dcp
.
signed
:
syslog
.
syslog
(
syslog
.
LOG_INFO
,
time
.
ctime
()
+
directoryname
+
\
syslog
.
syslog
(
syslog
.
LOG_INFO
,
time
.
ctime
()
+
directoryname
+
'
is signed.
'
)
'
is signed.
'
)
else
:
else
:
syslog
.
syslog
(
syslog
.
LOG_INFO
,
time
.
ctime
()
+
directoryname
+
\
syslog
.
syslog
(
syslog
.
LOG_INFO
,
time
.
ctime
()
+
directoryname
+
'
is not sigend.
'
)
'
is not sigend.
'
)
syslog
.
syslog
(
syslog
.
LOG_INFO
,
time
.
ctime
()
+
directoryname
+
\
syslog
.
syslog
(
syslog
.
LOG_INFO
,
time
.
ctime
()
+
directoryname
+
'
duration is
'
+
str
(
dcp
.
duration
))
'
duration is
'
+
str
(
dcp
.
duration
))
if
dcp
.
signed
and
dcp
.
duration
==
0
:
if
dcp
.
signed
and
dcp
.
duration
==
0
:
window
.
encryptedLine
.
setText
(
'
Most likely
'
)
window
.
encryptedLine
.
setText
(
'
Most likely
'
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment