replace print function for python 3 (except osc)

Esse commit está contido em:
micuat
2017-06-18 22:21:59 +00:00
commit b1f96ea206
8 arquivos alterados com 50 adições e 47 exclusões
Arquivo normal → Arquivo executável
+3 -3
Ver Arquivo
@@ -36,12 +36,12 @@ class IPluginExtended(IPlugin):
# inherited from IPlugin
def activate(self):
print "Plugin %s activated." % (self.__class__.__name__)
print("Plugin %s activated." % (self.__class__.__name__))
# inherited from IPlugin
def deactivate(self):
print "Plugin %s deactivated." % (self.__class__.__name__)
print("Plugin %s deactivated." % (self.__class__.__name__))
# plugins that require arguments should implement this method
def show_help(self):
print "I, %s, do not need any parameter." % (self.__class__.__name__)
print("I, %s, do not need any parameter." % (self.__class__.__name__))
Arquivo normal → Arquivo executável
+4 -4
Ver Arquivo
@@ -23,22 +23,22 @@ class PluginCSVCollect(plugintypes.IPluginExtended):
self.verbose = True
self.file_name = self.file_name + '.csv'
print "Will export CSV to:", self.file_name
print("Will export CSV to:" + self.file_name)
#Open in append mode
with open(self.file_name, 'a') as f:
f.write('%'+self.time_stamp + '\n')
def deactivate(self):
print "Closing, CSV saved to:", self.file_name
print("Closing, CSV saved to:" + self.file_name)
return
def show_help(self):
print "Optional argument: [filename] (default: collect.csv)"
print("Optional argument: [filename] (default: collect.csv)")
def __call__(self, sample):
t = timeit.default_timer() - self.start_time
#print timeSinceStart|Sample Id
#print(timeSinceStart|Sample Id)
if self.verbose:
print("CSV: %f | %d" %(t,sample.id))
Arquivo normal → Arquivo executável
+2 -2
Ver Arquivo
@@ -35,6 +35,6 @@ class PluginNoiseTest(plugintypes.IPluginExtended):
def show_help(self):
print "Optional argument: polling_interval -- in seconds, default: 10. \n \
print ("Optional argument: polling_interval -- in seconds, default: 10. \n \
Returns the power of the system noise.\n \
NOTE: The reference and channel should have the same input signal."
NOTE: The reference and channel should have the same input signal.")
Arquivo normal → Arquivo executável
+6 -6
Ver Arquivo
@@ -2,7 +2,7 @@ import plugin_interface as plugintypes
class PluginPrint(plugintypes.IPluginExtended):
def activate(self):
print "Print activated"
print("Print activated")
# called with each new sample
def __call__(self, sample):
@@ -12,15 +12,15 @@ class PluginPrint(plugintypes.IPluginExtended):
sample_string = "ID: %f\n%s\n%s\n%s" %(sample.id, str(sample.channel_data)[1:-1], str(sample.aux_data)[1:-1], str(sample.imp_data)[1:-1])
else:
sample_string = "ID: %f\n%s\n%s" %(sample.id, str(sample.channel_data)[1:-1], str(sample.aux_data)[1:-1])
print "---------------------------------"
print sample_string
print "---------------------------------"
print("---------------------------------")
print(sample_string)
print("---------------------------------")
# DEBBUGING
# try:
# sample_string.decode('ascii')
# except UnicodeDecodeError:
# print "Not a ascii-encoded unicode string"
# print("Not a ascii-encoded unicode string")
# else:
# print sample_string
# print(sample_string)
Arquivo normal → Arquivo executável
+5 -5
Ver Arquivo
@@ -24,11 +24,11 @@ class Monitor(Thread):
new_tick = timeit.default_timer()
elapsed_time = new_tick - self.tick
current_samples_out = nb_samples_out
print "--- at t: ", (new_tick - self.start_tick), " ---"
print "elapsed_time: ", elapsed_time
print "nb_samples_out: ", current_samples_out - self.nb_samples_out
print("--- at t: " + str(new_tick - self.start_tick) + " ---")
print("elapsed_time: " + str(elapsed_time))
print("nb_samples_out: " + str(current_samples_out - self.nb_samples_out))
sampling_rate = (current_samples_out - self.nb_samples_out) / elapsed_time
print "sampling rate: ", sampling_rate
print("sampling rate: " + str(sampling_rate))
self.tick = new_tick
self.nb_samples_out = nb_samples_out
time.sleep(self.polling_interval)
@@ -49,4 +49,4 @@ class PluginSampleRate(plugintypes.IPluginExtended):
monit.start()
def show_help(self):
print "Optional argument: polling_interval -- in seconds, default: 10."
print("Optional argument: polling_interval -- in seconds, default: 10.")
Arquivo normal → Arquivo executável
+8 -5
Ver Arquivo
@@ -31,10 +31,12 @@ class StreamerLSL(plugintypes.IPluginExtended):
imp_id = self.args[5]
# Create a new streams info, one for EEG values, one for AUX (eg, accelerometer) values
print "Creating LSL stream for EEG. Name:", eeg_stream, "- ID:", eeg_id, "- data type: float32.", self.eeg_channels, "channels at", self.sample_rate, "Hz."
print("Creating LSL stream for EEG. Name:" + eeg_stream + "- ID:" + eeg_id +
"- data type: float32." + str(self.eeg_channels) + "channels at" + str(self.sample_rate) + "Hz.")
info_eeg = StreamInfo(eeg_stream, 'EEG', self.eeg_channels,self.sample_rate,'float32',eeg_id);
# NB: set float32 instead of int16 so as OpenViBE takes it into account
print "Creating LSL stream for AUX. Name:", aux_stream, "- ID:", aux_id, "- data type: float32.", self.aux_channels, "channels at", self.sample_rate, "Hz."
print("Creating LSL stream for AUX. Name:" + aux_stream + "- ID:" + aux_id +
"- data type: float32." + str(self.aux_channels) + "channels at" + str(self.sample_rate) + "Hz.")
info_aux = StreamInfo(aux_stream, 'AUX', self.aux_channels,self.sample_rate,'float32',aux_id);
# make outlets
@@ -42,7 +44,8 @@ class StreamerLSL(plugintypes.IPluginExtended):
self.outlet_aux = StreamOutlet(info_aux)
if self.imp_channels > 0:
print "Creating LSL stream for Impedance. Name:", imp_stream, "- ID:", imp_id, "- data type: float32.", self.imp_channels, "channels at", self.sample_rate, "Hz."
print("Creating LSL stream for Impedance. Name:" + imp_stream + "- ID:" + imp_id +
"- data type: float32." + str(self.imp_channels) + "channels at" + str(self.sample_rate) + "Hz.")
info_imp = StreamInfo(imp_stream, 'Impedance', self.imp_channels,self.sample_rate,'float32',imp_id);
self.outlet_imp = StreamOutlet(info_imp)
@@ -54,5 +57,5 @@ class StreamerLSL(plugintypes.IPluginExtended):
self.outlet_imp.push_sample(sample.imp_data)
def show_help(self):
print """Optional arguments: [EEG_stream_name [EEG_stream_ID [AUX_stream_name [AUX_stream_ID [Impedance_steam_name [Impedance_stream_ID]]]]]]
\t Defaults: "OpenBCI_EEG" / "openbci_eeg_id1" and "OpenBCI_AUX" / "openbci_aux_id1" / "OpenBCI_Impedance" / "openbci_imp_id1"."""
print("""Optional arguments: [EEG_stream_name [EEG_stream_ID [AUX_stream_name [AUX_stream_ID [Impedance_steam_name [Impedance_stream_ID]]]]]]
\t Defaults: "OpenBCI_EEG" / "openbci_eeg_id1" and "OpenBCI_AUX" / "openbci_aux_id1" / "OpenBCI_Impedance" / "openbci_imp_id1".""")
Arquivo normal → Arquivo executável
+7 -7
Ver Arquivo
@@ -51,7 +51,7 @@ class StreamerTCPServer(plugintypes.IPluginExtended):
self.port = int(self.args[1])
# init network
print "Selecting raw TCP streaming. IP: ", self.ip, ", port: ", self.port
print("Selecting raw TCP streaming. IP: " + self.ip + ", port: " + str(self.port))
self.initialize()
# init the daemon that monitors connections
@@ -69,7 +69,7 @@ class StreamerTCPServer(plugintypes.IPluginExtended):
# create connection
self.server_socket.bind((self.ip, self.port))
self.server_socket.listen(1)
print "Server started on port " + str(self.port)
print("Server started on port " + str(self.port))
# From Streamer, to be called each time we're willing to accept new connections
def check_connections(self):
@@ -79,7 +79,7 @@ class StreamerTCPServer(plugintypes.IPluginExtended):
# New connection
sockfd, addr = self.server_socket.accept()
self.CONNECTION_LIST.append(sockfd)
print "Client (%s, %s) connected" % addr
print("Client (%s, %s) connected" % addr)
# and... don't bother with incoming messages
# From IPlugin: close sockets, send message to client
@@ -117,16 +117,16 @@ class StreamerTCPServer(plugintypes.IPluginExtended):
# TODO: should check if the correct number of bytes passed through
except:
# sometimes (always?) it's only during the second write to a close socket that an error is raised?
print "Something bad happened, will close socket"
print("Something bad happened, will close socket")
outdated_list.append(sock)
# now we are outside of the main list, it's time to remove outdated sockets, if any
for bad_sock in outdated_list:
print "Removing socket..."
print("Removing socket...")
self.CONNECTION_LIST.remove(bad_sock)
# not very costly to be polite
bad_sock.close()
def show_help(self):
print """Optional arguments: [ip [port]]
print("""Optional arguments: [ip [port]]
\t ip: target IP address (default: 'localhost')
\t port: target port (default: 12345)"""
\t port: target port (default: 12345)""")
Arquivo normal → Arquivo executável
+14 -14
Ver Arquivo
@@ -16,30 +16,30 @@ import plugin_interface as plugintypes
# class PluginPrint(IPlugin):
# # args: passed by command line
# def activate(self, args):
# print "Print activated"
# print("Print activated")
# # tell outside world that init went good
# return True
# def deactivate(self):
# print "Print Deactivated"
# print("Print Deactivated")
# def show_help(self):
# print "I do not need any parameter, just printing stuff."
# print("I do not need any parameter, just printing stuff.")
# # called with each new sample
# def __call__(self, sample):
# sample_string = "ID: %f\n%s\n%s" %(sample.id, str(sample.channel_data)[1:-1], str(sample.aux_data)[1:-1])
# print "---------------------------------"
# print sample_string
# print "---------------------------------"
# print("---------------------------------")
# print(sample_string)
# print("---------------------------------")
# # DEBBUGING
# # try:
# # sample_string.decode('ascii')
# # except UnicodeDecodeError:
# # print "Not a ascii-encoded unicode string"
# # print("Not a ascii-encoded unicode string")
# # else:
# # print sample_string
# # print(sample_string)
class UDPServer(plugintypes.IPluginExtended):
@@ -49,8 +49,8 @@ class UDPServer(plugintypes.IPluginExtended):
self.server = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
def activate(self):
print "udp_server plugin"
print self.args
print("udp_server plugin")
print(self.args)
if len(self.args) > 0:
self.ip = self.args[0]
@@ -58,11 +58,11 @@ class UDPServer(plugintypes.IPluginExtended):
self.port = int(self.args[1])
# init network
print "Selecting raw UDP streaming. IP: ", self.ip, ", port: ", str(self.port)
print("Selecting raw UDP streaming. IP: " + self.ip + ", port: " + str(self.port))
self.server = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
print "Server started on port " + str(self.port)
print("Server started on port " + str(self.port))
def __call__(self, sample):
self.send_data(json.dumps(sample.channel_data))
@@ -75,6 +75,6 @@ class UDPServer(plugintypes.IPluginExtended):
self.server.close();
def show_help(self):
print """Optional arguments: [ip [port]]
print("""Optional arguments: [ip [port]]
\t ip: target IP address (default: 'localhost')
\t port: target port (default: 12345)"""
\t port: target port (default: 12345)""")