rem
stringlengths
0
322k
add
stringlengths
0
2.05M
context
stringlengths
8
228k
self.ftp.storbinary("STOR %s" % fname, open(full_fname, "rb"))
remote_fname = "/".join(full_fname.split("/")[1:]) self.ftp.storbinary("STOR %s" % remote_fname, open(full_fname, "rb")) print "Finished uploading"
def write_event(self, name, event, params={}): # Format the event properly chans = event.target() msg = self.format_event(name, event, params) # Quit goes across all channels if not chans or not chans.startswith("#"): chans = self.chans else: chans = [chans] for chan in chans: self.append_log_msg(chan, msg)
print char_count
def test_file_unicode_char(self): ''' A file with one unicode character should have one glyph in the subset font ''' epub_file = os.path.join(self.testfiles_dir, 'test-utf8-char.epub') epub = EpubSubset(epub_file, self.FILENAME) epub.subset()
def test_file_unicode_char_two(self): ''' A file with one unicode character should have one glyph in the subset font ''' epub_file = os.path.join(self.testfiles_dir, 'test-utf8-char-two.epub') epub = EpubSubset(epub_file, self.FILENAME) epub.subset() (root, ext) = os.path.splitext(self.FILENAME) char_count = self._cou...
def test_file_unicode_char(self): ''' A file with one unicode character should have one glyph in the subset font ''' epub_file = os.path.join(self.testfiles_dir, 'test-utf8-char.epub') epub = EpubSubset(epub_file, self.FILENAME) epub.subset()
display_args["interact"] = display_args["interact"] and interact
def __call__(self, what, interact=True, **kwargs):
if not self.forward and len(self.children) == 1: child, x, y, focus, main = self.children[0] cw, ch = child.get_size() if x <= 0 and y <= 0 and cw + x >= self.width and ch + y >= self.height: if isinstance(child, Render): child = child.render_to_texture(alpha) if x != 0 or y != 0 or cw != self.width or ch != self.hei...
if opaque or alpha: if not self.forward and len(self.children) == 1: child, x, y, focus, main = self.children[0] cw, ch = child.get_size() if x <= 0 and y <= 0 and cw + x >= self.width and ch + y >= self.height: if isinstance(child, Render): child = child.render_to_texture(alpha) if x != 0 or y != 0 or cw != self.wi...
def render_to_texture(self, alpha=True): """ Returns a texture constructed from this render. This may return a cached textue, if one has already been rendered.
self.is_opaque()
def render_to_texture(self, alpha=True): """ Returns a texture constructed from this render. This may return a cached textue, if one has already been rendered.
rv.modal = self.screen.modal
rv.modal = self.screen.modal and not self.hiding
def render(self, w, h, st, at):
for i, trans in enumerate(self.transitions):
for trans in self.transitions[:-1]:
def render(self, width, height, st, at):
if i == len(self.transitions) - 1:
else: trans = self.transitions[-1]
def render(self, width, height, st, at):
py_padding = y_padding * pheight / vheight
py_padding = y_padding * pwidth / vwidth
def set_mode(self, virtual_size, physical_size, fullscreen): """ This changes the video mode. It also initializes OpenGL, if it can. It returns True if it was succesful, or False if OpenGL isn't working for some reason. """
if st == 0: self.children = [ ]
def render(self, width, height, st, at):
draw(0, xb, 0, yb) draw(xb, -xb, 0, yb) draw(-xb, 0, 0, yb)
if yb: if xb: draw(0, xb, 0, yb) draw(xb, -xb, 0, yb) if xb: draw(-xb, 0, 0, yb)
def draw(x0, x1, y0, y1):
draw(0, xb, yb, -yb)
if xb: draw(0, xb, yb, -yb)
def draw(x0, x1, y0, y1):
draw(-xb, 0, yb, -yb)
if xb: draw(-xb, 0, yb, -yb)
def draw(x0, x1, y0, y1):
draw(0, xb, -yb, 0) draw(xb, -xb, -yb, 0) draw(-xb, 0, -yb, 0)
if yb: if xb: draw(0, xb, -yb, 0) draw(xb, -xb, -yb, 0) if xb: draw(-xb, 0, -yb, 0)
def draw(x0, x1, y0, y1):
self.laidout_height += height + self.style.line_spacing
self.laidout_height += height + max(self.style.line_spacing, 0)
def layout(self, width, time): """ This lays out the text of this widget. It sets self.laidout, self.laidout_lineheights, self.laidout_width, and self.laidout_height. """
self.event_target = None self.time_offset = 0
def oldnew(w): if w is False: return old_widget if w is True: return new_widget
while True: trans = self.transitions[0] stoff = st - self.time_offset if stoff < trans.delay:
for i, trans in enumerate(self.transitions): if trans.delay > st:
def render(self, width, height, st, at):
if len(self.transitions) == 1: break self.time_offset += trans.delay self.transitions.pop(0) if len(self.transitions) == 1:
st -= trans.delay if i == len(self.transitions) - 1:
def render(self, width, height, st, at):
self.event_target = trans surf = renpy.display.render.render(trans, width, height, stoff, at)
surf = renpy.display.render.render(trans, width, height, st, at)
def render(self, width, height, st, at):
if stoff > 0: renpy.display.render.redraw(self, stoff)
if st < trans.delay: renpy.display.render.redraw(self, trans.delay - st)
def render(self, width, height, st, at):
def __init__(self, name, default_loop, stop_on_mute, tight):
def __init__(self, name, default_loop, stop_on_mute, tight, file_prefix, file_suffix):
def __init__(self, name, default_loop, stop_on_mute, tight):
lfn = topq.filename.lower()
lfn = topq.filename.lower() + self.file_suffix.lower()
def periodic(self): """ This is the periodic call that causes this channel to load new stuff into its queues, if necessary. """
topf = load(topq.filename)
topf = load(self.file_prefix + topq.filename + self.file_suffix)
def periodic(self): """ This is the periodic call that causes this channel to load new stuff into its queues, if necessary. """
def register_channel(name, mixer=None, loop=None, stop_on_mute=True, tight=False):
def register_channel(name, mixer=None, loop=None, stop_on_mute=True, tight=False, file_prefix="", file_suffix=""):
def register_channel(name, mixer=None, loop=None, stop_on_mute=True, tight=False): if not renpy.game.init_phase: raise Exception("Can't register channel outside of init phase.") c = Channel(name, loop, stop_on_mute, tight) c.mixer = mixer all_channels.append(c) channels[name] = c
c = Channel(name, loop, stop_on_mute, tight)
c = Channel(name, loop, stop_on_mute, tight, file_prefix, file_suffix)
def register_channel(name, mixer=None, loop=None, stop_on_mute=True, tight=False): if not renpy.game.init_phase: raise Exception("Can't register channel outside of init phase.") c = Channel(name, loop, stop_on_mute, tight) c.mixer = mixer all_channels.append(c) channels[name] = c
self.modes = [ ]
self.modes = renpy.python.RevertableList([ "start" ])
def after_upgrade(self, version): if version < 1: self.predict_info = PredictInfo() self.scene_lists.image_predict_info = self.predict_info.images
predict_function=None,
def __init__(self, name, function, predict_function=None, modal="False", zorder="0", tag=None): # The name of this screen. if isinstance(name, basestring): name = tuple(name.split())
tag=None):
tag=None, predict_function=None):
def __init__(self, name, function, predict_function=None, modal="False", zorder="0", tag=None): # The name of this screen. if isinstance(name, basestring): name = tuple(name.split())
:args: (name, function, modal="True", zorder="0", tag=None)
:args: (name, function, modal="False", zorder="0", tag=None)
def define_screen(*args, **kwargs): """ :doc: screens :args: (name, function, modal="True", zorder="0", tag=None) Defines a screen with `name`, which should be a string. `function` The function that is called to display the screen. The function is called with the screen scope as keyword arguments. It should ignore ad...
and f.scene_list is not None and layer not in renpy.config.overlay_layers):
and f.scene_list is not None):
def merge_slide(old, new):
if __name__ == "__main__" or android:
def main():
def path_to_renpy_base(): renpy_base = os.path.dirname(sys.argv[0]) renpy_base = os.environ.get('RENPY_BASE', renpy_base) renpy_base = os.path.abspath(renpy_base) return renpy_base
if not hasattr(node, 'lineno'): return self.last_line = max(self.last_line, node.lineno) node.lineno = self.last_line
if hasattr(node, 'lineno'): self.last_line = max(self.last_line, node.lineno) node.lineno = self.last_line
def generic_visit(self, node):
if not sty.cache: continue
def style_name(name): rv = name[0] for i in name[1:]: rv += "[%r]" % i
old_get_surface = pygame.display.get_surface
def update(rects=None): if rects is None: old_update() return
return screen
if old_get_surface(): return screen else: return None
def get_surface(): return screen
for k, v in self.properties: if k not in linear: setattr(trans.state, k, v)
def execute(self, trans, st, state, event):
raise renpy.display.core.IgnoreEvents()
raise renpy.display.core.IgnoreEvent()
def event(self, ev, x, y, st):
insensitive = pick(insensitive, "insensitive", idle)
insensitive = pick(insensitive, "insensitive", ground)
def pick(variable, name, other): if variable: return variable
renpy.display.render.kill_old_screen() renpy.display.focus.take_focuses()
def draw_screen(self, surftree, fullscreen_video): """ Draws the screen. """ if not fullscreen_video:
pwidth = max(1, pwidth) pheight = max(1, pheight)
def set_mode(self, virtual_size, physical_size, fullscreen): """ This changes the video mode. It also initializes OpenGL, if it can. It returns True if it was succesful, or False of OpenGL isn't working for some reason. """
x_padding = vwidth * max(0, physical_ar - virtual_ar) y_padding = vheight * max(0, (1.0 / physical_ar) - (1.0 / virtual_ar))
if physical_ar >= virtual_ar: x_padding = physical_ar * vheight - vwidth y_padding = 0 else: x_padding = 0 y_padding = ( 1.0 / physical_ar ) * vwidth - vheight
def set_mode(self, virtual_size, physical_size, fullscreen): """ This changes the video mode. It also initializes OpenGL, if it can. It returns True if it was succesful, or False of OpenGL isn't working for some reason. """
last_alloc_surface = None def alloc_surface(force): global last_alloc_surface if renpy.display.video.fullscreen and renpy.display.draw.fullscreen_surface: surf = renpy.display.draw.fullscreen_surface else: surf = renpy.display.video.surface if (surf is not last_alloc_surface) or force: last_alloc_surface = surf pss...
def rollback(): """ On rollback, we want to stop all the channels with non-empty sounds. """ for c in all_channels: if not c.loop: c.fadeout(0)
rv.depends_on(self)
def subsurface(self, rect, focus=False): """ Returns a subsurface of this render. If `focus` is true, then the focuses are copied from this render to the child. """
shutil.copy("c:/Python26/msvcr90.dll", "msvcr90.dll")
shutil.copy("c:/Python26/msvcr90.dll", "dist/msvcr90.dll")
def main(): sys.argv[1:] = [ 'py2exe', '--bundle', '2', '-a', '--dll-excludes', 'w9xpopen.exe', ] # sys.argv[1:] = [ 'py2exe', '-a', '--dll-excludes', 'w9xpopen.exe', ] setup(name="Ren'Py", windows=[ dict(script="renpy.py", dest_base="renpy", icon_resources=[ (1, "newicon.ico") ], ), ], console=[ dict(script="renpy....
if self.time:
if not self.time:
def event(self, ev, x, y, st):
try: renpy.python.py_eval(expr) except: report( "Could not evaluate '%s', in %s.", expr, where) if additional: add(additional)
try_compile(where, expr) m = re.match(r'\s*([a-zA-Z_]\w*)', expr) if not m: return if hasattr(renpy.store, m.group(1)): return if m.group(1) in __builtins__: return report( "Could not evaluate '%s', in %s.", expr, where) if additional: add(additional)
def try_eval(where, expr, additional=None): try: renpy.python.py_eval(expr) except: report( "Could not evaluate '%s', in %s.", expr, where) if additional: add(additional)
def try_compile(where, expr):
def try_compile(where, expr, additional=None):
def try_compile(where, expr): try: renpy.python.py_compile_eval_bytecode(expr) except: report("'%s' could not be compiled as a python expression, %s.", expr, where)
def check_label(node): def add_arg(n): if n is None: return if not hasattr(renpy.store, n): setattr(renpy.store, n, None) pi = node.parameters if pi is not None: for i in pi.positional: add_arg(i) add_arg(pi.extrapos) add_arg(pi.extrakw)
def check_style(name, s): if s.indexed: for i in s.indexed: check_style(name + "[%r]" % (name,), s.indexed[i]) for p in s.properties: for k, v in p.iteritems(): kname = name + "." + k # Treat font specially. if k.endswith("font"): check_file(name, v) e = renpy.style.expansions[k] # We only need to check the first...
def humanize(n): s = str(n) rv = [] for i, c in enumerate(reversed(s)): if i and not (i % 3): rv.insert(0, ',') rv.insert(0, c) return ''.join(rv)
def check_styles(): for name, s in renpy.style.style_map.iteritems(): check_style("Style property style." + name, s)
self.layer_at_list[i] = (None, [ ])
def after_setstate(self): for i in renpy.config.layers + renpy.config.top_layers: if i not in self.layers: self.layers[i] = [ ] self.at_list[i] = { }
selected_idle = imagemap.selected_idle selected_hover = imagemap.selected_hover insensitive = imagemap.insensitive
def _hotspot(spot, style='imagemap_button', **properties): if not imagemap_stack: raise Exception("hotspot expects an imagemap to be defined.") imagemap = imagemap_stack[-1] x, y, w, h = spot idle = imagemap.idle hover = imagemap.hover idle = renpy.display.layout.LiveCrop(spot, idle) hover = renpy.display.layout.L...
step_mean = 20
step_mean = 200
def render(self, screen): pygame.draw.circle(screen, self.color, map(int, self.position), int(self.radius), 0) pygame.draw.circle(screen, (0,0,0), map(int, self.position), int(self.radius), 2) #this draws a direction vector for a unit dirvector = map(int, (self.position.x + math.cos(self.angle)*self.radius, self.posit...
GLOBALNODES = 300
GLOBALNODES = 100
def think(self, dt, view, debugsurface): pass
def init(self, view): """Builds the static obstacle map, global roadmap"""
def globaltree(self, view):
def init(self, view): """Builds the static obstacle map, global roadmap""" #RRT from goal nodes = [self.Node(self.goal, None, None)] for i in xrange(self.GLOBALNODES): newpos = Vec2d(random.randrange(640), random.randrange(480)) #TODO: remove hardcoded world size besttime = None bestnode = None for tonode in nodes: top...
for i in xrange(self.GLOBALNODES):
while len(nodes) < self.GLOBALNODES:
def init(self, view): """Builds the static obstacle map, global roadmap""" #RRT from goal nodes = [self.Node(self.goal, None, None)] for i in xrange(self.GLOBALNODES): newpos = Vec2d(random.randrange(640), random.randrange(480)) #TODO: remove hardcoded world size besttime = None bestnode = None for tonode in nodes: top...
diff = topos - newpos
diff = newpos - topos
def init(self, view): """Builds the static obstacle map, global roadmap""" #RRT from goal nodes = [self.Node(self.goal, None, None)] for i in xrange(self.GLOBALNODES): newpos = Vec2d(random.randrange(640), random.randrange(480)) #TODO: remove hardcoded world size besttime = None bestnode = None for tonode in nodes: top...
div = 1 while difflen/div > self.GLOBALMINEDGE: div += 1
div = int(math.ceil(difflen/self.GLOBALMINEDGE)) prev = bestnode
def init(self, view): """Builds the static obstacle map, global roadmap""" #RRT from goal nodes = [self.Node(self.goal, None, None)] for i in xrange(self.GLOBALNODES): newpos = Vec2d(random.randrange(640), random.randrange(480)) #TODO: remove hardcoded world size besttime = None bestnode = None for tonode in nodes: top...
for d in xrange(div): nodes.append(self.Node(newpos + vdir*d*difflen/div, angle, bestnode))
for d in xrange(1, div+1): newnode = self.Node(topos + diff*d/div, angle, prev) nodes.append(newnode) prev = newnode poss = [] for n in nodes: poss.append((n.position[0], n.position[1])) poss.sort() for p in poss: print p
def init(self, view): """Builds the static obstacle map, global roadmap""" #RRT from goal nodes = [self.Node(self.goal, None, None)] for i in xrange(self.GLOBALNODES): newpos = Vec2d(random.randrange(640), random.randrange(480)) #TODO: remove hardcoded world size besttime = None bestnode = None for tonode in nodes: top...
print "Done building global RRT"
print "Done building global RRT", len(self.globalnodes) def init(self, view): """Builds the static obstacle map, global roadmap""" self.globaltree(view)
def init(self, view): """Builds the static obstacle map, global roadmap""" #RRT from goal nodes = [self.Node(self.goal, None, None)] for i in xrange(self.GLOBALNODES): newpos = Vec2d(random.randrange(640), random.randrange(480)) #TODO: remove hardcoded world size besttime = None bestnode = None for tonode in nodes: top...
def freeprob_path(self, path, view, startangle = None): raise NotImplementedError
def freeprob_path(self, path, view, startangle = None): raise NotImplementedError
if not (path[0] == self.position and path[-1] == self.goal): return None
def path_valid(self, path, view): """Returns if a path is safe still valid (i.e. deemed collision free)""" if not (path[0] == self.position and path[-1] == self.goal): return None #must go between current position and goal ctime = 0 freeprob = 1.0 a1 = self.angle p1 = self.position
return None return ctime
return False return True
def path_valid(self, path, view): """Returns if a path is safe still valid (i.e. deemed collision free)""" if not (path[0] == self.position and path[-1] == self.goal): return None #must go between current position and goal ctime = 0 freeprob = 1.0 a1 = self.angle p1 = self.position
best = None
bestparent = None
def getpath(self, view, max_size): start = Arty.Node(self.position, self.angle, parent = None, time = 0, freeprob = 1) if self.freeprob_linesegment(self.position, self.angle, self.goal, view, 0) >= self.SAFETY_THRESHOLD: return [self.position, self.goal] #direct path
if best is None or best[1] > endtime: best = (newprob, endtime, n) if best is not None: newprob, new_time, parent = best[0], best[1], best[2]
def getpath(self, view, max_size): start = Arty.Node(self.position, self.angle, parent = None, time = 0, freeprob = 1) if self.freeprob_linesegment(self.position, self.angle, self.goal, view, 0) >= self.SAFETY_THRESHOLD: return [self.position, self.goal] #direct path
newnode = Arty.Node(nextpos, (nextpos - n.position).angle(), parent = parent, time = new_time, freeprob = newprob) nodes.append(newnode) freeprob = self.freeprob_linesegment(newnode.position, newnode.angle, self.goal, view, new_time) target_prob = freeprob*newprob
diff = nextpos - parent.position angle = diff.angle() difflen = diff.length() vdir = diff/difflen div = int(math.ceil(difflen/self.LOCALMINEDGE)) for d in xrange(1, div+1): newnode = self.Node(parent.position + diff*d/div, angle, parent = parent, time = newtime, freeprob = newprob) nodes.append(newnode) freeprob = s...
def getpath(self, view, max_size): start = Arty.Node(self.position, self.angle, parent = None, time = 0, freeprob = 1) if self.freeprob_linesegment(self.position, self.angle, self.goal, view, 0) >= self.SAFETY_THRESHOLD: return [self.position, self.goal] #direct path
for n in self.globalnodes: if n.parent: pygame.draw.line(debugsurface, pygame.Color("black"), n.position, n.parent.position) pygame.draw.circle(debugsurface, pygame.Color("red"), n.position, 2, 0)
def think(self, dt, view, debugsurface): if not self.goal: return self.view = view self.debugsurface = debugsurface #for n in self.globalnodes: # if n.parent: # pygame.draw.line(debugsurface, pygame.Color("black"), n.position, n.parent.position) # pygame.draw.circle(debugsurface, pygame.Color("red"), n.position, 2, 0...
def getpath(self, view, max_size): testpath = self.find_globaltree(self.position, self.angle, view, 0, 1)
def getpath(self, view): """Use the Art algorithm to get a path to the goal""" testpath, testtime = self.find_globaltree(self.position, self.angle, view, 0, 1)
def getpath(self, view, max_size): testpath = self.find_globaltree(self.position, self.angle, view, 0, 1) if testpath: return testpath print "Cannot find global path from current, extending search tree" start = Arty.Node(self.position, self.angle, parent = None, time = 0, freeprob = 1) nodes = [start]
trypos = []
states = PrependedGenerator(self.position.x - self.view_range, self.position.x + self.view_range, self.position.y - self.view_range, self.position.y + self.view_range)
def getpath(self, view, max_size): testpath = self.find_globaltree(self.position, self.angle, view, 0, 1) if testpath: return testpath print "Cannot find global path from current, extending search tree" start = Arty.Node(self.position, self.angle, parent = None, time = 0, freeprob = 1) nodes = [start]
if pos.length() <= self.radius: trypos.append(pos) while len(trypos) < max_size: pos = Vec2d(random.random()*self.view_range, random.random()*self.view_range) if pos.length() <= self.radius: trypos.append(pos) for nextpos in trypos:
if pos.distance_to(self.position) <= self.radius: states.prepend(pos) for nextpos in states.generate_n(self.LOCALMAXSIZE):
def getpath(self, view, max_size): testpath = self.find_globaltree(self.position, self.angle, view, 0, 1) if testpath: return testpath print "Cannot find global path from current, extending search tree" start = Arty.Node(self.position, self.angle, parent = None, time = 0, freeprob = 1) nodes = [start]
if bestparent is None or bestparent[1] > endtime: bestparent = (newprob, endtime, n)
if bestparent is None or besttime > endtime: bestparent = n besttime = endtime
def getpath(self, view, max_size): testpath = self.find_globaltree(self.position, self.angle, view, 0, 1) if testpath: return testpath print "Cannot find global path from current, extending search tree" start = Arty.Node(self.position, self.angle, parent = None, time = 0, freeprob = 1) nodes = [start]
newprob, newtime, parent = bestparent[0], bestparent[1], bestparent[2] pygame.draw.line(self.debugsurface, (0,255,0), parent.position, nextpos) diff = nextpos - parent.position
pygame.draw.line(self.debugsurface, (0,255,0), bestparent.position, nextpos) diff = nextpos - bestparent.position
def getpath(self, view, max_size): testpath = self.find_globaltree(self.position, self.angle, view, 0, 1) if testpath: return testpath print "Cannot find global path from current, extending search tree" start = Arty.Node(self.position, self.angle, parent = None, time = 0, freeprob = 1) nodes = [start]
lastnode = bestparent
def getpath(self, view, max_size): testpath = self.find_globaltree(self.position, self.angle, view, 0, 1) if testpath: return testpath print "Cannot find global path from current, extending search tree" start = Arty.Node(self.position, self.angle, parent = None, time = 0, freeprob = 1) nodes = [start]
newnode = self.Node(parent.position + diff*d/div, angle, parent = parent, time = newtime, freeprob = newprob)
subpos = bestparent.position + diff*d/div freeprob = self.freeprob_turn_line(lastnode.position, lastnode.angle, subpos, view, lastnode.time) dt = self.segment_time(lastnode.angle, lastnode.position, subpos) newnode = self.Node(subpos, angle, parent = lastnode, time = lastnode.time + dt, freeprob = lastnode.freeprob * f...
def getpath(self, view, max_size): testpath = self.find_globaltree(self.position, self.angle, view, 0, 1) if testpath: return testpath print "Cannot find global path from current, extending search tree" start = Arty.Node(self.position, self.angle, parent = None, time = 0, freeprob = 1) nodes = [start]
freeprob = self.freeprob_turn_line(newnode.position, newnode.angle, self.goal, view, newtime) target_prob = freeprob*newprob if target_prob >= self.SAFETY_THRESHOLD: path = [self.goal]
gpath, gtime = self.find_globaltree(newnode.position, newnode.angle, view, newnode.time, newnode.freeprob) if gpath is not None: path = []
def getpath(self, view, max_size): testpath = self.find_globaltree(self.position, self.angle, view, 0, 1) if testpath: return testpath print "Cannot find global path from current, extending search tree" start = Arty.Node(self.position, self.angle, parent = None, time = 0, freeprob = 1) nodes = [start]
besttime = None
def find_globaltree(self, p1, a1, view, time, startprob): """Tries to reach global tree from position/angle Returns (path, time) to get to goal""" bestpath = None for n in self.globalnodes: a2 = (n.position - p1).angle() free = startprob * self.freeprob_turn(p1, a1, a2, view, time) time += abs(angle_diff(a1, a2))/se...
return bestpath
return (bestpath, besttime)
def find_globaltree(self, p1, a1, view, time, startprob): """Tries to reach global tree from position/angle Returns (path, time) to get to goal""" bestpath = None for n in self.globalnodes: a2 = (n.position - p1).angle() free = startprob * self.freeprob_turn(p1, a1, a2, view, time) time += abs(angle_diff(a1, a2))/se...
path = self.getpath(view, 50)
path = self.getpath(view)
def think(self, dt, view, debugsurface): if not self.goal: return self.view = view self.debugsurface = debugsurface for n in self.globalnodes: if n.parent: pygame.draw.line(debugsurface, pygame.Color("black"), n.position, n.parent.position) pygame.draw.circle(debugsurface, pygame.Color("red"), n.position, 2, 0)
poss = [] for n in nodes: poss.append((n.position[0], n.position[1])) poss.sort() for p in poss: print p
def globaltree(self, view): #RRT from goal nodes = [self.Node(self.goal, None, None)] while len(nodes) < self.GLOBALNODES: newpos = Vec2d(random.randrange(640), random.randrange(480)) #TODO: remove hardcoded world size besttime = None bestnode = None for tonode in nodes: topos = tonode.position connectable = True for o...
timeresolution = self.radius/self.speed
def freeprob_turn(self, position, a1, a2, view, starttime): dur = angle_diff(a1, a2)/self.turningspeed timeresolution = self.radius/self.speed for p in view.pedestrians: p1 = p.position p2 = p1 + dur*p1.velocity #extrapolate if linesegdist2(p1, p2, position) < (self.radius + p.radius)**2: return 0 return 1
p2 = p1 + dur*p1.velocity
p2 = p1 + p.velocity*dur
def freeprob_turn(self, position, a1, a2, view, starttime): dur = angle_diff(a1, a2)/self.turningspeed timeresolution = self.radius/self.speed for p in view.pedestrians: p1 = p.position p2 = p1 + dur*p1.velocity #extrapolate if linesegdist2(p1, p2, position) < (self.radius + p.radius)**2: return 0 return 1
def freeprob_linesegment(self, p1, a1, p2, view, starttime):
def freeprob_line(self, p1, p2, view, starttime):
def freeprob_linesegment(self, p1, a1, p2, view, starttime): if p1 == p2: return self.freeprob(p1, view, starttime) diff = p2 - p1 length = diff.length() v = diff/length resolution = self.radius numsegments = int(math.ceil(length/resolution)) segmentlen = length/numsegments timediff = segmentlen/self.speed freeprob =...
freeprob *= self.freeprob_linesegment(p1, p2, view, ctime)
freeprob *= self.freeprob_turn_line(p1, a1, p2, view, ctime)
def path_valid(self, path, view): """Returns if a path is safe (i.e. deemed collision free)""" ctime = 0 freeprob = 1.0 a1 = self.angle p1 = self.position
if self.freeprob_linesegment(self.position, self.angle, self.goal, view, 0) >= self.SAFETY_THRESHOLD:
if self.freeprob_turn_line(self.position, self.angle, self.goal, view, 0) >= self.SAFETY_THRESHOLD:
def getpath(self, view, max_size): start = Arty.Node(self.position, self.angle, parent = None, time = 0, freeprob = 1) if self.freeprob_linesegment(self.position, self.angle, self.goal, view, 0) >= self.SAFETY_THRESHOLD: return [self.position, self.goal] #direct path
freeprob = self.freeprob_linesegment(n.position, n.angle, nextpos, view, n.time)
freeprob = self.freeprob_turn_line(n.position, n.angle, nextpos, view, n.time)
def getpath(self, view, max_size): start = Arty.Node(self.position, self.angle, parent = None, time = 0, freeprob = 1) if self.freeprob_linesegment(self.position, self.angle, self.goal, view, 0) >= self.SAFETY_THRESHOLD: return [self.position, self.goal] #direct path
if newprob < self.SAFETY_THRESHOLD: assert(False) pygame.draw.line(self.debugsurface, (255,0,0), parent.position, nextpos) continue else: pygame.draw.line(self.debugsurface, (0,255,0), parent.position, nextpos)
pygame.draw.line(self.debugsurface, (0,255,0), parent.position, nextpos)
def getpath(self, view, max_size): start = Arty.Node(self.position, self.angle, parent = None, time = 0, freeprob = 1) if self.freeprob_linesegment(self.position, self.angle, self.goal, view, 0) >= self.SAFETY_THRESHOLD: return [self.position, self.goal] #direct path
freeprob = self.freeprob_linesegment(newnode.position, newnode.angle, self.goal, view, newtime)
freeprob = self.freeprob_turn_line(newnode.position, newnode.angle, self.goal, view, newtime)
def getpath(self, view, max_size): start = Arty.Node(self.position, self.angle, parent = None, time = 0, freeprob = 1) if self.freeprob_linesegment(self.position, self.angle, self.goal, view, 0) >= self.SAFETY_THRESHOLD: return [self.position, self.goal] #direct path
if target_prob > self.SAFETY_THRESHOLD:
if target_prob >= self.SAFETY_THRESHOLD:
def getpath(self, view, max_size): start = Arty.Node(self.position, self.angle, parent = None, time = 0, freeprob = 1) if self.freeprob_linesegment(self.position, self.angle, self.goal, view, 0) >= self.SAFETY_THRESHOLD: return [self.position, self.goal] #direct path
def find_globaltree(self, p1, a1, view, time, startprob): """Tries to reach global tree from position/angle Returns (path, time) to get to goal""" print "Calling globaltree" bestpath = None for n in self.globalnodes: a2 = (n.position - p1).angle() free = startprob * self.freeprob_turn(p1, a1, a2, view, time) time +...
def getpath(self, view, max_size): start = Arty.Node(self.position, self.angle, parent = None, time = 0, freeprob = 1) if self.freeprob_linesegment(self.position, self.angle, self.goal, view, 0) >= self.SAFETY_THRESHOLD: return [self.position, self.goal] #direct path
print "Agent Ground Speed:", self.agent.travel_length/agent_out_time print "Agent Collisions:", self.agent.collisions
print "Agent Collisions:", self.agent.collisions
def run(self): overtime = -1 agent_out_time = 0 while 1: if self.agent.position.distance_to(self.agent.goal) <= self.agent.radius: ## for Crossing scenario only if (agent_out_time == 0): self.world.remove_unit(self.agent) agent_out_time = self.world._time overtime = overtime + 1 if overtime == 0: if(len(self.world.avg_...
kwargs['args'] = args return BaseTemplateFile.__call__(self, self, **kwargs)
bound = self.bind(self) return bound(*args, **kwargs)
def __call__(self, *args, **kwargs): kwargs['args'] = args return BaseTemplateFile.__call__(self, self, **kwargs)
func = wraps(func)(wrapper)
wrapper = wraps(func)(wrapper)
def wrapper(self, request, *args, **kwargs): try: response = { "success": True, "data": func(self, request, *args, **kwargs) } except GargoyleException, exc: response = { "success": False, "data": exc.message } except Switch.DoesNotExist: response = { "success": False, "data": "Switch cannot be found" } except Validati...
conditions = self.get(key)
try: conditions = self[key] except KeyError: return False
def is_active(self, key, *instances): """ ``gargoyle.is_active('my_feature', request)`` """ conditions = self.get(key) if not conditions: # XXX: option to have default return value? return True
for field in switch.fields: for value in self.value[ns].get(field.name, []):
for name, field in switch.fields.iteritems(): for value in self.value[ns].get(name, []):
def get_active_conditions(self): "Returns groups of lists of active conditions" for switch in sorted(gargoyle._registry, key=lambda x: x.get_group_label()): ns = switch.get_namespace() if ns in self.value: group = switch.get_group_label() for field in switch.fields: for value in self.value[ns].get(field.name, []): yiel...
"User", field.label, field.render(value)
def get_active_conditions(self): "Returns groups of lists of active conditions" for switch in sorted(gargoyle._registry, key=lambda x: x.get_group_label()): ns = switch.get_namespace() if ns in self.value: group = switch.get_group_label() for field in switch.fields: for value in self.value[ns].get(field.name, []): yiel...
else: return GLOBAL
def get_status(self): if self.value.get('global') is False: return DISABLED elif self.value.get('global'): return SELECTIVE else: return GLOBAL
shutil.copy(control, os.path.join(taskdir, path)
shutil.copy(control, os.path.join(taskdir, path))
def upload_control_file(self, task_id, taskdir, source_dir): dirname = find_changelog(source_dir) if dirname is None: raise ValueError('Unable to find debian/control')
packages=['irgsh_node'],
packages=packages,
def get_version(): import irgsh_node return irgsh_node.__version__
def upload(self, task_id, path, content_type, **extra):
def upload(self, task_id, path, content_type, extra={}):
def upload(self, task_id, path, content_type, **extra): data = {} data.update(extra) data.update({'task_id': task_id, 'path': path, 'content_type': content_type})
Timer(1, self.upload())
Timer(1, self.upload)
def start(self): self.load_config() self.connect()