Example #1
0
def __launch(delegate):
    ''' 
   Runs the given (no-argument) delegate method in a 'safe' script environment.
   This environment will take care of all error handling, logging/debug stream,
   and other standard initialization behaviour before delegate() is called, and
   it will take care of cleaning everything up afterwards.
   '''
    try:
        # initialize the application resources (import directories, etc)
        Resources.initialize()

        # fire up the debug logging system
        log.install(ComicRack.MainWindow)

        # install a handler to catch uncaught Winforms exceptions
        def exception_handler(sender, event):
            del sender  #unused
            log.handle_error(event.Exception)
        Application.ThreadException \
           += ThreadExceptionEventHandler(exception_handler)

        # fire up the localization/internationalization system
        i18n.install(ComicRack)

        # see if we're in a valid environment
        if __validate_environment():
            delegate()

    except Exception, ex:
        log.handle_error(ex)
def __launch(delegate):
   ''' 
   Runs the given (no-argument) delegate method in a 'safe' script environment.
   This environment will take care of all error handling, logging/debug stream,
   and other standard initialization behaviour before delegate() is called, and
   it will take care of cleaning everything up afterwards.
   ''' 
   try:
      # initialize the application resources (import directories, etc)
      Resources.initialize()
      
      # fire up the debug logging system
      log.install(ComicRack.MainWindow)
      
      # install a handler to catch uncaught Winforms exceptions
      def exception_handler(sender, event):
         log.handle_error(event.Exception)
      Application.ThreadException \
         += ThreadExceptionEventHandler(exception_handler)
         
      # fire up the localization/internationalization system
      i18n.install(ComicRack)
      
      # see if we're in a valid environment
      if __validate_environment():
         delegate()
         
   except Exception, ex:
      log.handle_error(ex)
Example #3
0
def parse_args():
    """Read and parse options from command line
	Initialize logging

	Return values:
	options: options and arguments parsed from command line
	confs: configuration file dictionary information
	"""
    usage = """usage: %prog [options]
To crawl pages from web in terms of special URL patterns."""

    parser = optparse.OptionParser(usage=usage, version='%prog 1.0.0.0')
    parser.add_option('-c',
                      dest='filename',
                      help='read config file',
                      metavar='FILE')

    parser.add_option('-l',
                      '--log',
                      dest='log',
                      action='store_true',
                      help='start logging',
                      default=False)

    options, args = parser.parse_args()
    if options.filename is None:
        print parser.format_help()
        parser.exit()
    else:
        confs = utils.parse_config_file(options.filename)
        if options.log:
            log.read_config_file(confs['log']['log_config_file'])
            log.install(confs['log']['log_name'])
        else:
            log.uninstall()

        return options, confs
Example #4
0
            # than image average, and 0 means pixel is less than average.
            # return bits as a single long value
            pixels = [small_image.GetPixel(x,y).R 
                      for x in range(SIZE) for y in range(SIZE)];
            average = reduce(lambda x,y: x+y, pixels) / float(len(pixels))
            bits = map(lambda x: 1 if x > average else 0, pixels ) 
            return reduce(lambda x, (i, val): x|(val<<i), enumerate(bits), 0)
         
   else:
      return long(0);
   

#==============================================================================
# this is just testing code for working on the matching algorithm
if __name__ == '__main__':  
   log.install()
   
   samples_dir = r"K:/imgcmp/"
   bases = ["animalman", "armydark", "detective", "hip", 
            "locke", "snow", "tower", "joe", "bedlam"]
   compares = [(x+"-a.jpg",x+"-b.jpg") for x in bases] +\
      [("random.jpg",x+"-a.jpg")for x in bases] 
   
   for file1, file2 in compares:
      with Image.FromFile(samples_dir+file1) as image1:
         with Image.FromFile(samples_dir+file2) as image2:
            hash1 = hash(image1)
            hash2 = hash(image2)
            #log.debug()
            #log.debug("hash1: ", bin(hash1)[2:].zfill(64))
            #log.debug("hash2: ", bin(hash2)[2:].zfill(64))
Example #5
0
 def run(self, result):
    # overridden to install our logging framework during unit tests!
    log.install(None)
    super(AllTests, self).run(result)
    log.uninstall()