Пример #1
0
    def __str__(self, key_blacklist=None):
        '''The primary line, ie not including any comments'''
        if key_blacklist is None:
            key_blacklist = []

        self.update()

        dbg()
        dbg('original: %s' % self.text)
        dbg('variables: %s' % self.variables)

        ret = self.prefix()

        printed = set()
        for k in self.variable_print_order():
            if k in key_blacklist:
                continue
            if k in self.variables:
                v = self.variables[k]
                dbg('k: %s, v: %s' % (repr(k), repr(v)))
                printed.add(k)
                ret += ' %s' % self.print_variable(k)

        for k in self.variables:
            if k in key_blacklist:
                continue
            if k in printed:
                continue
            ret += ' %s' % self.print_variable(k)

        dbg('final: %s' % ret)

        return ret
Пример #2
0
    def from_tagged_file_names(image_file_names):
        engine = GridStitch()
        engine.image_file_names = image_file_names
        dbg('Orig file names: %s' % str(image_file_names))

        file_names_canonical = list()
        for file_name in image_file_names:
            new_fn = os.path.realpath(file_name)
            engine.canon2orig[new_fn] = file_name
            file_names_canonical.append(new_fn)

        engine.coordinate_map = ImageCoordinateMap.from_tagged_file_names(
            file_names_canonical)

        return engine
Пример #3
0
    def reparse(self):
        self.variables = dict()
        first = True
        #for token in self.text.split(' '):
        for (k, v) in self.get_tokens():
            #print 'token: "%s"' % token
            #k = token[0]
            #v = token[1:]
            dbg('k: %s, v: %s' % (repr(k), repr(v)))

            # We can still have empty string
            if not v is None and len(v) == 0:
                v = None
            if first:
                prefix = k
                if not v is None and len(v) > 0:
                    print 'Line: %s' % self.text
                    print 'ERROR: line type should not have value: %s' % repr(
                        v)
                    raise Exception('confused')
                first = False
                continue

            # Convert if possible
            try:
                if k in self.key_variables():
                    pass
                elif k in self.int_variables():
                    v = int(v)
                elif k in self.float_variables():
                    v = float(v)
                elif k in self.string_variables():
                    # Already in string form
                    pass
                else:
                    print 'WARNING: unknown data type on %s (full: %s)' % (
                        k, self.text)
                    raise Exception('Unknown key %s' % k)
            except:
                print 'line: %s' % self.text
                print 'key: %s, value: %s' % (repr(k), repr(v))
                self.print_variables()
                raise

            # Ready to roll
            self.set_variable(k, v)
Пример #4
0
    def get_tokens(self):
        '''
		Returns a list of (k, v) pairs
		If it has no v, v will be None
		
		Tokens can have quotes around them
		Ex:
		n"TIFF c:NONE r:CROP"
		
		Internally, we do not store these
		Instead, they will be re-added when writing
		'''
        tokens = list()
        i = 0
        # Some version have a0, some have a=0 although a0 seems much more common
        while i < len(self.text):
            k = ''
            v = None

            # Find the key: keep going until we hit either ", number, or space
            while i < len(self.text):
                c = self.text[i]
                # End of this k/v?
                if c == ' ':
                    i += 1
                    break
                # A quoted value?
                elif c == '"':
                    i += 1
                    v = ''
                    # Note we skip the "
                    while True:
                        if i >= len(self.text):
                            raise Exception('Missing closing " on %s' %
                                            self.text)
                        c = self.text[i]
                        if c == '"':
                            i += 1
                            break
                        v += c
                        i += 1
                    # Think we should have at most one quoted thingy
                    break
                # A numeric value?
                elif c in '+-0123456789':
                    v = ''
                    # Note we include the original char
                    while i < len(self.text):
                        c = self.text[i]
                        if c == ' ':
                            i += 1
                            break
                        v += c
                        i += 1
                    break
                else:
                    # This may not be bulletproof but I think its good enough
                    # These lines show up when you add images in Hugin
                    # ex bad: a=a but I'm not sure thats valid anyway
                    if c != '=':
                        k += c

                i += 1

            # Discard extra spaces and some other corner cases
            if len(k) > 0:
                tokens.append((k, v))
        dbg(tokens)
        return tokens