def readlink(path): ''' Return the path that a symlink points to This is only supported on Windows Vista or later. Inline with Unix behavior, this function will raise an error if the path is not a symlink, however, the error raised will be a SaltInvocationError, not an OSError. CLI Example: .. code-block:: bash salt '*' file.readlink /path/to/link ''' if sys.getwindowsversion().major < 6: raise SaltInvocationError( 'Symlinks are only supported on Windows Vista or later.') if not os.path.isabs(path): raise SaltInvocationError('Path to link must be absolute.') reparse_data = _get_reparse_data(path) if not reparse_data: raise SaltInvocationError( 'The path specified is not a reparse point (symlinks are a type of reparse point).' ) # REPARSE_DATA_BUFFER structure - see # http://msdn.microsoft.com/en-us/library/ff552012.aspx # parse the structure header to work out which type of reparse point this is header_parser = struct.Struct('L') ReparseTag, = header_parser.unpack(reparse_data[:header_parser.size]) # http://msdn.microsoft.com/en-us/library/windows/desktop/aa365511.aspx if not ReparseTag & 0xA000FFFF == 0xA000000C: raise SaltInvocationError( 'The path specified is not a symlink, but another type of reparse point (0x{0:X}).' .format(ReparseTag)) # parse as a symlink reparse point structure (the structure for other # reparse points is different) data_parser = struct.Struct('LHHHHHHL') ReparseTag, ReparseDataLength, Reserved, SubstituteNameOffset, \ SubstituteNameLength, PrintNameOffset, \ PrintNameLength, Flags = data_parser.unpack(reparse_data[:data_parser.size]) path_buffer_offset = data_parser.size absolute_substitute_name_offset = path_buffer_offset + SubstituteNameOffset target_bytes = reparse_data[ absolute_substitute_name_offset:absolute_substitute_name_offset + SubstituteNameLength] target = target_bytes.decode('UTF-16') if target.startswith('\\??\\'): target = target[4:] try: # comes out in 8.3 form; convert it to LFN to make it look nicer target = win32file.GetLongPathName(target) except pywinerror as exc: # if file is not found (i.e. bad symlink), return it anyway like on *nix if exc.winerror == 2: return target raise return target
def _get_struct_2id(): global _struct_2id if _struct_2id is None: _struct_2id = struct.Struct("<2id") return _struct_2id
def _get_struct_2f(): global _struct_2f if _struct_2f is None: _struct_2f = struct.Struct("<2f") return _struct_2f
def _get_struct_2I(): global _struct_2I if _struct_2I is None: _struct_2I = struct.Struct("<2I") return _struct_2I
def _get_struct_3I(): global _struct_3I if _struct_3I is None: _struct_3I = struct.Struct("<3I") return _struct_3I
def _get_struct_3d(): global _struct_3d if _struct_3d is None: _struct_3d = struct.Struct("<3d") return _struct_3d
def _get_fixed_size(cls): return struct.Struct(cls._get_fixed_format()).size
def deserialize_numpy(self, str, numpy): """ unpack serialized message in str into this message instance using numpy for array types :param str: byte array of serialized message, ``str`` :param numpy: numpy python module """ if python3: codecs.lookup_error("rosmsg").msg_type = self._type try: if self.action_goal is None: self.action_goal = msgs_demo.msg.GetMapActionGoal() if self.action_result is None: self.action_result = msgs_demo.msg.GetMapActionResult() if self.action_feedback is None: self.action_feedback = msgs_demo.msg.GetMapActionFeedback() end = 0 _x = self start = end end += 12 (_x.action_goal.header.seq, _x.action_goal.header.stamp.secs, _x.action_goal.header.stamp.nsecs,) = _get_struct_3I().unpack(str[start:end]) start = end end += 4 (length,) = _struct_I.unpack(str[start:end]) start = end end += length if python3: self.action_goal.header.frame_id = str[start:end].decode('utf-8', 'rosmsg') else: self.action_goal.header.frame_id = str[start:end] _x = self start = end end += 8 (_x.action_goal.goal_id.stamp.secs, _x.action_goal.goal_id.stamp.nsecs,) = _get_struct_2I().unpack(str[start:end]) start = end end += 4 (length,) = _struct_I.unpack(str[start:end]) start = end end += length if python3: self.action_goal.goal_id.id = str[start:end].decode('utf-8', 'rosmsg') else: self.action_goal.goal_id.id = str[start:end] _x = self start = end end += 12 (_x.action_result.header.seq, _x.action_result.header.stamp.secs, _x.action_result.header.stamp.nsecs,) = _get_struct_3I().unpack(str[start:end]) start = end end += 4 (length,) = _struct_I.unpack(str[start:end]) start = end end += length if python3: self.action_result.header.frame_id = str[start:end].decode('utf-8', 'rosmsg') else: self.action_result.header.frame_id = str[start:end] _x = self start = end end += 8 (_x.action_result.status.goal_id.stamp.secs, _x.action_result.status.goal_id.stamp.nsecs,) = _get_struct_2I().unpack(str[start:end]) start = end end += 4 (length,) = _struct_I.unpack(str[start:end]) start = end end += length if python3: self.action_result.status.goal_id.id = str[start:end].decode('utf-8', 'rosmsg') else: self.action_result.status.goal_id.id = str[start:end] start = end end += 1 (self.action_result.status.status,) = _get_struct_B().unpack(str[start:end]) start = end end += 4 (length,) = _struct_I.unpack(str[start:end]) start = end end += length if python3: self.action_result.status.text = str[start:end].decode('utf-8', 'rosmsg') else: self.action_result.status.text = str[start:end] _x = self start = end end += 12 (_x.action_result.result.map.header.seq, _x.action_result.result.map.header.stamp.secs, _x.action_result.result.map.header.stamp.nsecs,) = _get_struct_3I().unpack(str[start:end]) start = end end += 4 (length,) = _struct_I.unpack(str[start:end]) start = end end += length if python3: self.action_result.result.map.header.frame_id = str[start:end].decode('utf-8', 'rosmsg') else: self.action_result.result.map.header.frame_id = str[start:end] _x = self start = end end += 76 (_x.action_result.result.map.info.map_load_time.secs, _x.action_result.result.map.info.map_load_time.nsecs, _x.action_result.result.map.info.resolution, _x.action_result.result.map.info.width, _x.action_result.result.map.info.height, _x.action_result.result.map.info.origin.position.x, _x.action_result.result.map.info.origin.position.y, _x.action_result.result.map.info.origin.position.z, _x.action_result.result.map.info.origin.orientation.x, _x.action_result.result.map.info.origin.orientation.y, _x.action_result.result.map.info.origin.orientation.z, _x.action_result.result.map.info.origin.orientation.w,) = _get_struct_2If2I7d().unpack(str[start:end]) start = end end += 4 (length,) = _struct_I.unpack(str[start:end]) pattern = '<%sb'%length start = end s = struct.Struct(pattern) end += s.size self.action_result.result.map.data = numpy.frombuffer(str[start:end], dtype=numpy.int8, count=length) _x = self start = end end += 12 (_x.action_feedback.header.seq, _x.action_feedback.header.stamp.secs, _x.action_feedback.header.stamp.nsecs,) = _get_struct_3I().unpack(str[start:end]) start = end end += 4 (length,) = _struct_I.unpack(str[start:end]) start = end end += length if python3: self.action_feedback.header.frame_id = str[start:end].decode('utf-8', 'rosmsg') else: self.action_feedback.header.frame_id = str[start:end] _x = self start = end end += 8 (_x.action_feedback.status.goal_id.stamp.secs, _x.action_feedback.status.goal_id.stamp.nsecs,) = _get_struct_2I().unpack(str[start:end]) start = end end += 4 (length,) = _struct_I.unpack(str[start:end]) start = end end += length if python3: self.action_feedback.status.goal_id.id = str[start:end].decode('utf-8', 'rosmsg') else: self.action_feedback.status.goal_id.id = str[start:end] start = end end += 1 (self.action_feedback.status.status,) = _get_struct_B().unpack(str[start:end]) start = end end += 4 (length,) = _struct_I.unpack(str[start:end]) start = end end += length if python3: self.action_feedback.status.text = str[start:end].decode('utf-8', 'rosmsg') else: self.action_feedback.status.text = str[start:end] return self except struct.error as e: raise genpy.DeserializationError(e) # most likely buffer underfill
def _get_struct_2If2I7d(): global _struct_2If2I7d if _struct_2If2I7d is None: _struct_2If2I7d = struct.Struct("<2If2I7d") return _struct_2If2I7d
start = end end += 4 (length,) = _struct_I.unpack(str[start:end]) start = end end += length if python3: val1.label = str[start:end].decode('utf-8') else: val1.label = str[start:end] _x = val1 start = end end += 8 (_x.size, _x.stride,) = _struct_2I.unpack(str[start:end]) self.layout.dim.append(val1) start = end end += 4 (self.layout.data_offset,) = _struct_I.unpack(str[start:end]) start = end end += 4 (length,) = _struct_I.unpack(str[start:end]) pattern = '<%sb'%length start = end end += struct.calcsize(pattern) self.data = numpy.frombuffer(str[start:end], dtype=numpy.int8, count=length) return self except struct.error as e: raise genpy.DeserializationError(e) #most likely buffer underfill _struct_I = genpy.struct_I _struct_2I = struct.Struct("<2I")
def serialize_numpy(self, buff, numpy): """ serialize message with numpy array types into buffer :param buff: buffer, ``StringIO`` :param numpy: numpy python module """ try: _x = self buff.write(_get_struct_3I().pack(_x.action_goal.header.seq, _x.action_goal.header.stamp.secs, _x.action_goal.header.stamp.nsecs)) _x = self.action_goal.header.frame_id length = len(_x) if python3 or type(_x) == unicode: _x = _x.encode('utf-8') length = len(_x) buff.write(struct.Struct('<I%ss'%length).pack(length, _x)) _x = self buff.write(_get_struct_2I().pack(_x.action_goal.goal_id.stamp.secs, _x.action_goal.goal_id.stamp.nsecs)) _x = self.action_goal.goal_id.id length = len(_x) if python3 or type(_x) == unicode: _x = _x.encode('utf-8') length = len(_x) buff.write(struct.Struct('<I%ss'%length).pack(length, _x)) _x = self buff.write(_get_struct_3I().pack(_x.action_result.header.seq, _x.action_result.header.stamp.secs, _x.action_result.header.stamp.nsecs)) _x = self.action_result.header.frame_id length = len(_x) if python3 or type(_x) == unicode: _x = _x.encode('utf-8') length = len(_x) buff.write(struct.Struct('<I%ss'%length).pack(length, _x)) _x = self buff.write(_get_struct_2I().pack(_x.action_result.status.goal_id.stamp.secs, _x.action_result.status.goal_id.stamp.nsecs)) _x = self.action_result.status.goal_id.id length = len(_x) if python3 or type(_x) == unicode: _x = _x.encode('utf-8') length = len(_x) buff.write(struct.Struct('<I%ss'%length).pack(length, _x)) _x = self.action_result.status.status buff.write(_get_struct_B().pack(_x)) _x = self.action_result.status.text length = len(_x) if python3 or type(_x) == unicode: _x = _x.encode('utf-8') length = len(_x) buff.write(struct.Struct('<I%ss'%length).pack(length, _x)) _x = self buff.write(_get_struct_3I().pack(_x.action_result.result.map.header.seq, _x.action_result.result.map.header.stamp.secs, _x.action_result.result.map.header.stamp.nsecs)) _x = self.action_result.result.map.header.frame_id length = len(_x) if python3 or type(_x) == unicode: _x = _x.encode('utf-8') length = len(_x) buff.write(struct.Struct('<I%ss'%length).pack(length, _x)) _x = self buff.write(_get_struct_2If2I7d().pack(_x.action_result.result.map.info.map_load_time.secs, _x.action_result.result.map.info.map_load_time.nsecs, _x.action_result.result.map.info.resolution, _x.action_result.result.map.info.width, _x.action_result.result.map.info.height, _x.action_result.result.map.info.origin.position.x, _x.action_result.result.map.info.origin.position.y, _x.action_result.result.map.info.origin.position.z, _x.action_result.result.map.info.origin.orientation.x, _x.action_result.result.map.info.origin.orientation.y, _x.action_result.result.map.info.origin.orientation.z, _x.action_result.result.map.info.origin.orientation.w)) length = len(self.action_result.result.map.data) buff.write(_struct_I.pack(length)) pattern = '<%sb'%length buff.write(self.action_result.result.map.data.tostring()) _x = self buff.write(_get_struct_3I().pack(_x.action_feedback.header.seq, _x.action_feedback.header.stamp.secs, _x.action_feedback.header.stamp.nsecs)) _x = self.action_feedback.header.frame_id length = len(_x) if python3 or type(_x) == unicode: _x = _x.encode('utf-8') length = len(_x) buff.write(struct.Struct('<I%ss'%length).pack(length, _x)) _x = self buff.write(_get_struct_2I().pack(_x.action_feedback.status.goal_id.stamp.secs, _x.action_feedback.status.goal_id.stamp.nsecs)) _x = self.action_feedback.status.goal_id.id length = len(_x) if python3 or type(_x) == unicode: _x = _x.encode('utf-8') length = len(_x) buff.write(struct.Struct('<I%ss'%length).pack(length, _x)) _x = self.action_feedback.status.status buff.write(_get_struct_B().pack(_x)) _x = self.action_feedback.status.text length = len(_x) if python3 or type(_x) == unicode: _x = _x.encode('utf-8') length = len(_x) buff.write(struct.Struct('<I%ss'%length).pack(length, _x)) except struct.error as se: self._check_types(struct.error("%s: '%s' when writing '%s'" % (type(se), str(se), str(locals().get('_x', self))))) except TypeError as te: self._check_types(ValueError("%s: '%s' when writing '%s'" % (type(te), str(te), str(locals().get('_x', self)))))
start = end end += 4 (length,) = _struct_I.unpack(str[start:end]) pattern = '<%sd'%length start = end end += struct.calcsize(pattern) self.action_feedback.feedback.state.position = numpy.frombuffer(str[start:end], dtype=numpy.float64, count=length) start = end end += 4 (length,) = _struct_I.unpack(str[start:end]) pattern = '<%sd'%length start = end end += struct.calcsize(pattern) self.action_feedback.feedback.state.velocity = numpy.frombuffer(str[start:end], dtype=numpy.float64, count=length) start = end end += 4 (length,) = _struct_I.unpack(str[start:end]) pattern = '<%sd'%length start = end end += struct.calcsize(pattern) self.action_feedback.feedback.state.effort = numpy.frombuffer(str[start:end], dtype=numpy.float64, count=length) return self except struct.error as e: raise genpy.DeserializationError(e) #most likely buffer underfill _struct_I = genpy.struct_I _struct_3I = struct.Struct("<3I") _struct_B = struct.Struct("<B") _struct_2f3I = struct.Struct("<2f3I") _struct_2I = struct.Struct("<2I")
class WheelieSerial(Node): # <msgID><msgType><int1><int2><checksum> msg = struct.Struct("I B i i I") # <msgID><msgType><int1><int2><int3><checksum> incoming_msg = struct.Struct("I B i i i I") def __init__(self): super().__init__('wheelie_serial_node') self.subscription = self.create_subscription(String, 'topic', self.listener_callback, 10) self.imu_publisher = self.create_publisher(Imu, '~/imu_out', 20) self.imu_msg = Imu() imu_timer_period = 0.1 # seconds self.imu_timer = self.create_timer(imu_timer_period, self.imu_timer_callback) self.srv = self.create_service(SetBool, '~/set_motors_enabled', self.set_motors_enabled_callback) self.twist_sub = self.create_subscription(TwistStamped, '~/twist_target', self.twist_callback, 10) self.last_twist_time = 0 self.movement_timeout = 0.5 # seconds self.movement_enabled = False self.movement_timer = self.create_timer(self.movement_timeout, self.movement_timer_callback) ser_ports = [p.device for p in serial.tools.list_ports.comports()] if not ser_ports: self.get_logger().error("No serial port found. Exiting") sys.exit(1) self.get_logger().info(f"Found serial ports: {', '.join(ser_ports)}") if "/dev/cu.usbmodem14101" in ser_ports: ser_ports[0] = "/dev/cu.usbmodem14101" self.get_logger().info(f"Using {ser_ports[0]}") ser = serial.Serial(ser_ports[0], baudrate=115200, timeout=1) packetizer = WheelieSerialPacketizer(self.incoming_serial_handler, self.get_logger()) self.serial_thread = serial.threaded.ReaderThread(ser, packetizer) self.serial_thread.start() self.transport, self.protocol = self.serial_thread.connect() def imu_timer_callback(self): self.imu_publisher.publish(self.imu_msg) def movement_timer_callback(self): if time.time() - self.last_twist_time > 0.5: self.movement_enabled = False @staticmethod def bytes_checksum(b): sum = 0 for byte in b: sum += int(byte) return sum @staticmethod def int_to_float(i): return i / 1000 @staticmethod def float_to_int(f): return int(f * 1000) def incoming_serial_handler(self, packet): if len(packet) != 24: self.get_logger().error( f"Received message with incorrect length {len(packet)}. Ignoring." ) return msg_id, msg_type, int1, int2, int3, check = self.incoming_msg.unpack( packet) # self.get_logger().info(f"Received message: {msg_id} {msg_type} {int1} {int2} {int3} {check}") calced_checksum = self.bytes_checksum( self.incoming_msg.pack(msg_id, msg_type, int1, int2, int3, 0)) if check != calced_checksum: self.get_logger().error( f"Incorrect checksum {calced_checksum} != {check}. Ignoring message" ) return if msg_type == 0: # Acceleration values self.imu_msg.linear_acceleration.x, self.imu_msg.linear_acceleration.y, \ self.imu_msg.linear_acceleration.z = \ self.int_to_float(int1), self.int_to_float(int2), self.int_to_float(int3) def send_serial_bytes(self, b): b += WheelieSerialPacketizer.TERMINATOR self.get_logger().debug(f'Sending: {b}') self.transport.write(b) @staticmethod def generate_id(): return random.getrandbits(32) def format_serial_message(self, msg_id, msg_type, int1=0, int2=0): chk = self.bytes_checksum( self.msg.pack(msg_id, msg_type, int1, int2, 0)) full_msg = self.msg.pack(msg_id, msg_type, int1, int2, chk) return full_msg def set_motors_enabled_callback(self, request, response): enabled = bool(request.data) self.movement_enabled = enabled self.get_logger().info( f'Movement is now {"enabled" if enabled else "disabled"}.') self.send_serial_bytes( self.format_serial_message(self.generate_id(), SerialSendMessageType.SET_POWER, int(enabled))) # TODO wait for ACK before sending response response.success = True response.message = "" return response @staticmethod def scale_float(f: float) -> int: return int(30 * f) def twist_callback(self, msg): if self.movement_enabled: self.last_twist_time = time.time() self.send_serial_bytes( self.format_serial_message( self.generate_id(), SerialSendMessageType.SET_VELOCITY, self.scale_float(msg.twist.linear.x), self.scale_float(msg.twist.angular.z))) else: self.send_serial_bytes( self.format_serial_message(self.generate_id(), SerialSendMessageType.SET_VELOCITY, 0, 0)) self.get_logger().warn( 'Twist target received, but movement not enabled currently.') def listener_callback(self, msg): self.get_logger().info('I heard: "%s"' % msg.data)
def _get_struct_f6B(): global _struct_f6B if _struct_f6B is None: _struct_f6B = struct.Struct("<f6B") return _struct_f6B
def configureHeader(self, flags, seq_no, ack_no, payload_len): global recv_socket, sock352PktHdrData, other_host_addr packet_header = struct.Struct(sock352PktHdrData) return packet_header.pack(version, flags, 0x0, 0x0, header_length, 0x0, 0x0, 0x0, seq_no, ack_no, 0x0, payload_len)
_x.y, _x.z, ) = _struct_3d.unpack(str[start:end]) _v24 = val1.angular _x = _v24 start = end end += 24 ( _x.x, _x.y, _x.z, ) = _struct_3d.unpack(str[start:end]) self.accelerations.append(val1) _x = self start = end end += 8 ( _x.time_from_start.secs, _x.time_from_start.nsecs, ) = _struct_2i.unpack(str[start:end]) self.time_from_start.canon() return self except struct.error as e: raise genpy.DeserializationError(e) #most likely buffer underfill _struct_I = genpy.struct_I _struct_4d = struct.Struct("<4d") _struct_2i = struct.Struct("<2i") _struct_3d = struct.Struct("<3d")
offset = 0 offset += self.header.deserialize(buff[offset:]) offset += self.twist.deserialize(buff[offset:]) return offset def serializedLength(self): length = 0 length += self.header.serializedLength() length += self.twist.serializedLength() return length def echo(self): string_echo = '{' string_echo += '"header": {"' string_echo += self.header.echo() string_echo += '}, ' string_echo += '"twist": {"' string_echo += self.twist.echo() string_echo += '}' string_echo += '}' return string_echo def getType(self): return "geometry_msgs/TwistStamped" def getMD5(self): return "2e3e0a57a69306091cb5c65e92d048e1" _struct_I = struct.Struct('<I')
def _get_struct_3f(): global _struct_3f if _struct_3f is None: _struct_3f = struct.Struct("<3f") return _struct_3f
@author: Aisha Ali-Gombe @contact: [email protected], [email protected] """ #!/usr/bin/python import artParse as art import art_types as types import artClass as cls import artField as fld import artDex as dx import artThread as threadlist import sys, os, subprocess, struct,binascii from collections import OrderedDict from collections import Counter unpack_int = struct.Struct('<I').unpack unpack_dec = struct.Struct('<i').unpack unpack_b = struct.Struct('<B').unpack #Byte or Bool unpack_char = struct.Struct('<c').unpack unpack_short = struct.Struct('<H').unpack unpack_float = struct.Struct('<f').unpack unpack_long = struct.Struct('<Q').unpack unpack_double = struct.Struct('<d').unpack #Dump Libs artJVM.py path -g -data if os.path.isdir(sys.argv[1]): path = sys.argv[1] else: path = sys.argv[2] #art.path = path [nPath, rAddr, memList, mapList, listing, lstList,runtime]=art.main(path)
def _get_struct_f(): global _struct_f if _struct_f is None: _struct_f = struct.Struct("<f") return _struct_f
def _get_struct_B(): global _struct_B if _struct_B is None: _struct_B = struct.Struct("<B") return _struct_B
def _get_struct_4d(): global _struct_4d if _struct_4d is None: _struct_4d = struct.Struct("<4d") return _struct_4d
""" try: buff.write(_struct_B.pack(self.type)) except struct.error as se: self._check_types( struct.error("%s: '%s' when writing '%s'" % (type(se), str(se), str(_x)))) except TypeError as te: self._check_types( ValueError("%s: '%s' when writing '%s'" % (type(te), str(te), str(_x)))) def deserialize_numpy(self, str, numpy): """ unpack serialized message in str into this message instance using numpy for array types :param str: byte array of serialized message, ``str`` :param numpy: numpy python module """ try: end = 0 start = end end += 1 (self.type, ) = _struct_B.unpack(str[start:end]) return self except struct.error as e: raise genpy.DeserializationError(e) #most likely buffer underfill _struct_I = genpy.struct_I _struct_B = struct.Struct("<B")
def read_stations(limit, start_year, uk=False, germany=True, canada=True): """ Process the ISD history file Select stations which have defined lat, lon and elevation; at least N years of data (using start/end dates). Also do additional processing for Canadian (71*) and German (09* and 10*) stations. :param int limit: number of years of data required :param int start_year: year of data start :param bool uk: only run for stations starting 03* :param bool germany: do extra selection for 09* and 10* stations :param bool canada: do extra selection and processing for 71* stations :returns: list of selected station objects """ fieldwidths = (7, 6, 30, 5, 3, 5, 8, 9, 8, 9, 9) fmtstring = ''.join('%ds' % f for f in fieldwidths) parse = struct.Struct(fmtstring).unpack_from all_stations = [] try: with open(INPUT_FILE_LOCS + ISD_LISTING, 'r') as infile: lc = 0 for line in infile: lc += 1 if lc <= 22: continue fields = parse(line) # unpack st_id = fields[0].strip() + '-' + fields[1].strip() name = fields[2].rstrip() country = fields[3].strip() state = fields[4].strip() call = fields[5].strip() lat = fields[6].strip() lon = fields[7].strip() elev = fields[8].strip() start = dt.datetime.strptime(fields[9].strip(), "%Y%m%d").date() end = dt.datetime.strptime(fields[10].strip(), "%Y%m%d").date() if uk: if st_id[:2] != "03": continue # need to have lat, lon and elev and the elev defined if lat != "" and lon != "" and elev != "" and float( elev) != -999.9: # test if elevation is known (above Dead-Sea shore in Jordan at -423m) if float(elev) > -430.0: # create station object station = Station(st_id, float(lat), float(lon), float(elev)) station.name = name station.state = state station.call = call station.start = start station.end = end station.mergers = [] all_stations += [station] except OSError: print "{:s} does not exist. Check download".format(isd_listing) raise OSError print "{} stations in full ISD".format(lc) # go through German stations and pick out those which match in last 4 places of ID if germany: all_stations = process_germany(all_stations) candidate_stations = [] # go through Canadian stations to check for undocumented moves/mergers if canada: s_canada.process_EC_file() all_stations = s_canada.process_canadian_stations( all_stations, start_year) for station in all_stations: # need to have sufficient number of years of data if station.end.year - station.start.year >= limit: # store in list candidate_stations += [station] print "{} candidate stations (lat/lon/elev and timespan limits)".format( len(candidate_stations)) return all_stations, candidate_stations # read_stations
def _get_struct_6d(): global _struct_6d if _struct_6d is None: _struct_6d = struct.Struct("<6d") return _struct_6d
def _get_struct_3d2B(): global _struct_3d2B if _struct_3d2B is None: _struct_3d2B = struct.Struct("<3d2B") return _struct_3d2B
def _get_struct_i(): global _struct_i if _struct_i is None: _struct_i = struct.Struct("<i") return _struct_i
#!/usr/bin/env python import struct import unittest import utils from vtdb import dbexceptions from vtdb import keyspace from vtdb import keyrange from vtdb import keyrange_constants from vtdb import vtrouting # This unittest tests the computation of task map # and where clauses for streaming queries. pkid_pack = struct.Struct('!Q').pack int_shard_kid_map = { '-10': [1, 100, 1000, 100000, 527875958493693904, 626750931627689502, 345387386794260318, 332484755310826578], '10-20': [1842642426274125671, 1326307661227634652, 1761124146422844620, 1661669973250483744], '20-30': [3361397649937244239, 3303511690915522723, 2444880764308344533, 2973657788686139039], '30-40': [3821005920507858605, 4575089859165626432, 3607090456016432961, 3979558375123453425], '40-50': [5129057445097465905, 5464969577815708398, 5190676584475132364, 5762096070688827561], '50-60': [6419540613918919447, 6867152356089593986, 6601838130703675400, 6132605084892127391], '60-70': [7251511061270371980, 7395364497868053835, 7814586147633440734, 7968977924086033834],
""" unpack serialized message in str into this message instance using numpy for array types :param str: byte array of serialized message, ``str`` :param numpy: numpy python module """ try: end = 0 _x = self start = end end += 61 ( _x.auto_disable_bodies, _x.sor_pgs_precon_iters, _x.sor_pgs_iters, _x.sor_pgs_w, _x.sor_pgs_rms_error_tol, _x.contact_surface_layer, _x.contact_max_correcting_vel, _x.cfm, _x.erp, _x.max_contacts, ) = _struct_B2I6dI.unpack(str[start:end]) self.auto_disable_bodies = bool(self.auto_disable_bodies) return self except struct.error as e: raise genpy.DeserializationError(e) #most likely buffer underfill _struct_I = genpy.struct_I _struct_B2I6dI = struct.Struct("<B2I6dI")
end += 12 ( _x.header.seq, _x.header.stamp.secs, _x.header.stamp.nsecs, ) = _struct_3I.unpack(str[start:end]) start = end end += 4 (length, ) = _struct_I.unpack(str[start:end]) start = end end += length if python3: self.header.frame_id = str[start:end].decode('utf-8') else: self.header.frame_id = str[start:end] _x = self start = end end += 16 ( _x.point.x, _x.point.y, ) = _struct_2d.unpack(str[start:end]) return self except struct.error as e: raise genpy.DeserializationError(e) #most likely buffer underfill _struct_I = genpy.struct_I _struct_2d = struct.Struct("<2d") _struct_3I = struct.Struct("<3I")