Skip to content

Commit e7c9499

Browse files
committed
Now command file can contain quoted strings and comments
1 parent c335ddc commit e7c9499

2 files changed

Lines changed: 8 additions & 5 deletions

File tree

examples/simple.txt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
ae 1 2
2-
ae 1 3
3-
ae 2 "a node"
2+
ae 1 "a \"node\""
3+
ae 2 "a \"node\""
44
ns
55
hn 1
66
ns
77
hn 2
88
ln 2 "foo bar"
99
ns
10-
hn "a node"
10+
hn "a \"node\""
11+
# this is a comment
1112
ae 1 4
1213
ns
1314
un 2

gvanim/animation.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
# You should have received a copy of the GNU General Public License along with
1616
# "GraphvizAnim". If not, see <http://www.gnu.org/licenses/>.
1717

18+
from email.utils import quote
1819
import shlex
1920

2021
import action
@@ -105,6 +106,7 @@ def parse( self, lines ):
105106
}
106107
for line in lines:
107108
parts = shlex.split( line.strip(), True )
109+
if not parts: continue
108110
action, params = parts[ 0 ], parts[ 1: ]
109111
try:
110112
action2method[ action ]( *params )
@@ -129,8 +131,8 @@ def graphs( self ):
129131
graphs = []
130132
for n, s in enumerate( steps ):
131133
graph = [ 'digraph G {' ]
132-
for v in V: graph.append( '{} {};'.format( v, s.node_format( v ) ) )
133-
for e in E: graph.append( '{}->{} {};'.format( e[0], e[1], s.edge_format( e ) ) )
134+
for v in V: graph.append( '"{}" {};'.format( quote( v ), s.node_format( v ) ) )
135+
for e in E: graph.append( '"{}" -> "{}" {};'.format( quote( e[ 0 ] ), quote( e[ 1 ] ), s.edge_format( e ) ) )
134136
graph.append( '}' )
135137
graphs.append( '\n'.join( graph ) )
136138
return graphs

0 commit comments

Comments
 (0)