Continued work on GEP008: move src/Mime to src/gen/mime.

svn: r14118
This commit is contained in:
Brian Matherly 2010-01-24 20:17:14 +00:00
parent 09b0e50d41
commit cd30f4db2f
20 changed files with 80 additions and 172 deletions

View File

@ -94,22 +94,23 @@ src/const.py
src/Makefile
src/cli/Makefile
src/gen/Makefile
src/gen/display/Makefile
src/gen/proxy/Makefile
src/gen/db/Makefile
src/gen/display/Makefile
src/gen/lib/Makefile
src/gen/utils/Makefile
src/gen/mime/Makefile
src/gen/plug/Makefile
src/gen/plug/docbackend/Makefile
src/gen/plug/docgen/Makefile
src/gen/plug/menu/Makefile
src/gen/proxy/Makefile
src/gen/utils/Makefile
src/gui/Makefile
src/gui/editors/Makefile
src/gui/editors/displaytabs/Makefile
src/gui/selectors/Makefile
src/gui/views/Makefile
src/gui/views/treemodels/Makefile
src/Mime/Makefile
src/gui/widgets/Makefile
src/GrampsLogger/Makefile
src/Merge/Makefile
src/docgen/Makefile
@ -124,7 +125,6 @@ src/Filters/Rules/MediaObject/Makefile
src/Filters/Rules/Repository/Makefile
src/Filters/Rules/Note/Makefile
src/Filters/SideBar/Makefile
src/gui/widgets/Makefile
src/Simple/Makefile
src/GrampsLocale/Makefile
src/PluginUtils/Makefile

View File

@ -54,21 +54,6 @@ src/cli/grampscli.py
src/gen/__init__.py
src/gen/updatecallback.py
# gen display API
src/gen/display/name.py
# gen utils API
src/gen/utils/__init__.py
src/gen/utils/callback.py
src/gen/utils/callman.py
# gen proxy API
src/gen/proxy/living.py
src/gen/proxy/private.py
src/gen/proxy/proxybase.py
src/gen/proxy/filter.py
src/gen/proxy/__init__.py
# gen db API
src/gen/db/backup.py
src/gen/db/base.py
@ -78,6 +63,9 @@ src/gen/db/dbconst.py
src/gen/db/__init__.py
src/gen/db/undoredo.py
# gen display API
src/gen/display/name.py
# gen lib API
src/gen/lib/witness.py
src/gen/lib/__init__.py
@ -135,6 +123,12 @@ src/gen/lib/researcher.py
src/gen/lib/familyreltype.py
src/gen/lib/ldsord.py
# gen mime API
src/gen/mime/__init__.py
src/gen/mime/_gnomemime.py
src/gen/mime/_pythonmime.py
src/gen/mime/_winmime.py
# gen plugin API
src/gen/plug/__init__.py
src/gen/plug/_docgenplugin.py
@ -179,6 +173,18 @@ src/gen/plug/docbackend/__init__.py
src/gen/plug/docbackend/cairobackend.py
src/gen/plug/docbackend/docbackend.py
# gen proxy API
src/gen/proxy/living.py
src/gen/proxy/private.py
src/gen/proxy/proxybase.py
src/gen/proxy/filter.py
src/gen/proxy/__init__.py
# gen utils API
src/gen/utils/__init__.py
src/gen/utils/callback.py
src/gen/utils/callman.py
# gui - GUI code
src/gui/__init__.py
src/gui/dbguielement.py
@ -349,11 +355,6 @@ src/GrampsLogger/_GtkHandler.py
src/GrampsLogger/__init__.py
src/GrampsLogger/_RotateHandler.py
# Mime package
src/Mime/_GnomeMime.py
src/Mime/__init__.py
src/Mime/_PythonMime.py
# plugins directory
src/plugins/BookReport.py
src/plugins/bookreport.gpr.py

View File

@ -15,7 +15,6 @@ SUBDIRS = \
images \
Merge \
mapstraction \
Mime \
PluginUtils \
plugins \
ReportBase \

View File

@ -47,7 +47,6 @@ import gobject
#
#-------------------------------------------------------------------------
import const
import Mime
#-------------------------------------------------------------------------
#

View File

@ -6,7 +6,8 @@
SUBDIRS = \
db \
display \
lib\
lib \
mime \
plug \
proxy \
utils

View File

@ -30,4 +30,4 @@ The gen module provides 5 packages.
5. gen.utils provides some generic utilities
"""
__all__ = [ "proxy", "db", "lib", "utils", "plug" ]
__all__ = [ "db", "display", "lib", "mime", "plug", "proxy", "utils" ]

View File

@ -1,4 +1,4 @@
# This is the src/Mime level Makefile for Gramps
# This is the src/gen/mime level Makefile for Gramps
# We could use GNU make's ':=' syntax for nice wildcard use,
# but that is not necessarily portable.
# If not using GNU make, then list all .py files individually
@ -7,17 +7,17 @@ pkgdatadir = $(datadir)/@PACKAGE@/Mime
pkgdata_PYTHON = \
__init__.py\
_GnomeMime.py\
_WinMime.py\
_PythonMime.py
_gnomemime.py\
_winmime.py\
_pythonmime.py
pkgpyexecdir = @pkgpyexecdir@/Mime
pkgpythondir = @pkgpythondir@/Mime
pkgpyexecdir = @pkgpyexecdir@/gen/mime
pkgpythondir = @pkgpythondir@/gen/mime
# Clean up all the byte-compiled files
MOSTLYCLEANFILES = *pyc *pyo
GRAMPS_PY_MODPATH = "../"
GRAMPS_PY_MODPATH = "../../"
pycheck:
(export PYTHONPATH=$(GRAMPS_PY_MODPATH); \

View File

@ -19,12 +19,12 @@
#
try:
from _GnomeMime import *
from _gnomemime import get_description, get_type, mime_type_is_defined
except:
try:
from _WinMime import *
from _winmime import get_description, get_type, mime_type_is_defined
except:
from _PythonMime import *
from _pythonmime import get_description, get_type, mime_type_is_defined
def base_type(val):
return val.split('/')[0]

View File

@ -31,33 +31,6 @@ except:
from gen.ggettext import gettext as _
def get_application(type):
"""Return the application command and application name of the
specified mime type"""
try:
applist = mime_get_short_list_applications(type)
if applist:
applist = [mime_get_default_application(type)] + applist
for prog in applist:
if _is_good_command(prog[2]):
return (prog[2],prog[1])
else:
return None
else:
return None
except:
return None
def _is_good_command(cmd):
"""
We don't know what to do with certain substitution values.
If we find one, skip the command.
"""
for sub in [ "%m", "%i", "%c" ]:
if cmd.find(sub) != -1:
return False
return True
def get_description(type):
"""Return the description of the specified mime type."""
try:
@ -82,3 +55,17 @@ def mime_type_is_defined(type):
except:
return False
#-------------------------------------------------------------------------
#
# private functions
#
#-------------------------------------------------------------------------
def _is_good_command(cmd):
"""
We don't know what to do with certain substitution values.
If we find one, skip the command.
"""
for sub in [ "%m", "%i", "%c" ]:
if cmd.find(sub) != -1:
return False
return True

View File

@ -41,11 +41,6 @@ mimetypes.add_type('application/x-gramps-package','.gpkg')
mimetypes.add_type('application/x-gramps-package','.GPKG')
mimetypes.add_type('text/x-comma-separated-values', '.csv')
def get_application(mime_type):
"""Return the application command and application name of the
specified mime type"""
return None
def get_description(mime_type):
"""Return the description of the specified mime type"""
return _type_map.get(mime_type,_("unknown"))

View File

@ -31,66 +31,14 @@ Mime utility functions for the MS Windows platform
#-------------------------------------------------------------------------
import os
from _winreg import *
from gen.ggettext import gettext as _
#-------------------------------------------------------------------------
#
# Gramps modules
#
#-------------------------------------------------------------------------
import _PythonMime
def get_application(mime_type):
"""Return the application command and application name of the
specified mime type"""
extension = _get_extension(mime_type)
progid = _get_prog_id(extension)
if not progid:
return None
# Find the application associated with this program ID
hcr = ConnectRegistry(None, HKEY_CLASSES_ROOT)
subkey = OpenKey(hcr, "%s\shell\open\command" % progid)
if subkey:
name, command, data_type = EnumValue(subkey, 0)
if data_type == REG_EXPAND_SZ:
command = command.replace( '%SystemRoot%',
os.getenv('SystemRoot') )
CloseKey(hcr)
else:
return None
CloseKey(subkey)
# Find a friendly name for the application
if command.startswith('"'):
app = command.split('"')[1]
elif command.startswith('rundll32.exe'):
# Get the description of the DLL instead of the application
app = command.split()[1].split(',')[0]
else:
app = command.split()[0]
hcu = ConnectRegistry(None, HKEY_CURRENT_USER)
try:
subkey = OpenKey(hcu, "Software\Microsoft\Windows\ShellNoRoam\MUICache")
except WindowsError:
subkey = None
desc = None
if subkey:
try:
desc, data_type = QueryValueEx(subkey, app)
except WindowsError:
# No friendly name exists. Use progid
desc = progid
CloseKey(subkey)
else:
desc = progid
CloseKey(hcu)
return (command, desc)
import _pythonmime
from gen.ggettext import gettext as _
def get_description(mime_type):
"""Return the description of the specfied mime type"""
@ -110,7 +58,7 @@ def get_description(mime_type):
def get_type(file):
"""Return the mime type of the specified file"""
return _PythonMime.get_type(file)
return _pythonmime.get_type(file)
def mime_type_is_defined(mime_type):
"""
@ -120,7 +68,7 @@ def mime_type_is_defined(mime_type):
if extension:
return True
else:
return _PythonMime.mime_type_is_defined(mime_type)
return _pythonmime.mime_type_is_defined(mime_type)
#-------------------------------------------------------------------------
#

View File

@ -42,7 +42,7 @@ LOG = logging.getLogger(".")
# GRAMPS modules
#
#-------------------------------------------------------------------------
from Mime import mime_type_is_defined
from gen.mime import mime_type_is_defined
import TransUtils
#-------------------------------------------------------------------------

View File

@ -53,7 +53,7 @@ import gtk
import const
import config
import Utils
import Mime
import gen.mime
import ThumbNails
import GrampsDisplay
import ManagedWindow
@ -162,7 +162,7 @@ class AddMediaObject(ManagedWindow.ManagedWindow):
filename = Utils.relative_path(filename, pname)
mtype = Mime.get_type(full_file)
mtype = gen.mime.get_type(full_file)
description = description or os.path.basename(filename)
self.obj.set_description(description)
@ -197,7 +197,7 @@ class AddMediaObject(ManagedWindow.ManagedWindow):
filename = Utils.find_file( filename)
if filename:
mtype = Mime.get_type(filename)
mtype = gen.mime.get_type(filename)
if mtype and mtype.startswith("image"):
image = scale_image(filename, const.THUMBSCALE)
else:

View File

@ -52,7 +52,7 @@ import gen.lib
import Utils
import ThumbNails
import Errors
import Mime
import gen.mime
from DdTargets import DdTargets
from buttontab import ButtonTab
@ -458,8 +458,8 @@ class GalleryTab(ButtonTab, DbGUIElement):
protocol, site, mfile, j, k, l = urlparse.urlparse(d)
if protocol == "file":
name = Utils.fix_encoding(mfile)
mime = Mime.get_type(name)
if not Mime.is_valid_type(mime):
mime = gen.mime.get_type(name)
if not gen.mime.is_valid_type(mime):
return
photo = gen.lib.MediaObject()
photo.set_path(name)
@ -477,28 +477,6 @@ class GalleryTab(ButtonTab, DbGUIElement):
self.dbstate.db.transaction_commit(trans,
_("Drag Media Object"))
self.rebuild()
# elif protocol != "":
# import urllib
# u = urllib.URLopener()
# try:
# tfile, headers = u.retrieve(d)
# except (IOError,OSError), msg:
# t = _("Could not import %s") % d
# ErrorDialog(t,str(msg))
# return
# tfile = Utils.fix_encoding(tfile)
# mime = GrampsMime.get_type(tfile)
# photo = gen.lib.MediaObject()
# photo.set_mime_type(mime)
# photo.set_description(d)
# photo.set_path(tfile)
# trans = self.db.transaction_begin()
# self.db.add_object(photo,trans)
# self.db.transaction_commit(trans,_("Drag Media Object"))
# oref = gen.lib.MediaRef()
# oref.set_reference_handle(photo.get_handle())
# self.dataobj.add_media_reference(oref)
# self.add_thumbnail(oref)
def handle_extra_type(self, objtype, obj):
pass

View File

@ -42,7 +42,7 @@ import gtk
#-------------------------------------------------------------------------
from gui.utils import open_file_with_default_application
import gen.lib
import Mime
import gen.mime
import ThumbNails
import Utils
from editprimary import EditPrimary
@ -138,7 +138,7 @@ class EditMedia(EditPrimary):
self.draw_preview()
def determine_mime(self):
descr = Mime.get_description(self.obj.get_mime_type())
descr = gen.mime.get_description(self.obj.get_mime_type())
if descr:
self.mimetext.set_text(descr)
@ -146,9 +146,9 @@ class EditMedia(EditPrimary):
path_full = Utils.media_path_full(self.db, path)
if path != self.obj.get_path() and path_full != self.obj.get_path():
#redetermine mime
mime = Mime.get_type(Utils.find_file(path_full))
mime = gen.mime.get_type(Utils.find_file(path_full))
self.obj.set_mime_type(mime)
descr = Mime.get_description(mime)
descr = gen.mime.get_description(mime)
if descr:
self.mimetext.set_text(descr)
else:

View File

@ -43,7 +43,7 @@ import gtk
#-------------------------------------------------------------------------
from gui.utils import open_file_with_default_application
import const
import Mime
import gen.mime
import ThumbNails
import Utils
from gen.lib import NoteType
@ -110,7 +110,7 @@ class EditMediaRef(EditReference):
self.rectangle)
self.subpixmap.set_from_pixbuf(self.subpix)
mt = Mime.get_description(self.mtype)
mt = gen.mime.get_description(self.mtype)
self.top.get_object("type").set_text(mt if mt else "")
def _setup_fields(self):

View File

@ -38,7 +38,7 @@ import re
#
#-------------------------------------------------------------------------
from QuestionDialog import ErrorDialog, WarningDialog
import Mime
import gen.mime
import gen.lib
import Utils
import DateHandler
@ -1678,7 +1678,7 @@ class GrampsParser(UpdateCallback):
attr.set_type(key)
attr.set_value(attrs[key])
self.photo.add_attribute(attr)
self.photo.set_mime_type(Mime.get_type(self.photo.get_path()))
self.photo.set_mime_type(gen.mime.get_type(self.photo.get_path()))
self.db.add_object(self.photo, self.trans)
#set correct change time
self.db.commit_media_object(self.photo, self.trans, self.change)

View File

@ -113,7 +113,7 @@ import Errors
import const
import gen.lib
from gen.updatecallback import UpdateCallback
import Mime
import gen.mime
import LdsUtils
import Utils
from DateHandler._DateParser import DateParser
@ -4981,7 +4981,7 @@ class GedcomParser(UpdateCallback):
self.__warn(_("Could not import %s") % filename[0])
path = filename[0].replace('\\', os.path.sep)
state.media.set_path(path)
state.media.set_mime_type(Mime.get_type(path))
state.media.set_mime_type(gen.mime.get_type(path))
if not state.media.get_description():
state.media.set_description(path)
@ -5561,7 +5561,7 @@ class GedcomParser(UpdateCallback):
photo.set_description(title)
full_path = os.path.abspath(path)
if os.path.isfile(full_path):
photo.set_mime_type(Mime.get_type(full_path))
photo.set_mime_type(gen.mime.get_type(full_path))
else:
photo.set_mime_type(MIME_MAP.get(form.lower(), 'unknown'))
self.dbase.add_object(photo, self.trans)

View File

@ -54,7 +54,7 @@ import const
import config
import Utils
import Bookmarks
import Mime
import gen.mime
import gen.lib
from gui.editors import EditMedia, DeleteMediaQuery
import Errors
@ -190,8 +190,8 @@ class MediaView(ListView):
protocol, site, mfile, j, k, l = urlparse.urlparse(d)
if protocol == "file":
name = Utils.fix_encoding(mfile)
mime = Mime.get_type(name)
if not Mime.is_valid_type(mime):
mime = gen.mime.get_type(name)
if not gen.mime.is_valid_type(mime):
return
photo = gen.lib.MediaObject()
photo.set_path(name)

View File

@ -92,7 +92,7 @@ import Utils
from gui.utils import ProgressMeter
import ThumbNails
import ImgManip
import Mime
import gen.mime
from QuestionDialog import ErrorDialog, WarningDialog
from gen.display.name import displayer as _nd
from DateHandler import displayer as _dd
@ -2574,7 +2574,7 @@ class MediaPage(BasePage):
# get media type to be used primarily with "img" tags
mime_type = media.get_mime_type()
mtype = Mime.get_description(mime_type)
mtype = gen.mime.get_description(mime_type)
if mime_type:
note_only = False