rem stringlengths 0 322k | add stringlengths 0 2.05M | context stringlengths 8 228k |
|---|---|---|
grad, step_coeff = self._step_direction(p) | grad, step_coeff = self._step_direction(p, dostep = True) | def step(self, p): grad, step_coeff = self._step_direction(p) states = p.states for (g, state) in zip(grad,states): state.x += step_coeff * g |
for (g, state) in zip(grad,states): state.x += step_coeff * g | def step(self, p): grad, step_coeff = self._step_direction(p) states = p.states for (g, state) in zip(grad,states): state.x += step_coeff * g | |
self.linesearch_stop_code = None | def __init__(self, feval, max_line_steps=10, quiet=True, **kwargs): ''' Gradient-descent parameter update strategy, performing a line-search to select the step size | |
self.linesearch_stop_code = None | def reset(self): self.linesearch_stop_code = None self.cur_num_steps = -1 super(gd_linesearch_update, self).reset() | |
def _step_direction(self, p): | def _step_direction(self, p, dostep=True): | def _step_direction(self, p): grad, step_coeff = \ super(gd_linesearch_update, self)._step_direction(p) feval = self.feval states = p.states bup = p.backup() stop = self.max_line_steps step = 0 cur_energy = feval() new_energy = np.infty while new_energy > cur_energy and step != stop: for (g, state) in zip(gr... |
super(gd_linesearch_update, self)._step_direction(p) | super(gd_linesearch_update, self)._step_direction(p, False) | def _step_direction(self, p): grad, step_coeff = \ super(gd_linesearch_update, self)._step_direction(p) feval = self.feval states = p.states bup = p.backup() stop = self.max_line_steps step = 0 cur_energy = feval() new_energy = np.infty while new_energy > cur_energy and step != stop: for (g, state) in zip(gr... |
while new_energy > cur_energy and step != stop: for (g, state) in zip(grad,states): state.x += step_coeff * g | while step != stop: step += 1 self._perform_step(p, grad, step_coeff) new_energy = feval() | def _step_direction(self, p): grad, step_coeff = \ super(gd_linesearch_update, self)._step_direction(p) feval = self.feval states = p.states bup = p.backup() stop = self.max_line_steps step = 0 cur_energy = feval() new_energy = np.infty while new_energy > cur_energy and step != stop: for (g, state) in zip(gr... |
new_energy = feval() | if new_energy < cur_energy: break | def _step_direction(self, p): grad, step_coeff = \ super(gd_linesearch_update, self)._step_direction(p) feval = self.feval states = p.states bup = p.backup() stop = self.max_line_steps step = 0 cur_energy = feval() new_energy = np.infty while new_energy > cur_energy and step != stop: for (g, state) in zip(gr... |
step += 1 | def _step_direction(self, p): grad, step_coeff = \ super(gd_linesearch_update, self)._step_direction(p) feval = self.feval states = p.states bup = p.backup() stop = self.max_line_steps step = 0 cur_energy = feval() new_energy = np.infty while new_energy > cur_energy and step != stop: for (g, state) in zip(gr... | |
if step == stop: self.linesearch_stop_code = 'iteration limit reached' else: self.linesearch_stop_code = 'energy decreased' | if new_energy >= cur_energy: self.stop_code = 'line search failed' | def _step_direction(self, p): grad, step_coeff = \ super(gd_linesearch_update, self)._step_direction(p) feval = self.feval states = p.states bup = p.backup() stop = self.max_line_steps step = 0 cur_energy = feval() new_energy = np.infty while new_energy > cur_energy and step != stop: for (g, state) in zip(gr... |
(step, self.linesearch_stop_code) | (step, ('energy decreased' if new_energy < cur_energy else 'iteration limit reached')) if not dostep: p.restore(bup) | def _step_direction(self, p): grad, step_coeff = \ super(gd_linesearch_update, self)._step_direction(p) feval = self.feval states = p.states bup = p.backup() stop = self.max_line_steps step = 0 cur_energy = feval() new_energy = np.infty while new_energy > cur_energy and step != stop: for (g, state) in zip(gr... |
def __new__(cls, shape, dtype=rtype): shape = ensure_tuple(shape) | def __new__(cls, *args): if len(args) == 0: return object.__new__(cls) shape = ensure_tuple(args[0]) dtype = rtype if len(args) < 2 else args[1] | def __new__(cls, shape, dtype=rtype): shape = ensure_tuple(shape) if shape[0] == 1: return degen_rolling_average(shape, dtype) return object.__new__(cls) |
def __new__(cls, shape, dtype=rtype): | def __new__(cls, *args): | def __new__(cls, shape, dtype=rtype): return object.__new__(cls) |
base_super = super | _base_super = super | def make_wrapper(inner_name, around_fn): return lambda self, *args, **kwargs: \ around_fn(self, getattr(self, inner_name), *args, **kwargs) |
return base_super(cls, *args) | return _base_super(cls, *args) | def __new__(self, cls, *args): if not hasattr(cls, '__renames__') or not args: return base_super(cls, *args) return object.__new__(self) |
self.__sup = base_super(cls, obj) | self.__sup = _base_super(cls, obj) | def __init__(self, cls, obj): self.__sup = base_super(cls, obj) self.__renames = cls.__renames__ |
__builtins__.super = around_super | __builtins__.super = around_super __builtins__._base_super = _base_super | def __getattribute__(self, name): if name.startswith('_around_super__'): return object.__getattribute__(self, name) sup = self.__sup renames = self.__renames if name in renames: name = renames[name] return getattr(sup, name) |
__builtins__['super'] = around_super | __builtins__['super'] = around_super __builtins__['_base_super'] = _base_super | def __getattribute__(self, name): if name.startswith('_around_super__'): return object.__getattribute__(self, name) sup = self.__sup renames = self.__renames if name in renames: name = renames[name] return getattr(sup, name) |
param.updater = gd_update( eta = 0.02, max_iters = 100 ) | param.updater = gd_update( eta = 0.02 ) | def plot(ds, machine): shape_in, shape_out = ds.shape() assert (shape_in == shape_out == (1,)) inp = state((1,)); out = state((1,)); des = state((1,)) ds.seek(0) size = ds.size() coords = empty(size); outputs = empty(size); targets = empty(size) for i in xrange(size): ds.fprop(inp, des) machine.fprop(inp, out) coords[... |
trainer.train(50000) | trainer.train(10000) | def plot(ds, machine): shape_in, shape_out = ds.shape() assert (shape_in == shape_out == (1,)) inp = state((1,)); out = state((1,)); des = state((1,)) ds.seek(0) size = ds.size() coords = empty(size); outputs = empty(size); targets = empty(size) for i in xrange(size): ds.fprop(inp, des) machine.fprop(inp, out) coords[... |
_base_super = super | def make_wrapper(inner_name, around_fn): return lambda self, *args, **kwargs: \ around_fn(self, getattr(self, inner_name), *args, **kwargs) | |
__builtins__._base_super = _base_super | def __getattribute__(self, name): if name.startswith('_around_super__'): return object.__getattribute__(self, name) sup = self.__sup renames = self.__renames if name in renames: name = renames[name] return getattr(sup, name) | |
__builtins__['_base_super'] = _base_super | def __getattribute__(self, name): if name.startswith('_around_super__'): return object.__getattribute__(self, name) sup = self.__sup renames = self.__renames if name in renames: name = renames[name] return getattr(sup, name) | |
min_finished = self.ds_train.size() - self.ds.tell() | min_finished = self.ds_train.size() - self.ds_train.tell() | def train_online(self, niters = -1): if not self.quiet: print 'Starting training on %s%s' % \ (time.asctime(), ' (max %d iterations)' % (niters,) if niters >= 0 else '') parameter = self.parameter age = self.age msg = self.msg hess_interval = self.hess_interval report_interval = self.r... |
eta = 2.0, | eta = 1.0, | def plot_reconstructions(ds, machine, n = 1000, orig_x=5, orig_y=5, max_x=795, scale = 1.0): shape_in, shape_out = ds.shape() assert (len(shape_in) == len(shape_out) == 2) ensure_window(title = 'PSD Reconstructions') spacing, padding = 2, 5 pic = empty((max(shape_in[0], shape_out[0]), shape_in[1] + spacing + shape_out[... |
hess_interval = 0, report_interval = 1, | hess_interval = 10000, report_interval = 50, | def plot_reconstructions(ds, machine, n = 1000, orig_x=5, orig_y=5, max_x=795, scale = 1.0): shape_in, shape_out = ds.shape() assert (len(shape_in) == len(shape_out) == 2) ensure_window(title = 'PSD Reconstructions') spacing, padding = 2, 5 pic = empty((max(shape_in[0], shape_out[0]), shape_in[1] + spacing + shape_out[... |
trainer.train(20) | trainer.train(2000) | def plot_reconstructions(ds, machine, n = 1000, orig_x=5, orig_y=5, max_x=795, scale = 1.0): shape_in, shape_out = ds.shape() assert (len(shape_in) == len(shape_out) == 2) ensure_window(title = 'PSD Reconstructions') spacing, padding = 2, 5 pic = empty((max(shape_in[0], shape_out[0]), shape_in[1] + spacing + shape_out[... |
run_shell ('mono --debug solitary/Solitary.exe ' | run_shell ('mono --debug ../../solitary/Solitary.exe ' | def make_app_bundle (self): plist_path = os.path.join (self.bundle_skeleton_dir, 'Contents', 'Info.plist') app_name = 'Unknown.app' plist = None if os.path.exists (plist_path): plist = Plist.fromFile (plist_path) app_name = plist['CFBundleExecutable'] else: print 'Warning: no Contents/Info.plist in .app skeleton' |
Package.__init__ (self, 'banshee-1', '1.7.3') | Package.__init__ (self, 'banshee-1', '1.7.4') | def __init__ (self): Package.__init__ (self, 'banshee-1', '1.7.3') |
'http://download.banshee.fm/banshee/unstable/%{version}/%{name}-%{version}.tar.bz2' | 'http://download.banshee.fm/banshee/unstable/%{version}/%{name}-%{version}.tar.bz2', 'patches/banshee-gnome-doc-utils-fix.patch' | def __init__ (self): Package.__init__ (self, 'banshee-1', '1.7.3') |
'--disable-webkit', '--disable-youtube' | '--disable-boo', '--disable-youtube', '--disable-gnome' | def __init__ (self): Package.__init__ (self, 'banshee-1', '1.7.3') |
'--disable-boo', '--disable-gnome', | def __init__ (self): Package.__init__ (self, 'banshee-1', '1.7.3') | |
product = party_obj.browse(cursor, user, product, context=context) | product = product_obj.browse(cursor, user, product, context=context) | def compute(self, cursor, user, price_list, party, product, unit_price, quantity, uom, pattern=None, context=None): ''' Compute price based on price list of party |
product = party_obj.browse(product) | product = product_obj.browse(product) | def compute(self, price_list, party, product, unit_price, quantity, uom, pattern=None): ''' Compute price based on price list of party |
probe.log("MAPPING_TIMEOUT mapped_ip=%s" % probe.mapped_ip) | probe.log("MAPPING_TIMEOUT") | def run(self): # Advance state of probes that are ready for probe in self.probes: now = time.time() if not probe.next_ts <= now: continue if probe.waiting: # Last ping timed out, so back off a TTL if probe.mapping_tries == probe.max_mapping_tries: probe.mapped = True probe.max_ttl -= 1 probe.log("MAPPED mapped_ip=%s ma... |
hosts = ['cnn.com', 'google.com', 'justin.tv', 'yahoo.com', 'nytimes.com', 'ustream.tv', 'ycombinator.com', 'blogtv.com', 'comcast.com', 'ea.com'] | hosts = ['cnn.com'] | def ping(self, addr, id=1, seq=1, ttl=255, verbose = False): addr = socket.gethostbyname(addr) packet = self.create_packet(addr, id, seq) if verbose: print "Pinging %s (id=%s seq=%s ttl=%s)" % (addr, id, seq, ttl) self.sock.setsockopt(socket.SOL_IP, socket.IP_TTL, ttl) # Python requires a tuple of (addr, port), but the... |
self.search_options[k]=v(self.context) return self.search_options | v = v(self.context) options[k] = v return options | def _search_options(self): for k,v in self.search_options.items(): if callable(v): self.search_options[k]=v(self.context) return self.search_options |
self.search_util = queryUtility(ISearch) | def search(self, kwargs={}): self.search_util = queryUtility(ISearch) parameters = {} query = self.build_query() flares = self.search_util(query, **parameters) self.contents = [PloneFlare(f) for f in flares] | |
def filters(self): return [] | def filters(self): return [] | |
def filters(self): return [] | filters = [] auto_count = None | def filters(self): return [] |
request_filters = [('review_state', 'state')] | request_filters = [('review_state', 'review_state')] | def filters(self): return [] |
template = self.table | template = self.table, auto_count = self.auto_count, | def render_listing(self): generator = queryUtility(ITableGenerator, 'ftw.tablegenerator') return generator.generate(self.batch, self.columns, sortable=True, selected=(self.sort_on, self.sort_order), template = self.table ) |
parsed_state = json.loads(state) if 'group' in parsed_state: del parsed_state['group'] state = json.dumps(parsed_state) | if state: parsed_state = json.loads(state) if 'group' in parsed_state: del parsed_state['group'] state = json.dumps(parsed_state) | def load_grid_state(self): """Loads the stored grid state - if any is stored. """ # get the key from the key generator generator = queryMultiAdapter((self.context, self, self.request), IGridStateStorageKeyGenerator) key = generator.get_key() |
parsed_state = json.loads(state) | def load_grid_state(self): """Loads the stored grid state - if any is stored. """ # get the key from the key generator generator = queryMultiAdapter((self.context, self, self.request), IGridStateStorageKeyGenerator) key = generator.get_key() | |
generator = queryMultiAdapter((self.context, listing, self.request), | generator = queryMultiAdapter((self.context, listing_view, self.request), | def setgridstate(self): """Stores the current grid configuration (visible columns, column order, grouping, sorting etc.) persistent in dictstorage. """ |
self.catalog = catalog = getToolByName(self.context, 'portal_catalog') | self.catalog = getToolByName(self.context, 'portal_catalog') | def search(self, kwargs): self.catalog = catalog = getToolByName(self.context, 'portal_catalog') query = self.build_query(**kwargs) self.contents = self.catalog(**query) self.len_results = len(self.contents) |
return len(self.contents) > self.pagesize | return self.len_results > self.pagesize | def multiple_pages(self): """The multiple_pages in plone.app.batch has a bug if size == pagesize.""" |
self.catalog = getToolByName(self.context,'portal_catalog') | self.catalog = catalog = getToolByName(self.context,'portal_catalog') | def search(self, kwargs): self.catalog = getToolByName(self.context,'portal_catalog') # if IATTopic.providedBy(self.context): # contentsMethod = self.context.queryCatalog # else: # contentsMethod = self.context.getFolderContents query = self.build_query(**kwargs) self.contents = self.catalog(**query) self.len_... |
self.contents = self.catalog(**query) | self.contents = catalog(**query) | def search(self, kwargs): self.catalog = getToolByName(self.context,'portal_catalog') # if IATTopic.providedBy(self.context): # contentsMethod = self.context.queryCatalog # else: # contentsMethod = self.context.getFolderContents query = self.build_query(**kwargs) self.contents = self.catalog(**query) self.len_... |
self._conditionCache.nail() | def _markColumnsAsDirty(self, colnames): """Mark column indexes in `colnames` as dirty.""" assert len(colnames) > 0 if self.indexed: colindexed, cols = self.colindexed, self.cols # Mark the proper indexes as dirty for colname in colnames: if colindexed[colname]: col = cols._g_col(colname) col.index.dirty = True # Put a... | |
assert o == [[(1, 1), (2, 2)]] | assert o == [[(2, 2), (3, 3)]] | def test_zoom_in(): import numpy from mock import Mock, Fake sound = Mock({"numchan": 1}) sound.changed = Fake() data = numpy.array([1, 2, 3, 4], DTYPE) sound.frames = data g = Graph(sound) g.set_width(2) g.zoom_in() o = g.channels() assert o == [[(1, 1), (2, 2)]] g.zoom_out() g.set_width(4) o = g.channels() assert ... |
assert g.channels() == [[(1, 1), (2, 2)]] | assert g.channels() == [[(1, 2), (3, 3)]] | def test_zoom_in_on(): import numpy from mock import Mock, Fake sound = Mock({"numchan": 1}) sound.changed = Fake() data = numpy.array([1, 2, 3, 4], DTYPE) sound.frames = data g = Graph(sound) g.set_width(2) g.zoom_in_on(0) assert g.channels() == [[(1, 1), (2, 2)]] g.zoom_out() g.zoom_in_on(1) assert g.channels() == ... |
assert g.channels() == [[(2, 2), (3, 3)]] | assert g.channels() == [[(1, 2), (3, 3)]] | def test_zoom_in_on(): import numpy from mock import Mock, Fake sound = Mock({"numchan": 1}) sound.changed = Fake() data = numpy.array([1, 2, 3, 4], DTYPE) sound.frames = data g = Graph(sound) g.set_width(2) g.zoom_in_on(0) assert g.channels() == [[(1, 1), (2, 2)]] g.zoom_out() g.zoom_in_on(1) assert g.channels() == ... |
assert g.channels() == [[(3, 3), (4, 4)]] | assert g.channels() == [[(1, 2), (3, 3)]] | def test_zoom_in_on(): import numpy from mock import Mock, Fake sound = Mock({"numchan": 1}) sound.changed = Fake() data = numpy.array([1, 2, 3, 4], DTYPE) sound.frames = data g = Graph(sound) g.set_width(2) g.zoom_in_on(0) assert g.channels() == [[(1, 1), (2, 2)]] g.zoom_out() g.zoom_in_on(1) assert g.channels() == ... |
start, end = self._selection.pixels() | pstart, pend = self._selection.pixels() fstart, fend = self._selection.get() | def button_press(self, widget, event): if event.button == 1: self.pressed = True x = event.x start, end = self._selection.pixels() # a double click resumes selection. if event.type == gtk.gdk._2BUTTON_PRESS: self._selection.pin(x) # extend towards left elif self._selection.selected() and near(start, x): self._selection... |
elif self._selection.selected() and near(start, x): self._selection.pin(end) | elif self._selection.selected() and near(pstart, x): self._selection.set(fend, fend) | def button_press(self, widget, event): if event.button == 1: self.pressed = True x = event.x start, end = self._selection.pixels() # a double click resumes selection. if event.type == gtk.gdk._2BUTTON_PRESS: self._selection.pin(x) # extend towards left elif self._selection.selected() and near(start, x): self._selection... |
elif self._selection.selected() and near(end, x): self._selection.pin(start) | elif self._selection.selected() and near(pend, x): self._selection.set(fstart, fstart) | def button_press(self, widget, event): if event.button == 1: self.pressed = True x = event.x start, end = self._selection.pixels() # a double click resumes selection. if event.type == gtk.gdk._2BUTTON_PRESS: self._selection.pin(x) # extend towards left elif self._selection.selected() and near(start, x): self._selection... |
self.move_to(frame - (self._width - 1) * self.density) | self.move_to(frame - (self._width - 1) * self.density * 0.5) | def center_on(self, frame): self.move_to(frame - (self._width - 1) * self.density) |
filename=self.filename()) | filename=self.notebook.filename()) | def save_selection_as(self, *args): dialog = SaveSelectionFileDialog(app.list_extensions(), parent=self, filename=self.filename()) filename = dialog.get_filename() if filename != None: self.notebook.save_selection_as(filename) |
realstart = str(start +1) realstop = str(stop +1) | realstart = str(start+1) realstop = str(stop) | def replace(self, start, stop, value): # FIXME right now this assumes that autoindent is ON # (the '!' in 'change!' means 'toggle autoindent' realstart = str(start +1) realstop = str(stop +1) if stop >= 2147483646: realstop = "$" self.vimp.sendkeys('<Esc>:%s,%s change!\n' % (realstart,realstop) ) for l in value: self.v... |
self.vimp.sendkeys('<Esc>:%s,%s change!\n' % (realstart,realstop) ) | if start == stop: self.vimp.sendkeys('<Esc>:%s,%s insert!\n' % (realstart,realstart) ) else: self.vimp.sendkeys('<Esc>:%s,%s change!\n' % (realstart,realstop) ) | def replace(self, start, stop, value): # FIXME right now this assumes that autoindent is ON # (the '!' in 'change!' means 'toggle autoindent' realstart = str(start +1) realstop = str(stop +1) if stop >= 2147483646: realstop = "$" self.vimp.sendkeys('<Esc>:%s,%s change!\n' % (realstart,realstop) ) for l in value: self.v... |
self.contents[original.linenum:original.linenum] = [str(original), str(addition)] | self.contents[original.linenum:original.linenum+1] = [str(original), str(addition)] | def split_todo(self, original, addition): r""" >>> i = TodoList([',INBOX','\tmust do X','\tmust do Y @CURRENT', ',CONTEXTS', '\t#FRED', '\t\tdo another thing @FOO']) >>> i.split_todo(i.current_todo(), '\tthen do Z') >>> j = i.contents >>> j[1] '\tmust do X' >>> j[2] '\tmust do Y @CURRENT' >>> j[3] '\tthen do Z' >>> j[4... |
self.contents[l:l+1] = [self.contents[l+1]] | self.contents[l:l+2] = [self.contents[l+1]] | def mark_current_done(self): r""" >>> i = TodoList([',INBOX','\tmust do X @CURRENT','\tmust do Y', ',CONTEXTS', '\t#FRED', '\t\tdo another thing @FOO']) >>> i.mark_current_done() >>> i.contents[0:3] [',INBOX', '\tmust do Y', ',CONTEXTS'] >>> 'must do X' in i.contents[-1] True >>> '@CURRENT' not in i.contents[-1] False ... |
print "usage: python imacro_asm.py infile.jsasm outfile.c.out" | print("usage: python imacro_asm.py infile.jsasm outfile.c.out") | def fail(msg, *args): raise ValueError("%s at %s:%d" % (msg % args, filename, lineno + 1)) |
def recv(self, block_size=65536): cothread.select([self.sock.fileno()], [], []) | def recv(self, block_size=65536, timeout=0.2): cothread.select([self.sock.fileno()], [], [], timeout) | def recv(self, block_size=65536): cothread.select([self.sock.fileno()], [], []) chunk = self.sock.recv(block_size) if not chunk: raise self.EOF('Connection closed by server') return chunk |
squared = u'\u00B2' | def read(self): '''Can be called at any time to read the most recent buffer.''' return 1e-3 * self.buffer.read(self.notify_size) | |
pass | self.show_x = show_x self.show_y = show_y | def show_xy(self, show_x, show_y): pass |
return numpy.nanmin(value), numpy.nanmax(value) | ix = (self.show_x, self.show_y) ix = numpy.nonzero(ix)[0] return numpy.nanmin(value[:, ix]), numpy.nanmax(value[:, ix]) | def get_minmax(self, value): value = self.compute(value) return numpy.nanmin(value), numpy.nanmax(value) |
def get_minmax(self, value): return numpy.nanmin(value), numpy.nanmax(value) | def get_minmax(self, value): return numpy.nanmin(value), numpy.nanmax(value) | |
self.show_x = show_x self.show_y = show_y | mode_common.show_xy(self, show_x, show_y) | def show_xy(self, show_x, show_y): self.show_x = show_x self.show_y = show_y self.set_visible() |
self.show_x = show_x self.show_y = show_y | mode_common.show_xy(self, show_x, show_y) | def show_xy(self, show_x, show_y): self.show_x = show_x self.show_y = show_y self.cxb.setVisible(show_x) self.cyb.setVisible(show_y) |
self.channel = int(self.ui.channel_id.text()) self.bpm_name = 'BPM id %d' % self.channel self.monitor.set_id(self.channel) | channel = int(self.ui.channel_id.text()) if channel != self.channel: self.channel = channel self.bpm_name = 'BPM id %d' % channel self.monitor.set_id(channel) | def set_channel_id(self): self.channel = int(self.ui.channel_id.text()) self.bpm_name = 'BPM id %d' % self.channel self.monitor.set_id(self.channel) |
print 'Generating manifest' | def generate_manifest(self, path, prefix, parts, parts_digest, file, key, iv, cert_path, ec2cert_path, private_key_path, target_arch, image_size, bundled_size, image_digest, user, kernel, ramdisk, mapping=None, product_codes=None, ancestor_ami_ids=None): print 'Generating manifest' | |
def register_image(self, name=None, description=None, image_location=None, architecture=None, kernel_id=None, ramdisk_id=None, root_device_name=None, block_device_map=None): """ Register an image. :type name: string :param name: The name of the AMI. Valid only for EBS-based images. :type description: string :param d... | def endElement(self, name, value, connection): if name == 'virtualName': self.current_vname = value elif name == 'device' or name == 'deviceName': if hasattr(self, 'current_vname') and self.current_vname: self[self.current_vname] = value self.current_vname = None else: self.current_name = value | |
return boto.connect_ec2( | return EC2Connection( | def make_connection(self): if not self.ec2_user_access_key: self.ec2_user_access_key = self.environ['EC2_ACCESS_KEY'] if not self.ec2_user_access_key: print 'EC2_ACCESS_KEY environment variable must be set.' raise ConnectionFailed |
filename = '%s.%d' % (file, i) | filename = '%s.%02d' % (file, i) | def split_file(self, file, chunk_size): parts = [] parts_digest = [] file_size = os.path.getsize(file) in_file = open(file, 'rb') number_parts = int(file_size / chunk_size) number_parts += 1 bytes_read = 0 for i in range(0, number_parts, 1): filename = '%s.%d' % (file, i) part_digest = sha() file_part = open(filename, ... |
in_file = open(image_file, 'rb') sha_image = sha() buf = in_file.read(IMAGE_IO_CHUNK) while buf: sha_image.update(buf) buf = in_file.read(IMAGE_IO_CHUNK) return (image_size, hexlify(sha_image.digest())) | return image_size | def check_image(self, image_file, path): print 'Checking image' if not os.path.exists(path): os.makedirs(path) image_size = os.path.getsize(image_file) if self.debug: print 'Image Size:', image_size, 'bytes' in_file = open(image_file, 'rb') sha_image = sha() buf = in_file.read(IMAGE_IO_CHUNK) while buf: sha_image.updat... |
print 'Tarring image' tar_file = '%s.tar.gz' % os.path.join(path, prefix) outfile = open(tar_file, 'wb') | targz = '%s.tar.gz' % os.path.join(path, prefix) targzfile = open(targz, 'w') tar_cmd = ['tar', 'ch', '-S'] | def tarzip_image( self, prefix, file, path, ): Util().check_prerequisite_command('tar') |
tar_cmd = ['tar', 'ch', '-S'] | def tarzip_image( self, prefix, file, path, ): Util().check_prerequisite_command('tar') | |
p1 = Popen(tar_cmd, stdout=PIPE) p2 = Popen(['gzip'], stdin=p1.stdout, stdout=outfile) p2.communicate() outfile.close if os.path.getsize(tar_file) <= 0: print 'Could not tar image' | tarproc = subprocess.Popen(tar_cmd, stdout=subprocess.PIPE) zipproc = subprocess.Popen(['gzip'], stdin=subprocess.PIPE, stdout=targzfile) sha_image = sha() buf=os.read(tarproc.stdout.fileno(), 8196) while buf: zipproc.stdin.write(buf) sha_image.update(buf) buf=os.read(tarproc.stdout.fileno(), 8196) zipproc.stdin.clo... | def tarzip_image( self, prefix, file, path, ): Util().check_prerequisite_command('tar') |
return tar_file | return (targz, hexlify(sha_image.digest())) | def tarzip_image( self, prefix, file, path, ): Util().check_prerequisite_command('tar') |
key = hex(BN.rand(16 * 8))[2:34].replace('L', 'c') | key = hex(BN.rand(17 * 8,top=0))[4:36] | def encrypt_image(self, file): print 'Encrypting image' enc_file = '%s.part' % file.replace('.tar.gz', '') |
iv = hex(BN.rand(16 * 8))[2:34].replace('L', 'c') | iv = hex(BN.rand(17 * 8,top=0))[4:36] | def encrypt_image(self, file): print 'Encrypting image' enc_file = '%s.part' % file.replace('.tar.gz', '') |
class ConnectionFailed: def __init__(self): self.message = "Connection failed" | def __init__(self): | |
sys.exit(1) | raise ConnectionFailed | def make_connection(self): |
user_eucarc = os.path.join(os.getenv('HOME'), ".eucarc") | user_eucarc = None if 'HOME' in os.environ: os.path.join(os.getenv('HOME'), ".eucarc") | def setup_environ(self): |
elif os.path.exists(user_eucarc): | elif user_eucarc is not None and os.path.exists(user_eucarc): | def setup_environ(self): |
try: Util().check_prerequisite_command(self.MAKEFS_CMD) except NotFoundError: sys.exit(1) | Util().check_prerequisite_command(self.MAKEFS_CMD) | def make_fs(self, image_path): try: Util().check_prerequisite_command(self.MAKEFS_CMD) except NotFoundError: sys.exit(1) |
sys.exit(1) | raise UnsupportedException | def create_image(self, size_in_MB, image_path): |
sys.exit(1) | raise UnsupportedException | def make_fs(self, image_path): |
sys.exit(1) | raise UnsupportedException | def make_essential_devs(self, image_path): |
sys.exit(1) | def usage(self, compat=False): | |
sys.exit(1) | raise NotFoundError | def get_environ(self, name): if self.environ.has_key(name): |
try: Util().check_prerequisite_command('tar') except NotFoundError: sys.exit(1) | Util().check_prerequisite_command('tar') | def tarzip_image(self, prefix, file, path): try: Util().check_prerequisite_command('tar') except NotFoundError: sys.exit(1) |
sys.exit(1) | raise CommandFailed | def tarzip_image(self, prefix, file, path): try: Util().check_prerequisite_command('tar') except NotFoundError: sys.exit(1) |
sys.exit(1) | raise UnsupportedException | def make_image(self, size_in_MB, excludes, prefix, destination_path): image_file = '%s.img' % (prefix) image_path = '%s/%s' % (destination_path, image_file) if not os.path.exists(destination_path): os.makedirs(destination_path) |
try: Util().check_prerequisite_command('losetup') except NotFoundError: sys.exit(1) | Util().check_prerequisite_command('losetup') | def create_loopback(self, image_path): |
sys.exit(1) | raise CommandFailed | def create_loopback(self, image_path): |
try: Util().check_prerequisite_command('mount') except NotFoundError: sys.exit(1) | Util().check_prerequisite_command('mount') | def mount_image(self, image_path): try: Util().check_prerequisite_command('mount') except NotFoundError: sys.exit(1) |
try: Util().check_prerequisite_command('umount') except NotFoundError: sys.exit(1) | Util().check_prerequisite_command('umount') | def unmount_image(self, mount_point): try: Util().check_prerequisite_command('umount') except NotFoundError: sys.exit(1) |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.