The unified diff between revisions [6566c817..] and [8f58bb18..] is displayed below. It can also be downloaded as a raw diff.
This diff has been restricted to the following files: 'fritz.py'
#
#
# patch "fritz.py"
# from [28c80476a119ac744f16107031bb10ed60e3e780]
# to [e53a6d5f470a753ab5d51ac45f98c501ff0bfe1c]
#
============================================================
--- fritz.py 28c80476a119ac744f16107031bb10ed60e3e780
+++ fritz.py e53a6d5f470a753ab5d51ac45f98c501ff0bfe1c
@@ -4,16 +4,10 @@ import cPickle
import random
random.seed()
import cPickle
+import getopt
import sys
-
-def debug_fritzable(chain):
- def fritzable(s):
- return len (s.state) > 1
- print chain.states.values()
- fritzable_states = filter (fritzable, chain.states.values())
- print map (lambda s : ''.join (s.state), fritzable_states)
-def fritz(chain, max_bytes):
+def fritz_gen(fd, chain, max_bytes):
def starting_point():
# pick a starting point
total = sum (map (lambda s : s.total, chain.states.values ()))
@@ -38,7 +32,7 @@ def fritz(chain, max_bytes):
to_out = ''.join (state.state)
if out_bytes + len(to_out) >= max_bytes:
to_out = to_out[:max_bytes - out_bytes]
- sys.stdout.write (to_out)
+ fd.write (to_out)
out_bytes += len(to_out)
cycle_count = cycle_counts[id(state)] = cycle_counts.setdefault(id(state), 0) + 1
if cycle_count > 5:
@@ -46,8 +40,45 @@ def fritz(chain, max_bytes):
cycle_count = {}
else:
state = chain.random_next (state)
- sys.stdout.write('\n')
+ fd.write('\n')
+def log(s):
+ print >>sys.stderr, s
+
+def usage():
+ print """\
+Usage: %s [ --output=<file> ... ] [ --fritzfrom=<file> ] model.mk
+ --output specifies a file that should be generated from the model
+ --fritzfrom specifies a file that should be used as a basis for fritzing
+ (output is written to stdout)
+"""
+
+def get_fritzable(chain):
+ def fritzable(s):
+ return len (s.state) > 1
+ log (chain.states.values())
+ fritzable_states = filter (fritzable, chain.states.values())
+ #log ("%s" % repr(map (lambda s : ''.join (s.state), fritzable_states)))
+ return fritzable_states
+
+def fritz_file(fd, chain):
+ find_states = get_fritzable(chain)
+
+
if __name__ == '__main__':
+ try:
+ optlist, args = getopt.getopt (sys.argv[1:], '', ['output=', 'fritzfile='])
+ except getopt.GetoptError:
+ usage()
+ sys.exit(1)
+ if len(args) != 1:
+ usage()
+ sys.exit(2)
+ log("Loading %s" % args[0])
+ chain = cPickle.load (open (args[0], 'rb'))
+ for o, a in optlist:
+ if o == '--output':
+ log ("Writing fritz to %s." % (a))
+ fritz_gen (open (a, 'wb'), chain, 1024)
+ elif o == "--fritzfile":
+ log ("Fritzing %s." % (a))
- chain = cPickle.load (sys.stdin)
- fritz(chain, 1024)