/usr/share/pyshared/neuroshare/File.py is in python-neuroshare 0.8.5-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 | from Library import *
from Entity import *
from EventEntity import *
from AnalogEntity import *
from SegmentEntity import *
from NeuralEntity import *
class EntityProxy(object):
def __init__(self, nsfile):
self._nsfile = nsfile
def __getitem__(self, key):
return self._nsfile.get_entity(key)
def __iter__(self):
for x in xrange (0, self._nsfile.entity_count):
yield self[x]
def __len__(self):
return self._nsfile.entity_count
class File(object):
def __init__(self, filename, library=None):
self._handle = None
self._filename = filename
if not library:
library = load_library_for_file (filename)
self._lib = library
(handle, info) = self._lib._open_file (filename)
self._handle = handle
self._info = info
self._eproxy = EntityProxy(self)
def __del__(self):
self.close ()
def close(self):
if self._handle:
self._lib._close_file (self)
self._handle = None
@property
def library(self):
return self._lib
@property
def file_type(self):
pass
@property
def metadata_raw(self):
return self._info
@property
def app_name(self):
return self._info['AppName']
@property
def comment(self):
return self._info['FileComment']
@property
def entity_count(self):
return self._info['EntityCount']
@property
def time_span(self):
return self._info['TimeSpan']
@property
def time_stamp_resolution(self):
return self.info['TimeStampResolution']
@property
def ctime(self):
from datetime import datetime
year = self._info['Time_Year']
month = self._info['Time_Month']
day = self._info['Time_Day']
hour = self._info['Time_Hour']
minute = self._info['Time_Min']
sec = self._info['Time_Sec']
millisec = self._info['Time_MilliSec']
msec = millisec * 1000
ct = datetime (year, month, day, hour, minute, sec, msec)
return ct
def get_entity(self, entity_id):
info = self._lib._get_entity_info (self, entity_id)
entity_type = info['EntityType']
if entity_type == EntityType.Event:
entity = EventEntity(self, entity_id, info)
elif entity_type == EntityType.Analog:
entity = AnalogEntity(self, entity_id, info)
elif entity_type == EntityType.Segment:
entity = SegmentEntity(self, entity_id, info)
elif entity_type == EntityType.Neural:
entity = NeuralEntity(self, entity_id, info)
else:
return None #should not happen, throw exception?
return entity
def list_entities(self, start=0, end=-1):
if end == -1:
end = self.entity_count
for x in xrange (start, end):
yield self.get_entity(x)
@property
def entities(self):
return self._eproxy
@property
def _get_handle(self):
return self._handle
def __repr__(self):
return 'neuroshare.File(%r)' % (self._filename)
|