def read(self): path = os.path.normpath( os.path.join(self.index.source_dir if self.index else '', self.src)) logger.debug("Trying to read file '%s'" % path) with open(path, encoding='utf-8') as fl: return fl.read()
def load_ext_modules(ext): "Load the modules mapped with passed file extension" logger.debug('Loading modules mapped with specified extension "%s"'%ext) if not MODULES.__contains__(ext) or not MODULES[ext]: logger.error('No module names mapped with %s'%ext) modules = MODULES[ext] for filename in modules: __import__(filename) modules.pop(0)
def get_class_by_format(filename): "Find file extension of the passed filename and return mapped class mapped with that" logger.debug('Trying to get matching of %s'%basename(filename)) ext = splitext(filename)[1][1:] if not FORMATS.__contains__(ext): try: logger.warning('Extension "%s" is not mapped to any class'%ext) load_ext_modules(ext) except: raise Exception('File with unknown format:',filename) return FORMATS[ext]
def read(self): path = os.path.normpath(os.path.join(self.index.source_dir if self.index else '',self.src)) logger.debug("Trying to read file '%s'"%path) with open(path,encoding='utf-8') as fl: return fl.read()
import os.path from jsbuild.logging import logger DIR = os.path.dirname(__file__) TEMPLATES = ['package.js','module.js','maincall.js','file.js'] for filename, template in map(lambda path: (os.path.normpath(os.path.join(DIR,path)),os.path.splitext(path)[0]), TEMPLATES): logger.debug('Trying to read the template named "%s" and located at "%s"'%(template,filename)) with open(filename,encoding='utf-8') as source_code: globals()[template] = source_code.read()
def parse(self): logger.debug('Parsing %s'%self.src) lib = __import__('json') return lib.loads(self.buffer)