ldraw.py

changeset 3
1dc58f44d556
parent 2
50d3086070df
child 4
8eb83f200486
equal deleted inserted replaced
2:50d3086070df 3:1dc58f44d556
1 #!/usr/bin/env python3 1 class Color:
2 from parse import parse_ldraw_code 2 def __init__(self, index):
3 3 self.index = int(index, 0)
4 def read_ldraw(file, *, libraries): 4 def __str__(self):
5 result = list() 5 if self.is_direct_color():
6 for line in file: 6 # write direct colors with hex codes
7 result.append(parse_ldraw_code(line)) 7 return '0x%07X' % self.index
8 return result 8 else:
9 9 return str(self.index)
10 if __name__ == '__main__': 10 def is_direct_color(self):
11 from sys import argv 11 return self.index >= 0x2000000
12 libraries = [{'path': '/home/teemu/ldraw', 'role': 'official'}]
13 with open(argv[1], 'r') as file:
14 model = read_ldraw(file, libraries = libraries)
15 from pprint import pprint
16 pprint(model)

mercurial