function stringlengths 11 56k | repo_name stringlengths 5 60 | features list |
|---|---|---|
def update(self, pkg=None):
ayum = yum.YumBase()
ayum.doGenericSetup()
ayum.doRepoSetup()
try:
ayum.doLock()
if pkg != None:
tx_result = ayum.update(pattern=pkg)
else:
tx_result = ayum.update()
ayum.buildTransaction()
ayum.processTransaction(
callback=DummyCallback())
finally:
ayum.closeRpmDB()
ayum.doUnlock()
return map(str, tx_result) | kadamski/func | [
9,
2,
9,
1,
1211919894
] |
def init_state(env, startPos):
# declare events
env.memory.declareEvent(EVENT_LOOK_FOR_PEOPLE); | davesnowdon/nao-wanderer | [
7,
14,
7,
13,
1358257635
] |
def shutdown(env):
planner = get_planner_instance(env)
planner.shutdown()
executor = get_executor_instance(env, None)
executor.shutdown()
mapper = get_mapper_instance(env)
mapper.shutdown()
updater_instances = get_updaters(env)
for updater in updater_instances:
updater.shutdown() | davesnowdon/nao-wanderer | [
7,
14,
7,
13,
1358257635
] |
def __init__(self, env_):
super(Planner, self).__init__()
self.env = env_ | davesnowdon/nao-wanderer | [
7,
14,
7,
13,
1358257635
] |
def does_event_interrupt_plan(self, event, state):
return True | davesnowdon/nao-wanderer | [
7,
14,
7,
13,
1358257635
] |
def shutdown(self):
pass | davesnowdon/nao-wanderer | [
7,
14,
7,
13,
1358257635
] |
def __init__(self, env, actionExecutor):
super(PlanExecutor, self).__init__()
self.env = env
self.actionExecutor = actionExecutor | davesnowdon/nao-wanderer | [
7,
14,
7,
13,
1358257635
] |
def _have_moved_wrapper(self):
self.env.log("Have moved")
pos = get_position(self.env)
lastPos = get_last_position(self.env)
self.have_moved(lastPos, pos)
save_waypoint(self.env, pos) | davesnowdon/nao-wanderer | [
7,
14,
7,
13,
1358257635
] |
def have_moved(self, previousPos, currentPos):
pass | davesnowdon/nao-wanderer | [
7,
14,
7,
13,
1358257635
] |
def shutdown(self):
pass | davesnowdon/nao-wanderer | [
7,
14,
7,
13,
1358257635
] |
def __init__(self, env):
super(AbstractMapper, self).__init__()
self.env = env | davesnowdon/nao-wanderer | [
7,
14,
7,
13,
1358257635
] |
def update(self, position, sensors):
pass | davesnowdon/nao-wanderer | [
7,
14,
7,
13,
1358257635
] |
def get_map(self):
return None | davesnowdon/nao-wanderer | [
7,
14,
7,
13,
1358257635
] |
def __init__(self, env):
super(NullMapper, self).__init__(env) | davesnowdon/nao-wanderer | [
7,
14,
7,
13,
1358257635
] |
def __init__(self, env, save_data=True):
super(FileLoggingMapper, self).__init__(env)
self.save_data = save_data
if self.save_data:
self.open_data_file() | davesnowdon/nao-wanderer | [
7,
14,
7,
13,
1358257635
] |
def update(self, position, sensors):
if self.save_data:
self.save_update_data(position, sensors) | davesnowdon/nao-wanderer | [
7,
14,
7,
13,
1358257635
] |
def open_data_file(self):
self.logFilename = tempfile.mktemp()
self.env.log("Saving sensor data to {}".format(self.logFilename))
self.first_write = True
try:
self.logFile = open(self.logFilename, 'r+')
except IOError:
self.env.log("Failed to open file: {}".format(self.logFilename))
self.logFile = None | davesnowdon/nao-wanderer | [
7,
14,
7,
13,
1358257635
] |
def save_update_data(self, position, sensors):
if self.logFile:
data = { 'timestamp' : self.timestamp(),
'position' : position,
'leftSonar' : sensors.get_sensor('LeftSonar'),
'rightSonar' : sensors.get_sensor('RightSonar') }
jstr = json.dumps(data)
#self.env.log("Mapper.update: "+jstr)
if not self.first_write:
self.logFile.write(",\n")
self.logFile.write(jstr)
self.first_write = False
self.logFile.flush() | davesnowdon/nao-wanderer | [
7,
14,
7,
13,
1358257635
] |
def write_sensor_data_to_file(self, fp, buffer_size=1024):
if self.logFile:
self.logFile.seek(0)
fp.write('[\n')
while 1:
copy_buffer = self.logFile.read(buffer_size)
if copy_buffer:
fp.write(copy_buffer)
else:
break
fp.write(' ]\n')
self.logFile.seek(0, 2) | davesnowdon/nao-wanderer | [
7,
14,
7,
13,
1358257635
] |
def get_planner_instance(env):
global planner_instance
if not planner_instance:
fqcn = env.get_property(DEFAULT_CONFIG_FILE, PROPERTY_PLANNER_CLASS, DEFAULT_PLANNER_CLASS)
env.log("Creating a new planner instance of {}".format(fqcn))
klass = find_class(fqcn)
planner_instance = klass(env)
return planner_instance | davesnowdon/nao-wanderer | [
7,
14,
7,
13,
1358257635
] |
def get_executor_instance(env, actionExecutor):
global executor_instance
if not executor_instance:
fqcn = env.get_property(DEFAULT_CONFIG_FILE, PROPERTY_EXECUTOR_CLASS, DEFAULT_EXECUTOR_CLASS)
env.log("Creating a new executor instance of {}".format(fqcn))
klass = find_class(fqcn)
executor_instance = klass(env, actionExecutor)
# NOT THREAD SAFE
# even if we already had an instance of an executor the choreographe object might have become
# stale so we refresh it. We only have one executor instance at once so this should be OK
executor_instance.actionExecutor = actionExecutor
return executor_instance | davesnowdon/nao-wanderer | [
7,
14,
7,
13,
1358257635
] |
def get_mapper_instance(env):
global mapper_instance
if not mapper_instance:
fqcn = env.get_property(DEFAULT_CONFIG_FILE, PROPERTY_MAPPER_CLASS, DEFAULT_MAPPER_CLASS)
env.log("Creating a new mapper instance of {}".format(fqcn))
klass = find_class(fqcn)
mapper_instance = klass(env)
return mapper_instance | davesnowdon/nao-wanderer | [
7,
14,
7,
13,
1358257635
] |
def get_updaters(env):
global updater_instances
if not updater_instances:
updater_instances = []
fqcns = env.get_property(DEFAULT_CONFIG_FILE, PROPERTY_UPDATER_CLASSES)
if fqcns:
for fqcn in fqcns:
env.log("Creating a new updater instance of {}".format(fqcn))
klass = find_class(fqcn)
updater = klass(env)
if updater:
updater_instances.append(updater) | davesnowdon/nao-wanderer | [
7,
14,
7,
13,
1358257635
] |
def make_wanderer_environment(box_):
env = make_environment(box_)
env.set_application_name(WANDERER_NAME)
return env | davesnowdon/nao-wanderer | [
7,
14,
7,
13,
1358257635
] |
def save_event(env, event):
env.memory.insertData(MEM_CURRENT_EVENT, to_json_string(event)) | davesnowdon/nao-wanderer | [
7,
14,
7,
13,
1358257635
] |
def save_plan(env, plan):
env.memory.insertData(MEM_PLANNED_ACTIONS, to_json_string(plan)) | davesnowdon/nao-wanderer | [
7,
14,
7,
13,
1358257635
] |
def save_completed_actions(env, actions):
env.memory.insertData(MEM_COMPLETED_ACTIONS, to_json_string(actions)) | davesnowdon/nao-wanderer | [
7,
14,
7,
13,
1358257635
] |
def get_current_action(env):
return from_json_string(env.memory.getData(MEM_CURRENT_ACTIONS)) | davesnowdon/nao-wanderer | [
7,
14,
7,
13,
1358257635
] |
def push_completed_action(env, action):
actions = load_completed_actions(env)
if actions is None:
actions = []
actions.append(action)
save_completed_actions(env, actions) | davesnowdon/nao-wanderer | [
7,
14,
7,
13,
1358257635
] |
def save_direction(env, hRad):
env.memory.insertData(MEM_HEADING, hRad) | davesnowdon/nao-wanderer | [
7,
14,
7,
13,
1358257635
] |
def get_path(env):
return env.memory.getData(MEM_WALK_PATH) | davesnowdon/nao-wanderer | [
7,
14,
7,
13,
1358257635
] |
def get_last_position(env):
path = get_path(env)
pos = None
if not path is None:
try:
pos = path[-1]
except IndexError:
pass
return pos | davesnowdon/nao-wanderer | [
7,
14,
7,
13,
1358257635
] |
def get_position(env):
# 1 = FRAME_WORLD
return env.motion.getPosition("Torso", 1, True) | davesnowdon/nao-wanderer | [
7,
14,
7,
13,
1358257635
] |
def read_class_path(class_path):
'''Cache content of all jars.
Begin with rt.jar
'''
# folders for lookup for class files
lookup_paths = []
# content of all jars (name->path to jar)
jars = {}
# content of rt.jar
rt = {}
# first check local rt.jar
local_path = os.path.dirname(os.path.realpath(__file__))
RT_JAR = os.path.join(local_path, "../rt/rt.jar")
if not os.path.isfile(RT_JAR):
JAVA_HOME = os.environ.get('JAVA_HOME')
if JAVA_HOME is None:
raise Exception("JAVA_HOME is not set")
if not os.path.isdir(JAVA_HOME):
raise Exception("JAVA_HOME must be a folder: %s" % JAVA_HOME)
RT_JAR = os.path.join(JAVA_HOME, "lib/rt.jar")
if not os.path.exists(RT_JAR) or os.path.isdir(RT_JAR):
RT_JAR = os.path.join(JAVA_HOME, "jre/lib/rt.jar")
if not os.path.exists(RT_JAR) or os.path.isdir(RT_JAR):
raise Exception("rt.jar not found")
if not zipfile.is_zipfile(RT_JAR):
raise Exception("rt.jar is not a zip: %s" % RT_JAR)
read_from_jar(RT_JAR, rt)
current = os.getcwd()
splitter = None
if ":" in class_path:
splitter = ":"
elif ";" in class_path:
splitter = ";"
elif "," in class_path:
splitter = ","
else:
splitter = ":"
cpaths = class_path.split(splitter)
for p in cpaths:
p = p.strip()
path = os.path.join(current, p)
if not os.path.exists(path):
raise Exception("Wrong class path entry: %s (path not found %s)",
p, path)
if os.path.isdir(path):
lookup_paths.append(path)
else:
if zipfile.is_zipfile(path):
read_from_jar(path, jars)
else:
raise Exception("Class path entry %s is not a jar file" % path)
return (lookup_paths, jars, rt) | andrewromanenco/pyjvm | [
233,
25,
233,
3,
1396823002
] |
def __init__(self, bodies, **kwargs):
""" data is a from Load.BodyData """
# Performance data | Qirky/PyKinectTk | [
30,
14,
30,
4,
1455203905
] |
def update(self, frame):
""" Used to animate the drawing - passes a blitting=True argument to draw() """
self.draw(frame, blitting=True)
return self.lines | Qirky/PyKinectTk | [
30,
14,
30,
4,
1455203905
] |
def display():
plt.show() | Qirky/PyKinectTk | [
30,
14,
30,
4,
1455203905
] |
def draw_bone(self, body, a, b, i):
""" Draws update line i to draw a line between a and b """
# Re-order axes
# Kinect Axis Z is depth (matplot X)
# Kinect Axis Y is height (matplot Z)
# Kinect Axis X is width (matplot y) | Qirky/PyKinectTk | [
30,
14,
30,
4,
1455203905
] |
def animate(view):
""" Takes a 3D.View object and 'plays' the frames """
try:
mov = animation.FuncAnimation(view.fig, view.update, interval=view.rate, blit=False)
view.display()
except:
pass | Qirky/PyKinectTk | [
30,
14,
30,
4,
1455203905
] |
def setUpClass(cls):
cls.conf = load_test_config() | partofthething/infopanel | [
31,
10,
31,
10,
1486934002
] |
def test_connect(self):
"""
Make sure we can connect.
This relies on the test.mosquitto.org test server.
"""
self.client.start()
self.client.stop() | partofthething/infopanel | [
31,
10,
31,
10,
1486934002
] |
def __init__(self, filename, gdal_dataset, gdal_metadata, date=None,
ds=None, bands=None, cachedir=None, *args, **kwargs):
self.test_mapper(filename)
if not IMPORT_SCIPY:
raise NansatReadError('Sentinel-1 data cannot be read because scipy is not installed')
timestamp = date if date else self.get_date(filename)
self.create_vrt(filename, gdal_dataset, gdal_metadata, timestamp, ds, bands, cachedir)
Sentinel1.__init__(self, filename)
self.add_calibrated_nrcs(filename)
self.add_nrcs_VV_from_HH(filename) | nansencenter/nansat | [
169,
65,
169,
91,
1374067434
] |
def add_nrcs_VV_from_HH(self, filename):
if not 'Amplitude_HH' in self.ds.variables.keys():
return
layer_time_id, layer_date = Opendap.get_layer_datetime(None,
self.convert_dstime_datetimes(self.get_dataset_time()))
dims = list(self.ds.variables['dn_HH'].dimensions)
dims[dims.index(self.timeVarName)] = layer_time_id
src = [
self.get_metaitem(filename, 'Amplitude_HH', dims)['src'],
self.get_metaitem(filename, 'sigmaNought_HH', dims)['src'],
{'SourceFilename': self.band_vrts['inciVRT'].filename, 'SourceBand': 1}
]
dst = {
'wkv': 'surface_backwards_scattering_coefficient_of_radar_wave',
'PixelFunctionType': 'Sentinel1Sigma0HHToSigma0VV',
'polarization': 'VV',
'suffix': 'VV'}
self.create_band(src, dst)
self.dataset.FlushCache() | nansencenter/nansat | [
169,
65,
169,
91,
1374067434
] |
def get_date(filename):
"""Extract date and time parameters from filename and return
it as a formatted (isoformat) string
Parameters
----------
filename: str
nn
Returns
-------
str, YYYY-mm-ddThh:MMZ
"""
_, filename = os.path.split(filename)
t = datetime.strptime(filename.split('_')[4], '%Y%m%dT%H%M%S')
return datetime.strftime(t, '%Y-%m-%dT%H:%M:%SZ') | nansencenter/nansat | [
169,
65,
169,
91,
1374067434
] |
def __init__(self, interval=1):
print "init flogger3"
print "flogger3 initialized"
return | tobiz/OGN-Flight-Logger_V3 | [
1,
2,
1,
2,
1489363723
] |
def flogger_run(self, settings):
print "flogger_run called"
print "settings.FLOGGER_SMTP_SERVER_URL: ", settings.FLOGGER_SMTP_SERVER_URL | tobiz/OGN-Flight-Logger_V3 | [
1,
2,
1,
2,
1489363723
] |
def floggerStop(self):
print "floggerStop called" | tobiz/OGN-Flight-Logger_V3 | [
1,
2,
1,
2,
1489363723
] |
def flogger_start(self, local_settings):
print "flogger_start called\n"
settings = local_settings | tobiz/OGN-Flight-Logger_V3 | [
1,
2,
1,
2,
1489363723
] |
def CheckPrev(callsignKey, dataKey, value):
print "CheckPrev if callsign in nprev_vals: ", callsignKey, " key: ", dataKey, " Value: ", value
if nprev_vals.has_key(callsignKey) == 1:
print "nprev_vals already has entry: ", callsignKey
else:
print "nprev_vals doesn't exist for callsignKey: ", callsignKey
nprev_vals[callsignKey] = {}
nprev_vals[callsignKey] = {'latitude': 0, 'longitude': 0, "altitude": 0, "speed": 0, 'maxA': 0}
nprev_vals[callsignKey][dataKey] = value
print "nprev_vals for callsignKey: ", callsignKey, " is: ", nprev_vals[callsignKey] | tobiz/OGN-Flight-Logger_V3 | [
1,
2,
1,
2,
1489363723
] |
def CheckVals(callsignKey, dataKey, value):
print "CheckVals if callsign in nvalues: ", callsignKey, " key: ", dataKey, " Value: ", value
if nvalues.has_key(callsignKey) == 1:
print "nvalues already has entry: ", callsignKey
else:
print "nvalues doesn't exist for callsignKey: ", callsignKey
nvalues[callsignKey] = {}
nvalues[callsignKey] = {'latitude': 0, 'longitude': 0, "altitude": 0, "speed": 0, 'maxA': 0}
nvalues[callsignKey][dataKey] = value
print "nvalues for callsignKey: ", callsignKey, " is: ", nvalues[callsignKey] | tobiz/OGN-Flight-Logger_V3 | [
1,
2,
1,
2,
1489363723
] |
def isDayLight ():
return True | tobiz/OGN-Flight-Logger_V3 | [
1,
2,
1,
2,
1489363723
] |
def fleet_check(call_sign):
if aircraft.has_key(call_sign):
return True
else:
return False | tobiz/OGN-Flight-Logger_V3 | [
1,
2,
1,
2,
1489363723
] |
def comp_vals(set1, set2):
# Works out if the difference in positions is small and both speeds are close to zero
# Return True is yes and False if no
# Set1 are new values, set2 old values
print "Set1 value for key latitude is: ", set1["latitude"], " value: ", float(set1["latitude"]) | tobiz/OGN-Flight-Logger_V3 | [
1,
2,
1,
2,
1489363723
] |
def set_keepalive(sock, after_idle_sec=1, interval_sec=3, max_fails=5):
"""Set TCP keepalive on an open socket. | tobiz/OGN-Flight-Logger_V3 | [
1,
2,
1,
2,
1489363723
] |
def is_dst(zonename):
# Determine if in daylight
tz = pytz.timezone(zonename)
now = pytz.utc.localize(datetime.utcnow())
return now.astimezone(tz).dst() != timedelta(0) | tobiz/OGN-Flight-Logger_V3 | [
1,
2,
1,
2,
1489363723
] |
def fleet_check_new(callsign):
#
# This has become a little confusing! If FLOGGER_FLEET_CHECK == n|N then FLOGGER_AIRFIELD_NAME is not used in
# the flarm_db search so a non-fleet aircraft can be found, but the later code checks whether the aircraft
# has taken off at FLOGGER_AIRFIELD_NAME; if it hasn't it won't be included in the flights, if it has it will.
#
# This logic and code needs to be re-thought!
# Note, there is a difference between aircraft registered to a location and in a designated 'fleet' for
# that location and whether the aircraft has taken off from a location.
# The fleet_check is intended to check whether an aircraft is a member of a designated fleet, not whether
# it has taken off from the designated location. The intention if the fleet check is to enable recording only
# flights undertaken by the club fleet.
#
print "In fleet check for: ", callsign | tobiz/OGN-Flight-Logger_V3 | [
1,
2,
1,
2,
1489363723
] |
def callsign_trans(callsign):
# Translates a callsign supplied as a flarm_id
# into the aircraft registration using a local db based on flarmnet or OGN
# Note if OGN db is being used then callsigns don't start with FLR or ICA, this is denoted by the 'Type' field | tobiz/OGN-Flight-Logger_V3 | [
1,
2,
1,
2,
1489363723
] |
def APRS_connect (settings):
#
#-----------------------------------------------------------------
# Connect to the APRS server to receive flarm data
#-----------------------------------------------------------------
# | tobiz/OGN-Flight-Logger_V3 | [
1,
2,
1,
2,
1489363723
] |
def addTrack(cursor,flight_no,track_no,longitude,latitude,altitude,course,speed,timeStamp):
#
#-----------------------------------------------------------------
# Add gps track data to track record if settings.FLOGGER_TRACK is "Y" ie yes
# and if flight_no != None which it will be if flight has not taken off at FLOGGER_AIRFIELD_NAME
#-----------------------------------------------------------------
# | tobiz/OGN-Flight-Logger_V3 | [
1,
2,
1,
2,
1489363723
] |
def endTrack():
return | tobiz/OGN-Flight-Logger_V3 | [
1,
2,
1,
2,
1489363723
] |
def CheckTrackData(cursor, flight_no, track_no, callsignKey): | tobiz/OGN-Flight-Logger_V3 | [
1,
2,
1,
2,
1489363723
] |
def check_position_packet (packet_str):
#
#-----------------------------------------------------------------
# This function determines if airfield is in the list of APRS
# base stations used for receiving position fixes.
#
# base_list should be set up as part of the main code initialisation
#-----------------------------------------------------------------
# | tobiz/OGN-Flight-Logger_V3 | [
1,
2,
1,
2,
1489363723
] |
def delete_table (table):
#
#-----------------------------------------------------------------
# This function deletes the SQLite3 table
# with the name supplied by "table".
#-----------------------------------------------------------------
# | tobiz/OGN-Flight-Logger_V3 | [
1,
2,
1,
2,
1489363723
] |
def delete_flogger_file(folder, filename, days):
#
#-----------------------------------------------------------------
# This function deletes the files whose name contain filename in folder folder
# if they were created up to and including the number of days in the past
# specified by the days parameter.
# If days is zero then no deletions are performed
#-----------------------------------------------------------------
#
print "folder: ", folder
print "filename: ", filename
if days <= 0:
print "Don't delete old files, return"
return | tobiz/OGN-Flight-Logger_V3 | [
1,
2,
1,
2,
1489363723
] |
def connect_APRS(sock):
#
#-----------------------------------------------------------------
#
# This function tries to shutdown the specified sock and if it
# fails closes it and then creates a new one and reconnects to the APRS system
#
#-----------------------------------------------------------------
#
try:
sock.shutdown(0)
except socket.error, e:
if 'not connected' in e:
print '*** Transport endpoint is not connected ***'
print "socket no longer open so can't be closed, create new one"
else:
print "Socket still open so close it"
sock.close()
print "Create new socket"
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
sock.connect((settings.APRS_SERVER_HOST, settings.APRS_SERVER_PORT))
except Exception, e:
print "Connection refused. Errno: ", e
exit()
APRSparm = ('user %s pass %s vers %s %s filter r/%s/%s/%s\n ' % (settings.APRS_USER,
settings.APRS_PASSCODE,
settings.FLOGGER_NAME,
settings.FLOGGER_VER,
settings.FLOGGER_LATITUDE,
settings.FLOGGER_LONGITUDE,
settings.FLOGGER_RAD)) | tobiz/OGN-Flight-Logger_V3 | [
1,
2,
1,
2,
1489363723
] |
def _disassemble_word(word):
i = struct.pack(">I", word)
r = md.disasm(i, 4).next()
return "%s %s" % (r.mnemonic, r.op_str) | sstjohn/thundergate | [
69,
10,
69,
2,
1430539071
] |
def __init__(self):
self._references = []
self._scopes = []
self._fixed_reference_end = None
self._fixed_scope_end = None
self._known_frame_levels = [] | sstjohn/thundergate | [
69,
10,
69,
2,
1430539071
] |
def _add_variables_references(self, v):
if hasattr(v, "children") and isinstance(v.children, list) and len(v.children) > 0:
self._assign_variablesReference(v)
for c in v.children:
c.scope = v.scope
self._add_variables_references(c) | sstjohn/thundergate | [
69,
10,
69,
2,
1430539071
] |
def _add_scope(self, s, fl=0):
print "adding scope %s" % s.name
s.fl = fl
self._assign_variablesReference(s)
self._scopes += [s]
for c in s.children:
c.scope = s
self._add_variables_references(c)
if not fl in self._known_frame_levels:
self._known_frame_levels += [fl] | sstjohn/thundergate | [
69,
10,
69,
2,
1430539071
] |
def clear_dynamic_scopes(self):
self._scopes = self._scopes[:self._fixed_scope_end]
self._references = self._references[:self._fixed_reference_end]
self._fixed_scope_end = None
self._fixed_reference_end = None
self._known_frame_levels = [] | sstjohn/thundergate | [
69,
10,
69,
2,
1430539071
] |
def dereference(self, ref_no):
return self._references[ref_no - 1] | sstjohn/thundergate | [
69,
10,
69,
2,
1430539071
] |
def __init__(self, dev, di, do):
self.data_in = di
self.data_out = do
self.dev = dev
self._monitor = ExecutionMonitor(dev, functools.partial(CDPServer._evt_stopped, self))
self.__dispatch_setup()
self._register_model = model_registers(dev)
self._register_model.accessor = functools.partial(get_data_value, mroot=self._register_model)
self._memory_model = model_memory(dev)
self._memory_model.accessor = functools.partial(get_data_value, mroot=self._register_model)
self._vt = Var_Tracker()
self._vt.add_fixed_scope(self._register_model)
self._vt.add_fixed_scope(self._memory_model)
for c in self._register_model.children:
if c.name == "rxcpu":
s = ScopeModel("rxcpu registers")
s2 = ScopeModel("rxcpu state")
for r in c.children:
if r.name[0] == 'r' and r.name[1:].isdigit():
reg_no = int(r.name[1:])
reg_name = mips_regs.inv[reg_no]
reg_for_display = GenericModel(r.name, r.parent)
reg_for_display.display_name = reg_name
s.children += [reg_for_display]
if r.name == "pc":
ss = GenericModel(r.name, r.parent)
ss.display_name = "program counter"
ss.accessor = lambda r=r:self._register_model.accessor(r)
s2.children += [ss]
if r.name == "ir":
ss = GenericModel(r.name, r.parent)
ss.display_name = "instruction register"
ss.accessor = lambda r=r:self._register_model.accessor(r)
s2.children += [ss]
if not _no_capstone:
ss = GenericModel(r.name, r.parent)
ss.display_name = "instruction register (decoded)"
ss.accessor = lambda r=r:_disassemble_word(self._register_model.accessor(r))
s2.children += [ss]
if r.name in ["mode", "status"]:
ss = GenericModel(r.name, r.parent)
ss.accessor = lambda r=r:self._register_model.accessor(r)
for b in r.children:
cc = GenericModel(b.name, b.parent)
cc.accessor = lambda b=b:self._register_model.accessor(b)
ss.children += [cc]
s2.children += [ss] | sstjohn/thundergate | [
69,
10,
69,
2,
1430539071
] |
def __enter__(self):
return self | sstjohn/thundergate | [
69,
10,
69,
2,
1430539071
] |
def __dispatch_setup(self):
self.__dispatch_tbl = {}
for i in self.__class__.__dict__:
if len(i) > 5 and i[0:5] == "_cmd_":
self.__dispatch_tbl[unicode(i[5:])] = getattr(self, i) | sstjohn/thundergate | [
69,
10,
69,
2,
1430539071
] |
def _cmd_initialize(self, cmd):
self._seq = 1
ex = {}
ex["supportsConfigurationDoneRequest"] = True
ex["supportEvaluateForHovers"] = False
self._respond(cmd, True, ex=ex) | sstjohn/thundergate | [
69,
10,
69,
2,
1430539071
] |
def _cmd_setExceptionBreakpoints(self, cmd):
self._respond(cmd, False) | sstjohn/thundergate | [
69,
10,
69,
2,
1430539071
] |
def __advance_to_next_line(self):
while True:
self.dev.rxcpu.mode.single_step = 1
count = 0
while self.dev.rxcpu.mode.single_step:
count += 1
if count > 500:
raise Exception("single step bit failed to clear")
current_pc = self.dev.rxcpu.pc
if not current_pc in self._bp_replaced_insn:
ir_reg_val = self.dev.rxcpu.ir
insn_from_mem = struct.unpack(">I", self.dev.rxcpu.tr_read(current_pc, 1))[0]
if ir_reg_val != insn_from_mem:
print "ir reg is %x, should be %x, fixing." % (ir_reg_val, insn_from_mem)
self.dev.rxcpu.ir = insn_from_mem
ir_reg_val = self.dev.rxcpu.ir
assert ir_reg_val == insn_from_mem
else:
self.__prepare_resume_from_breakpoint()
if current_pc in self._image._addresses:
break | sstjohn/thundergate | [
69,
10,
69,
2,
1430539071
] |
def _cmd_next(self, cmd):
self._respond(cmd, True)
pc = self.dev.rxcpu.pc
cl = self._image.addr2line(pc)
self._log_write("single step began at pc: %x, cl: %s" % (pc, cl))
self.__advance_to_next_line()
pc = self.dev.rxcpu.pc
cl = self._image.addr2line(pc)
self._log_write("single step completed at pc: %x, cl: \"%s\"" % (pc, cl))
self.__prepare_resume_from_breakpoint()
self._event("stopped", {"reason": "step", "threadId": 1}) | sstjohn/thundergate | [
69,
10,
69,
2,
1430539071
] |
def _cmd_disconnect(self, cmd):
self._running = False
self._respond(cmd, True) | sstjohn/thundergate | [
69,
10,
69,
2,
1430539071
] |
def _cmd_pause(self, cmd):
self._respond(cmd, True)
self.dev.rxcpu.halt() | sstjohn/thundergate | [
69,
10,
69,
2,
1430539071
] |
def __stack_unwind(self):
frame_state_attrs = ["r%d" % x for x in range(32)] + ["pc"]
frame_state = {}
for a in frame_state_attrs:
frame_state[a] = getattr(self.dev.rxcpu, a)
if 0x8008000 <= frame_state["pc"] and 0x8008010 > frame_state["pc"]:
return [frame_state]
else:
return self.__unwind_stack_from([frame_state]) | sstjohn/thundergate | [
69,
10,
69,
2,
1430539071
] |
def __find_cfa_tbl_line_for(self, pc):
result = None
for entry in sorted(self._image._cfa_rule.keys(), reverse=True):
if pc >= entry and entry != 0:
result = self._image._cfa_rule[entry]
break
return result | sstjohn/thundergate | [
69,
10,
69,
2,
1430539071
] |
def _collect_scopes(self, frame):
loc = self._image.loc_at(frame["pc"])
func_name, cu_name, cu_line, source_dir = loc
scopes = []
if len(self._image._compile_units[cu_name]["variables"]) > 0:
global_scope = ScopeModel("global variables")
global_scope.children = self._collect_vars(self._image._compile_units[cu_name]["variables"], global_scope, frame)
global_scope.accessor = lambda x: x.evaluator()
scopes += [global_scope]
if func_name:
if len(self._image._compile_units[cu_name]["functions"][func_name]["args"]) > 0:
argument_scope = ScopeModel("function arguments")
argument_scope.children = self._collect_vars(self._image._compile_units[cu_name]["functions"][func_name]["args"], argument_scope, frame)
argument_scope.accessor = lambda x: x.evaluator()
scopes += [argument_scope]
if len(self._image._compile_units[cu_name]["functions"][func_name]["vars"]) > 0:
local_scope = ScopeModel("local variables")
local_scope.children = self._collect_vars(self._image._compile_units[cu_name]["functions"][func_name]["vars"], local_scope, frame)
local_scope.accessor = lambda x: x.evaluator()
scopes += [local_scope]
return scopes | sstjohn/thundergate | [
69,
10,
69,
2,
1430539071
] |
def _var_pp(v):
try: return "%x" % v
except: return str(v) | sstjohn/thundergate | [
69,
10,
69,
2,
1430539071
] |
def _cmd_scopes(self, cmd): | sstjohn/thundergate | [
69,
10,
69,
2,
1430539071
] |
def _cmd_variables(self, cmd):
members = self._vt.dereference(cmd["arguments"]["variablesReference"])
b = {}
b["variables"] = []
for child in members.children:
o = {}
try: o["name"] = child.display_name
except: o["name"] = child.name
if hasattr(child, "variablesReference"):
o["variablesReference"] = child.variablesReference
o["value"] = ""
else:
o["variablesReference"] = 0
data_value = child.scope.accessor(child)
try: o["value"] = "%x" % data_value
except: o["value"] = str(data_value)
b["variables"] += [o]
self._respond(cmd, True, body = b) | sstjohn/thundergate | [
69,
10,
69,
2,
1430539071
] |
def _log_write(self, data):
print data.strip()
sys.stdout.flush() | sstjohn/thundergate | [
69,
10,
69,
2,
1430539071
] |
def _event(self, event, body = None):
r = {}
r["type"] = "event"
r["seq"] = self._seq
self._seq += 1
r["event"] = event
if body is not None:
r["body"] = body
self.send(r) | sstjohn/thundergate | [
69,
10,
69,
2,
1430539071
] |
def __insn_repl(self, addr, replacement):
original_insn = struct.unpack("!I", self.dev.rxcpu.tr_read(addr, 1))[0]
self.dev.rxcpu.tr_write_dword(addr, replacement)
return original_insn
try:
self._breakpoints[addr] = original_insn
except:
self._breakpoints = {addr: original_insn} | sstjohn/thundergate | [
69,
10,
69,
2,
1430539071
] |
def _clear_breakpoint(self, filename, line_no = None):
try:
current_breakpoints = self._breakpoints[filename]
except:
return
if line_no is None:
lines = current_breakpoints.keys()
else:
lines = [line_no]
for line in lines:
line_addrs = current_breakpoints[line]
for addr in line_addrs:
self.__insn_repl(addr, self._bp_replaced_insn[addr])
del self._bp_replaced_insn[addr]
print "breakpoint cleared at \"%s+%d\" (%x)" % (filename, line, addr)
del self._breakpoints[filename][line] | sstjohn/thundergate | [
69,
10,
69,
2,
1430539071
] |
def send(self, resp):
r = json.dumps(resp, separators=(",",":"))
cl = len(r)
txt = "Content-Length: %d%s%s" % (cl, LINE_SEP + LINE_SEP, r) | sstjohn/thundergate | [
69,
10,
69,
2,
1430539071
] |
def recv(self):
h = self.data_in.readline()
content_length = int(h.split(" ")[1])
d = self.data_in.readline()
d = self.data_in.read(content_length)
self._log_write("rcvd: %s\n" % repr(d))
try:
j = json.loads(d)
except:
self._log_write("EXCEPTION!")
return j | sstjohn/thundergate | [
69,
10,
69,
2,
1430539071
] |
def __init__(self, cred, controller):
super(CredEntry, self).__init__()
self.cred = cred
self._controller = controller
self._code = Code('', 0, 0) | Yubico/yubioath-desktop-dpkg | [
6,
6,
6,
1,
1434464093
] |
def code(self):
return self._code | Yubico/yubioath-desktop-dpkg | [
6,
6,
6,
1,
1434464093
] |
def code(self, value):
self._code = value
self.changed.emit() | Yubico/yubioath-desktop-dpkg | [
6,
6,
6,
1,
1434464093
] |
def manual(self):
return self.cred.touch or self.cred.oath_type == TYPE_HOTP | Yubico/yubioath-desktop-dpkg | [
6,
6,
6,
1,
1434464093
] |
def cb(code):
if timer:
timer.stop()
dialog.accept()
if isinstance(code, Exception):
QtGui.QMessageBox.warning(window, m.error,
code.message)
else:
self.code = code | Yubico/yubioath-desktop-dpkg | [
6,
6,
6,
1,
1434464093
] |
def delete(self):
if self.cred.name in ['YubiKey slot 1', 'YubiKey slot 2']:
self._controller.delete_cred_legacy(int(self.cred.name[-1]))
else:
self._controller.delete_cred(self.cred.name) | Yubico/yubioath-desktop-dpkg | [
6,
6,
6,
1,
1434464093
] |
def names(creds):
return set(c.cred.name for c in creds) | Yubico/yubioath-desktop-dpkg | [
6,
6,
6,
1,
1434464093
] |
def __init__(self, interval):
super(Timer, self).__init__()
self._interval = interval
now = time()
rem = now % interval
self._time = int(now - rem)
QtCore.QTimer.singleShot((self._interval - rem) * 1000, self._tick) | Yubico/yubioath-desktop-dpkg | [
6,
6,
6,
1,
1434464093
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.