Beispiel #1
0
 def getModifiedFilesWithGivenSuffix(self, suffix):
     files = []
     for path in self._getPaths():
         value = path.firstChild.nodeValue
         if path.getAttribute("action") == "M" and value.endswith(suffix):
             files.append(value)
     return files
Beispiel #2
0
def conv_svg(fn, char, glyphnum = None):
  global lastglyphnum
  global header_printed
  if not header_printed:
    print_header()
  if glyphnum == None:
    glyphnum = lastglyphnum + 1
  lastglyphnum = glyphnum
  print 'StartChar:', os.path.basename(fn)[:-4]
  print 'Encoding: %d %d %d' % (char, glyphnum, char)
  print 'Width: %d' % (21 * 40)
  print 'Flags: W'
  print 'LayerCount: 2'
  print 'Fore'
  print 'SplineSet'
  doc = xml.dom.minidom.parse(fn)
  # TODO: reverse paths if fill color is white-ish (this is more code,
  # and in the meantime, we'll rely on correct path direction in FF)
  for path in doc.getElementsByTagName('path'):
    path_to_sfd(path.getAttribute('d'))
  for polygon in doc.getElementsByTagName('polygon'):
    path_to_sfd('M' + polygon.getAttribute('points') + 'z')
  for circle in doc.getElementsByTagName('circle'):
    cx = float(circle.getAttribute('cx'))
    cy = float(circle.getAttribute('cy'))
    r = float(circle.getAttribute('r'))
    circle_to_sfd(cx, cy, r)
  print 'EndSplineSet'
  print 'EndChar'
Beispiel #3
0
def conv_svg(fn, char, glyphnum=None):
    global lastglyphnum
    global header_printed
    if not header_printed:
        print_header()
    if glyphnum == None:
        glyphnum = lastglyphnum + 1
    lastglyphnum = glyphnum
    print 'StartChar:', os.path.basename(fn)[:-4]
    print 'Encoding: %d %d %d' % (char, glyphnum, char)
    print 'Width: %d' % (21 * 40)
    print 'Flags: W'
    print 'LayerCount: 2'
    print 'Fore'
    print 'SplineSet'
    doc = xml.dom.minidom.parse(fn)
    # TODO: reverse paths if fill color is white-ish (this is more code,
    # and in the meantime, we'll rely on correct path direction in FF)
    for path in doc.getElementsByTagName('path'):
        path_to_sfd(path.getAttribute('d'))
    for polygon in doc.getElementsByTagName('polygon'):
        path_to_sfd('M' + polygon.getAttribute('points') + 'z')
    for circle in doc.getElementsByTagName('circle'):
        cx = float(circle.getAttribute('cx'))
        cy = float(circle.getAttribute('cy'))
        r = float(circle.getAttribute('r'))
        circle_to_sfd(cx, cy, r)
    print 'EndSplineSet'
    print 'EndChar'
Beispiel #4
0
def getSvgPaths(fileName):
    u"""Extracts path strings from XML."""
    doc = minidom.parse(fileName)  # parseString also exists
    svgPaths = [path.getAttribute('d') for path
                in doc.getElementsByTagName('path')]
    doc.unlink()
    return svgPaths
Beispiel #5
0
def getSvgPaths(fileName):
    u"""Extracts path strings from XML."""
    doc = minidom.parse(fileName)  # parseString also exists
    svgPaths = [path.getAttribute('d') for path
                in doc.getElementsByTagName('path')]
    doc.unlink()
    return svgPaths
Beispiel #6
0
def get_log( file, empty=True, multi=False, default='GENERAL' ):
	
	logs = []
	
	xmldoc = minidom.parse(file)
	data = xmldoc.toxml( 'utf-8' )
	xmldoc = minidom.parseString( data )
	
	for log in xmldoc.getElementsByTagName('logentry'):
		
		r = log.getAttribute('revision').encode('utf-8')
		m = ''
		
		try:
			m = log.getElementsByTagName('msg')[0].firstChild.nodeValue.encode('utf-8')
		except: pass
		
		m = m.strip()
		
		if not empty and len( m ) == 0:
			continue
		
		d = log.getElementsByTagName('date')[0].firstChild.nodeValue.encode('utf-8')
		d = d[0:10]
		
		dt = log.getElementsByTagName('date')[0].firstChild.nodeValue.encode('utf-8')
		dt = datetime.datetime( int(dt[0:4]), int(dt[5:7]), int(dt[8:10]), int(dt[11:13]), int(dt[14:16]), int(dt[17:19]) )
	
		a = log.getElementsByTagName('author')[0].firstChild.nodeValue.encode('utf-8')
		
		p = []
		for path in log.getElementsByTagName('path'):
			p.append( ( path.getAttribute('action').encode('utf-8'), path.firstChild.nodeValue.encode('utf-8') ) )
		
		c = default.upper()
		
		if not multi:
			mm = m.split('\n')
		else:
			mm = [ m ]
		
		for ml in mm:
			
			mp = ml.strip().split(':',1)
			if len( mp ) >= 2 and mp[0].upper() == mp[0]:
				c = mp[0]
			
			ml = ml.replace( c + ':', '' ).strip()
			c  = c.strip()
			
			logs.append( { 'revision': r, 'category': c, 'message': ml, 'date': d, 'datetime': dt, 'author': a, 'paths': p } )
	
	return logs
def create_svg_for_event(sender, instance, **kwargs):
    if (not instance.svg):
        factory = qrcode.image.svg.SvgPathImage
        qr_file = ContentFile(b'',
                              name='svg_for_event_id_' + str(instance.id) +
                              '.svg')
        qrcode.make(instance.barcode, image_factory=factory).save(qr_file)
        instance.svg = qr_file
        instance.save()
        file_path = 'media/' + str(instance.svg)
        doc = minidom.parse(file_path)
        for path in doc.getElementsByTagName('path'):
            event_svg_d_path = path.getAttribute('d')

        file_path = 'media/' + str(instance.image_state)
        with open(file_path) as f:
            json_data = json.load(f)
        json_data['canvas']['objects'][1]['path'] = event_svg_d_path
        json_values = simplejson.dumps(json_data)
        instance.image_state.save(
            'state_for_event_id_' + str(instance.id) + '.json',
            ContentFile(json_values))
Beispiel #8
0
 def getModifiedFiles(self):
     files = []
     for path in self._getPaths():
         if path.getAttribute("action") == "M":
             files.append(path.firstChild.nodeValue)
     return files
Beispiel #9
0
from line_work import Point
from os import path
from xml.dom import minidom
from bezier_2_circles import bezier_2_circles

# Get project base location
_basepath = path.dirname(__file__)
_filepath = path.abspath(path.join(_basepath,'homer-simpson.svg'))

# Convert SVG file to a series of path strings
doc = minidom.parse(_filepath)
path_strings = [path.getAttribute('d') for path
                in doc.getElementsByTagName('path')]
doc.unlink()

# Create SCALE_FACTOR to determine the scaling of the overall GCODE output
SCALE_FACTOR = 0.2

# Create 4 Points
p1 = Point(0,0)
p2 = Point(0,0)
p3 = Point(0,0)
p4 = Point(0,0)

# Establish a Start Point for Each Curve Section
start_point = Point(0,0)
start_point_flag = 0

print "G0 F4000"
# Iterate through the path strings
for element in path_strings:
Beispiel #10
0
def work():
    
    left = '0'
    right = '0'
    tarpath = r"E:\Workspace\Mobilephone_DDT\trunk\Client\Develop\Resource_release"
    
    publicpath = r"E:\Workspace\Mobilephone_DDT\trunk\Client\Develop\Resource_Android"
    
    opts, args = getopt.getopt(sys.argv[1:], "r:l:i:")
    for op, value in opts:
        if op == "-l":
            left = value
        elif op == "-r":
            right = value
        elif op == "-i":
            tarpath = value
    
    
    os.system("svn update %s" % (tarpath))
    
    
    if left == '0':
        with open(os.path.join(publicpath, "Revision")) as tempFile:
            left = tempFile.readline().strip()
        if left == '0':
            return
        
    if right == '0':
        right = getCurRevision(tarpath)
        if right == '0': 
            return
    
    tmpfilename = os.path.join(projectdir, "svndifftemp.xml")
    if os.path.exists(tmpfilename):
        os.remove(tmpfilename)
    
    
    
    cmd = "svn diff --summarize --xml -r%s:%s %s >> %s" % (left, right, tarpath, tmpfilename)
    print cmd
    
    os.system(cmd)
    
    if os.path.exists(tmpfilename):
        dom = xml.dom.minidom.parse(tmpfilename)
        root = dom.documentElement
        paths = root.getElementsByTagName('path')
        
        changeList = []
        deleteList = {}
        
        for path in paths:
            kind = path.getAttribute("kind")
            if kind == "file":
                item = path.getAttribute("item")
                path = path.firstChild.data
                if item == "modified":
                    changeList.append(path)
                elif item == "added":
                    changeList.append(path)
                elif item == "deleted":
                    deleteList[path] = True
               
        filterExt = [".lua", ".map", ".png", "jpg", ".json", ".xml", ".txt", ".atlas"]
        filterFile = [r"LuaScript\MEGameStartup.lua", r"MEFramework\init.lua", r"MEFramework\Main.lua", "config1"]
        for path in changeList:
            if deleteList.get(path):
                del deleteList[path]
            relpath = os.path.relpath(path, tarpath)
            isNeedCopy = False
            for ext in filterExt:
                if relpath.find(ext) != -1:
                    isNeedCopy = True
                    break
            for ext in filterFile:
                if relpath.find(ext) != -1:
                    isNeedCopy = False
                    break
            if not isNeedCopy:
                continue
            # if relpath.startswith("res"):
            print 'copy file:', os.path.join(publicpath, relpath)
            pathdir = os.path.dirname(os.path.join(publicpath, relpath))
            if not os.path.isdir(pathdir):
                os.makedirs(pathdir) 
            shutil.copy(path, os.path.join(publicpath, relpath))
            sys.stdout.flush() 
        
        for key in deleteList.keys(): 
            relpath = os.path.relpath(key, tarpath) 
            if relpath.startswith(""):
                if os.path.exists(os.path.join(publicpath, relpath)):
                    print 'del file:', os.path.join(publicpath, relpath)
                    os.remove(os.path.join(publicpath, relpath))
                    sys.stdout.flush() 

    
    if os.path.exists(tmpfilename):
        os.remove(tmpfilename)
        
    with open(os.path.join(publicpath, "Revision"), "wb+") as tempFile:
        tempFile.write(str(right))
    pass
	def __init__(self, _svgFile):

		self.rects = []
		self.circles = []
		self.chains = []

		svg = xml.dom.minidom.parse(_svgFile)
		print("svg: "+_svgFile)
		layers = svg.getElementsByTagName("g")
		for layer in layers:
			name = layer.getAttribute("inkscape:label")
			print("name: "+name)

			if ("Box2D" in name):
				rects = layer.getElementsByTagName("rect")
				for rect in rects:
					obj = Rect()
					obj.x = int(float(rect.getAttribute("x")))
					obj.y = int(float(rect.getAttribute("y")))
					obj.w = int(float(rect.getAttribute("width")))
					obj.h = int(float(rect.getAttribute("height")))

					transform = rect.getAttribute("transform")
					if ("matrix" in transform):
						print transform
						# fancy regex from the internets, grabs numbers in any format from strings
						trans = re.findall(r"[+-]? *(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?", transform)
						if (float(trans[0]) == float(trans[3]) and float(trans[1]) == -float(trans[2])):
							# seems like a pure rotational transformation
							obj.r = -math.degrees(math.acos(float(trans[0])))

							print obj.r
					self.rects.append(obj)

				paths = layer.getElementsByTagName("path")
				for path in paths:
					if path.getAttribute("sodipodi:type") == "arc":
						# if it's an arc let's hope it's a circle
						d = path.getAttribute("d")
						if ("m" in d):
							print d
							# fancy regex from the internets, grabs numbers in any format from strings
							values = re.findall(r"[+-]? *(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?", d)

						t = path.getAttribute("transform")
						if ("translate" in t):
							print t
							# fancy regex from the internets, grabs numbers in any format from strings
							trans = re.findall(r"[+-]? *(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?", t)

						c = Circle()
						c.x = float(values[0]) + float(trans[0]) - float(values[2])
						c.y = float(values[1]) + float(trans[1])
						c.r = float(values[2])

						self.circles.append(c)

					else:
						# probably a chain
						d = path.getAttribute("d")
						# if ("m" in d):
						# 	print d
						# 	# fancy regex from the internets, grabs numbers in any format from strings
						# 	points = re.findall(r"[+-]? *(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?", d)

						path = Path(d)
						print path.points
						self.chains.append(path.points)