mirror of
https://github.com/gryf/pygtktalog.git
synced 2025-12-17 19:40:21 +01:00
* Finished files/directories fetching into catalog.
This commit is contained in:
107
mainWindow.py
107
mainWindow.py
@@ -360,13 +360,18 @@ import gtk.glade
|
|||||||
|
|
||||||
from config import Config
|
from config import Config
|
||||||
import deviceHelper
|
import deviceHelper
|
||||||
|
import filetypeHelper
|
||||||
import dialogs
|
import dialogs
|
||||||
|
import prefs
|
||||||
from files import fileObj
|
from files import fileObj
|
||||||
|
|
||||||
|
_count=0
|
||||||
|
|
||||||
class PyGTKtalog:
|
class PyGTKtalog:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
|
||||||
self.conf = Config()
|
self.conf = Config()
|
||||||
|
self.conf.load()
|
||||||
|
|
||||||
self.gladefile = "glade/main.glade"
|
self.gladefile = "glade/main.glade"
|
||||||
self.pygtkcat = gtk.glade.XML(self.gladefile,"main")
|
self.pygtkcat = gtk.glade.XML(self.gladefile,"main")
|
||||||
@@ -404,6 +409,7 @@ class PyGTKtalog:
|
|||||||
"on_new1_activate" :self.newDB,
|
"on_new1_activate" :self.newDB,
|
||||||
"on_add_cd_activate" :self.addCD,
|
"on_add_cd_activate" :self.addCD,
|
||||||
"on_about1_activate" :self.about,
|
"on_about1_activate" :self.about,
|
||||||
|
"on_properties1_activate":self.preferences,
|
||||||
}
|
}
|
||||||
|
|
||||||
# connect signals
|
# connect signals
|
||||||
@@ -420,7 +426,9 @@ class PyGTKtalog:
|
|||||||
self.conf.save()
|
self.conf.save()
|
||||||
|
|
||||||
return
|
return
|
||||||
|
def preferences(self):
|
||||||
|
|
||||||
|
return
|
||||||
def doQuit(self, widget):
|
def doQuit(self, widget):
|
||||||
"""quit and save window parameters to config file"""
|
"""quit and save window parameters to config file"""
|
||||||
try:
|
try:
|
||||||
@@ -507,9 +515,12 @@ class PyGTKtalog:
|
|||||||
dialogs.Wrn("error mounting device - pyGTKtalog","Cannot mount device pointed to %s.\nLast mount message:\n<tt>%s</tt>" % (self.conf.confd['cd'],mount))
|
dialogs.Wrn("error mounting device - pyGTKtalog","Cannot mount device pointed to %s.\nLast mount message:\n<tt>%s</tt>" % (self.conf.confd['cd'],mount))
|
||||||
|
|
||||||
def scan(self,path):
|
def scan(self,path):
|
||||||
|
global _count
|
||||||
|
_count= 0
|
||||||
mime = mimetypes.MimeTypes()
|
mime = mimetypes.MimeTypes()
|
||||||
extensions = ('mkv','avi','ogg','mpg','wmv','mp4')
|
mov_ext = ('mkv','avi','ogg','mpg','wmv','mp4','mpeg')
|
||||||
|
img_ext = ('jpg','jpeg','png','gif','bmp','tga','tif','tiff','ilbm','iff','pcx')
|
||||||
|
# count files in directory tree
|
||||||
count = 0
|
count = 0
|
||||||
for root,kat,plik in os.walk(path):
|
for root,kat,plik in os.walk(path):
|
||||||
for p in plik:
|
for p in plik:
|
||||||
@@ -518,77 +529,53 @@ class PyGTKtalog:
|
|||||||
frac = 1.0/count
|
frac = 1.0/count
|
||||||
count = 1
|
count = 1
|
||||||
|
|
||||||
c=0
|
def recurse(path,name,wobj,date=0,frac=0):
|
||||||
oldroot = path
|
global _count
|
||||||
t="\t"
|
|
||||||
|
|
||||||
current_dir = {}
|
|
||||||
|
|
||||||
index = 1
|
|
||||||
|
|
||||||
for root,kat,plik in os.walk(path,False):
|
|
||||||
|
|
||||||
if root == path:
|
walker = os.walk(path)
|
||||||
r = '/'
|
root,dirs,files = walker.next()
|
||||||
else:
|
|
||||||
r = root[len(path):]
|
f = fileObj(name=name,filetype="d",mtime=date)
|
||||||
|
|
||||||
|
for i in dirs:
|
||||||
|
f.add_member(recurse(os.path.join(path,i),i,wobj,os.stat(os.path.join(root,i)).st_mtime,frac))
|
||||||
|
|
||||||
a = fileObj(name=r,tmproot=root)
|
for i in files:
|
||||||
for k in kat:
|
_count+=1
|
||||||
b = fileObj(name=k,tmproot=os.path.join(root,k))
|
st = os.stat(os.path.join(root,i))
|
||||||
a.add_member(b)
|
### scan files
|
||||||
|
if i[-3:].lower() in mov_ext or \
|
||||||
#current_dir.append(a)
|
mime.guess_type(i)!= (None,None) and \
|
||||||
|
mime.guess_type(i)[0].split("/")[0] == 'video':
|
||||||
# scan only files
|
|
||||||
for p in plik:
|
|
||||||
b = fileObj(name=p,tmproot=os.path.join(root,p))
|
|
||||||
a.add_member(b)
|
|
||||||
if p[-3:].lower() in extensions or \
|
|
||||||
mime.guess_type(p)!= (None,None) and \
|
|
||||||
mime.guess_type(p)[0].split("/")[0] == 'video':
|
|
||||||
# video only
|
# video only
|
||||||
# TODO: parametrize this loop!
|
info = filetypeHelper.guess_video(os.path.join(root,i))
|
||||||
info = popen2.popen4('midentify "' + os.path.join(root,p)+'"')[0].readlines()
|
#print info
|
||||||
video_format = ''
|
elif i[-3:].lower() in img_ext or \
|
||||||
audio_codec = ''
|
mime.guess_type(i)!= (None,None) and \
|
||||||
video_codec = ''
|
mime.guess_type(i)[0].split("/")[0] == 'image':
|
||||||
video_x = ''
|
pass
|
||||||
video_y = ''
|
### end of scan
|
||||||
for line in info:
|
if wobj.sbid != 0:
|
||||||
l = line.split('=')
|
wobj.status.remove(wobj.sbSearchCId, wobj.sbid)
|
||||||
val = l[1].split('\n')[0]
|
wobj.sbid = wobj.status.push(wobj.sbSearchCId, "Scannig: %s" % (os.path.join(root,i)))
|
||||||
if l[0] == 'ID_VIDEO_FORMAT':
|
|
||||||
video_format = val
|
|
||||||
elif l[0] == 'ID_AUDIO_CODEC':
|
|
||||||
audio_codec = val
|
|
||||||
elif l[0] == 'ID_VIDEO_CODEC':
|
|
||||||
video_codec = val
|
|
||||||
elif l[0] == 'ID_VIDEO_WIDTH':
|
|
||||||
video_x = val
|
|
||||||
elif l[0] == 'ID_VIDEO_HEIGHT':
|
|
||||||
video_y = val
|
|
||||||
|
|
||||||
if self.sbid != 0:
|
wobj.progress.set_fraction(frac * _count)
|
||||||
self.status.remove(self.sbSearchCId, self.sbid)
|
|
||||||
self.sbid = self.status.push(self.sbSearchCId, "Scannig: %s" % (os.path.join(root,p)))
|
|
||||||
|
|
||||||
self.progress.set_fraction(frac * count)
|
|
||||||
count+=1
|
|
||||||
|
|
||||||
# PyGTK FAQ entry 23.20
|
# PyGTK FAQ entry 23.20
|
||||||
while gtk.events_pending(): gtk.main_iteration()
|
while gtk.events_pending(): gtk.main_iteration()
|
||||||
#current_dir[] =
|
|
||||||
print a
|
f.add_member(fileObj(name=i, size=st.st_size, filetype="r", mtime=st.st_mtime))
|
||||||
#for i in current_dir:
|
|
||||||
# print i
|
return f
|
||||||
|
|
||||||
|
fileobj = recurse(path,'/',self,0,frac)
|
||||||
|
|
||||||
if self.sbid != 0:
|
if self.sbid != 0:
|
||||||
self.status.remove(self.sbSearchCId, self.sbid)
|
self.status.remove(self.sbSearchCId, self.sbid)
|
||||||
self.sbid = self.status.push(self.sbSearchCId, "Idle")
|
self.sbid = self.status.push(self.sbSearchCId, "Idle")
|
||||||
|
|
||||||
self.progress.set_fraction(0)
|
self.progress.set_fraction(0)
|
||||||
|
|
||||||
def about(self,widget):
|
def about(self,widget):
|
||||||
dialogs.Abt("pyGTKtalog", __version__, "About", ["Roman 'gryf' Dobosz"], licence)
|
dialogs.Abt("pyGTKtalog", __version__, "About", ["Roman 'gryf' Dobosz"], licence)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user