Hi, I needed to run the kaa-metadata in pure python (to be able to easily redistribute it to Windows or Mac users).
This was not a big change, so I submit it to you, because it's better to remove a dependence. I took the 0.7.7 release. The modifications are in core.py and factory.py, and you need to include strutils.py (with this small patch for Mac OS): 39,40c39 < # added ValueError for Mac binary < except (UnicodeError, TypeError, ValueError): --- > except (UnicodeError, TypeError): As I am debugging, I had to modify factory.py so that the ParseError were recognised as they should be: I do not understand clearly the problem, but when a parser raise a core.ParseError (coming from video.core for example) it is not recognised as a kaa_metadata.core.ParseError (even though the video.core imports it correctly...) so I had to do the same trick you did for getting the parser info (with a runtime import) Update: after looking at the patch for core, I made the class ParseError inherit from Exception (it feels more logical to me, and we have a traceback for debuging if needed), so maybe my problem comes from this modification: please tell me if it's the case. Here are the patch files, and feel free to give me any comments or advices. Regards, Louis Plissonneau PS: I had some more errors on windows, so I still correct the code, and hopefully it will be independent of platform (I'm working only on video files up to now).
37,39c37 < #import kaa < # use strutils instead of kaa < import strutils as kaa --- > import kaa 70c68 < class ParseError(Exception): --- > class ParseError:
37c37 < #import sys --- > import sys 43c43 < #import kaa.utils --- > import kaa.utils 45c45 < # kaa_metadata imports --- > # kaa.metadata imports 49c49 < log = logging.getLogger('pytomo') --- > log = logging.getLogger('metadata') 61,90d60 < # from kaa.utils < class Singleton(object): < """ < Create Singleton object from classref on demand. < """ < < class MemberFunction(object): < def __init__(self, singleton, name): < self._singleton = singleton < self._name = name < < def __call__(self, *args, **kwargs): < return getattr(self._singleton(), self._name)(*args, **kwargs) < < < def __init__(self, classref): < self._singleton = None < self._class = classref < < def __call__(self): < if self._singleton is None: < self._singleton = self._class() < return self._singleton < < def __getattr__(self, attr): < if self._singleton is None: < return Singleton.MemberFunction(self, attr) < return getattr(self._singleton, attr) < < 125c95 < raised. This should not mappen for kaa_metadata parsers. --- > raised. This should not mappen for kaa.metadata parsers. 141d110 < self.errormap = {} 160d128 < return self.classmap[name] 162,178c130 < def get_error(self, name): < """Return the ParseError exception from the module < Needed for the catching the correct exception in create_from_file < """ < if '.' in name: < name = '.'.join(name.split('.')[:-1] + ['core']) < if name not in self.errormap: < # Import the parser class for the given name. < try: < exec('from %s import ParseError' % name) < self.errormap[name] = ParseError < except Exception: < # Something failed while trying to import this parser. < # log and use core.ParseError < log.exception('Error importing ParseError %s' % name) < self.errormap[name] = core.ParseError < return self.errormap[name] --- > return self.classmap[name] 200,201d151 < parser = self.get_class(info[R_CLASS]) < parse_error = self.get_error(info[R_CLASS]) 202a153 > parser = self.get_class(info[R_CLASS]) 204c155 < except parse_error: --- > except core.ParseError: 221,222d171 < parser = self.get_class(p[R_CLASS]) < parse_error = self.get_error(p[R_CLASS]) 223a173 > parser = self.get_class(p[R_CLASS]) 225c175 < except parse_error: --- > except core.ParseError: 244,245d193 < parser = self.get_class(e[R_CLASS]) < parse_error = self.get_error(e[R_CLASS]) 247,248c195,196 < return parser(file) < except parse_error: --- > return self.get_class(e[R_CLASS])(file) > except core.ParseError: 251c199 < log.exception('UNHANDLED ERROR') --- > log.exception('parser error') 281,282d228 < parser = self.get_class(e[R_CLASS]) < parse_error = self.get_error(e[R_CLASS]) 284,285c230,231 < return parser(url) < except parse_error: --- > return self.get_class(e[R_CLASS])(url) > except core.ParseError: 304,305d249 < parser = self.get_class(self.mimemap[mime][R_CLASS]) < parse_error = self.get_error(self.mimemap[mime][R_CLASS]) 307,308c251,252 < return parser(file) < except parse_error: --- > return self.get_class(self.mimemap[mime][R_CLASS])(file) > except core.ParseError: 340,341d283 < parser = self.get_class(e[R_CLASS]) < parse_error = self.get_error(e[R_CLASS]) 343c285 < t = parser(devicename) --- > t = self.get_class(e[R_CLASS])(devicename) 346c288 < except parse_error: --- > except core.ParseError: 357,358d298 < parser = self.get_class(e[R_CLASS]) < parse_error = self.get_error(e[R_CLASS]) 360,361c300,301 < return parser(dirname) < except parse_error: --- > return self.get_class(e[R_CLASS])(dirname) > except core.ParseError: 376,377c316 < # Windows Python has no os.uname < if (hasattr(os, 'uname') and os.uname()[0] == 'FreeBSD' and --- > if (os.uname()[0] == 'FreeBSD' and \ 385c324 < log.exception('kaa_metadata.create error') --- > log.exception('kaa.metadata.create error') 393c332 < register the parser to kaa_metadata --- > register the parser to kaa.metadata 439c378 < Factory = Singleton(_Factory) --- > Factory = kaa.utils.Singleton(_Factory)
------------------------------------------------------------------------------ Create and publish websites with WebMatrix Use the most popular FREE web apps or write code yourself; WebMatrix provides all the features you need to develop and publish your website. http://p.sf.net/sfu/ms-webmatrix-sf
_______________________________________________ Freevo-devel mailing list Freevo-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/freevo-devel