示例#1
0
def configureLogging(fileLevel=DEBUG, screenLevel=WARNING):
    """ 
	Set up logging based on configuration options 
	
	@return: None
	"""
    global logger

    if 'logger' in globals():
        raise Exception('Logging has already been configured')

    logger = logging.getLogger('scanmanager')
    logger.propagate = False

    handler = logging.handlers.RotatingFileHandler(
        filename=os.path.join(smDataPath(), 'scanmanager.log'),
        mode='a',
        #		maxBytes=(1024)*1024,
        #		backupCount=10,
    )
    handler.setLevel(DEBUG)
    formatter = logging.Formatter('%(asctime)s %(levelname)-8s %(message)s')
    handler.setFormatter(formatter)
    logger.addHandler(handler)

    if screenLevel is not None:
        console = logging.StreamHandler()
        console.setLevel(DEBUG)
        formatter = logging.Formatter(
            '%(asctime)s %(levelname)-8s %(message)s')
        console.setFormatter(formatter)
        logger.addHandler(console)

    logger.setLevel(-1)
示例#2
0
def configureLogging(fileLevel=DEBUG,screenLevel=WARNING):
	""" 
	Set up logging based on configuration options 
	
	@return: None
	"""
	global logger
	
	if 'logger' in globals():
		raise Exception('Logging has already been configured')
	
	logger = logging.getLogger('scanmanager')
	logger.propagate = False
	
	handler = logging.handlers.RotatingFileHandler(
		filename=os.path.join(smDataPath(),'scanmanager.log'),
		mode='a',
#		maxBytes=(1024)*1024,
#		backupCount=10,
	)
	handler.setLevel(DEBUG)
	formatter = logging.Formatter('%(asctime)s %(levelname)-8s %(message)s')
	handler.setFormatter(formatter)
	logger.addHandler(handler)
	
	if screenLevel is not None:
		console = logging.StreamHandler()
		console.setLevel(DEBUG)
		formatter = logging.Formatter('%(asctime)s %(levelname)-8s %(message)s')
		console.setFormatter(formatter)
		logger.addHandler(console)

	logger.setLevel(-1)
示例#3
0
	def init(self):
		
		dbFile = os.path.join(smDataPath(),'scanmanager.settings')
		
		if not os.path.exists(dbFile):
			shutil.copyfile(os.path.join(smBasePath(),'scanmanager.settings.default'),dbFile)
		
		# open a db and check we can access its keys
		db = shelve.open(dbFile)
		[i for i in db.keys()]
		db.close()
		
		# db seems OK -- make a backup and then open it for real
		shutil.copyfile(dbFile,os.path.join(smDataPath(),'scanmanager.settings.backup'))
		self.db = shelve.open(dbFile)
		
		if not self.db.keys():
			self.db['version'] = base.smGetSettingsVersion()
		self.settings = ApplicationMainSettings(db=self.db)
		if not self.settings.load():
				log.error('Settings file out of date')
				e = QtGui.QMessageBox.critical(
					None,
					self.tr('Error'),
					self.tr('''
						<p>Your scanmanager.settings file appears to be out of date (existing settings version %s, app settings version %s).</p>
						<p>Try deleting %s</p>''') % (
							self.db.get('version',None),
							base.smGetSettingsVersion(),
							os.path.join(base.smDataPath(),'scanmanager.settings')
						)
				)
				self.quit()
				return
			
		self.images = []
		
		backend.apis = backend.BackendManager(trace=base.runtimeOptions.trace)
		apis = backend.apis
		apis.loadAll()
		apis.openAll(db=self.db)
		errorText = apis.formatAPIErrors()
		if errorText:
			sys.stderr.write(errorText)
		

		self.processingQueue = processing.ProcessingQueue()
		
		self.setWindowIcon(QtGui.QIcon(':/scanmanager-16.png'))
		self.SetupWindow.initialiseOptions()
		self.SetupWindow.show()
		self.SetupWindow.loadSettings()
示例#4
0
    def init(self):

        dbFile = os.path.join(smDataPath(), 'scanmanager.settings')

        if not os.path.exists(dbFile):
            shutil.copyfile(
                os.path.join(smBasePath(), 'scanmanager.settings.default'),
                dbFile)

        # open a db and check we can access its keys
        db = shelve.open(dbFile)
        [i for i in db.keys()]
        db.close()

        # db seems OK -- make a backup and then open it for real
        shutil.copyfile(
            dbFile, os.path.join(smDataPath(), 'scanmanager.settings.backup'))
        self.db = shelve.open(dbFile)

        if not self.db.keys():
            self.db['version'] = base.smGetSettingsVersion()
        self.settings = ApplicationMainSettings(db=self.db)
        if not self.settings.load():
            log.error('Settings file out of date')
            e = QtGui.QMessageBox.critical(
                None, self.tr('Error'),
                self.tr('''
						<p>Your scanmanager.settings file appears to be out of date (existing settings version %s, app settings version %s).</p>
						<p>Try deleting %s</p>''') %
                (self.db.get('version', None), base.smGetSettingsVersion(),
                 os.path.join(base.smDataPath(), 'scanmanager.settings')))
            self.quit()
            return

        self.images = []

        backend.apis = backend.BackendManager(trace=base.runtimeOptions.trace)
        apis = backend.apis
        apis.loadAll()
        apis.openAll(db=self.db)
        errorText = apis.formatAPIErrors()
        if errorText:
            sys.stderr.write(errorText)

        self.processingQueue = processing.ProcessingQueue()

        self.setWindowIcon(QtGui.QIcon(':/scanmanager-16.png'))
        self.SetupWindow.initialiseOptions()
        self.SetupWindow.show()
        self.SetupWindow.loadSettings()
示例#5
0
	def open(self):
		
		if self.opened:
			return
		
		if platform.system().lower() == 'windows':
			from .remote import client
			self.api = client.GPhotoClient()
			self.opened = True
			self.api.open(workingDir=smDataPath(),basePath=os.path.join(smBasePath(),'backend','libgphoto2'))
		else:
			from . import api
			self.api = api.API()
			self.opened = True
			self.api.open()
示例#6
0
	class MyOptParser(optparse.OptionParser):
		def print_help(self):
			print 'ScanManager'
			print COMMAND_LINE_HELP
			
	parser = MyOptParser()
	parser.add_option('-d','--debug',action='store_true',dest='debug')
	parser.add_option('-t','--trace',action='store_true',dest='trace')
	(options, args) = parser.parse_args()
	
	base.runtimeOptions.debug = options.debug
	base.runtimeOptions.trace = options.trace

	if getattr(sys,'frozen',None) == 'windows_exe':
		sys.stdout = open(os.path.join(base.smDataPath(),'scanmanager.stdout.log'),'wt')
		sys.stderr = open(os.path.join(base.smDataPath(),'scanmanager.stdout.log'),'wt')

	try:
		if base.runtimeOptions.debug:
			log.configureLogging(fileLevel=log.DEBUG,screenLevel=log.DEBUG)
		else:
			log.configureLogging(fileLevel=log.DEBUG,screenLevel=log.WARNING)
			
		log.debug('starting up on %s'%sys.platform)
		
		try:
			log.debug('running on %s'%('; '.join(platform.uname())))
		except:
			pass
		
示例#7
0
    class MyOptParser(optparse.OptionParser):
        def print_help(self):
            print 'ScanManager'
            print COMMAND_LINE_HELP

    parser = MyOptParser()
    parser.add_option('-d', '--debug', action='store_true', dest='debug')
    parser.add_option('-t', '--trace', action='store_true', dest='trace')
    (options, args) = parser.parse_args()

    base.runtimeOptions.debug = options.debug
    base.runtimeOptions.trace = options.trace

    if getattr(sys, 'frozen', None) == 'windows_exe':
        sys.stdout = open(
            os.path.join(base.smDataPath(), 'scanmanager.stdout.log'), 'wt')
        sys.stderr = open(
            os.path.join(base.smDataPath(), 'scanmanager.stdout.log'), 'wt')

    try:
        if base.runtimeOptions.debug:
            log.configureLogging(fileLevel=log.DEBUG, screenLevel=log.DEBUG)
        else:
            log.configureLogging(fileLevel=log.DEBUG, screenLevel=log.WARNING)

        log.debug('starting up on %s' % sys.platform)

        try:
            log.debug('running on %s' % ('; '.join(platform.uname())))
        except:
            pass