Skip to content

Commit

Permalink
Merge pull request #14 from cdberkstresser/goodness-from-other-prs
Browse files Browse the repository at this point in the history
Goodness from other PRs + Fixes
  • Loading branch information
cdberkstresser authored May 1, 2020
2 parents 166173f + a87fcb3 commit 6f370a3
Show file tree
Hide file tree
Showing 12 changed files with 124 additions and 145 deletions.
6 changes: 3 additions & 3 deletions FAHControl
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ def set_proc_name(name):

libc = cdll.LoadLibrary('libc.so.6')
buff = create_string_buffer(len(name)+1)
buff.value = bytes(name,encoding="UTF8")
buff.value = name
libc.prctl(15, byref(buff), 0, 0, 0)


if sys.platform.startswith('linux'): set_proc_name('FAHControl')
if sys.platform.startswith('linux'): set_proc_name(b'FAHControl')

# If present, remove the Launch Services -psn_xxx_xxx argument
if len(sys.argv) > 1 and sys.argv[1][:4] == '-psn':
Expand All @@ -53,7 +53,7 @@ if options.exit:
try:
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect(single_app_addr)
sock.send('EXIT')
sock.send(b'EXIT')
if sock.recv(1024).strip() == 'OK': print ('Ok')
except Exception as e:
pass
Expand Down
6 changes: 3 additions & 3 deletions SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import os
env = Environment(ENV = os.environ)
try:
env.Tool('config', toolpath = [os.environ.get('CBANG_HOME')])
except Exception, e:
raise Exception, 'CBANG_HOME not set?\n' + str(e)
except Exception as e:
raise Exception('CBANG_HOME not set?\n' + str(e))

env.CBLoadTools('packager run_distutils osx fah-client-version')
env.CBAddVariables(
Expand All @@ -14,7 +14,7 @@ conf = env.CBConfigure()
# Version
try:
version = env.FAHClientVersion()
except Exception, e:
except Exception as e:
print(e)
version = '0.0.0'
env.Replace(PACKAGE_VERSION = version)
Expand Down
4 changes: 2 additions & 2 deletions fah/Client.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def __init__(self, app, name, address, port, password):

# Option names
names = list(app.client_option_widgets.keys())
self.option_names = [name.replace('_', '-') for name in names]
self.option_names = list(map(lambda name: name.replace('_', '-'), names))
self.option_names.append('power') # Folding power

# Init commands
Expand Down Expand Up @@ -301,7 +301,7 @@ def process_error(self, app, data):
self.name, self.address, self.port, data)

# Only popup dialog once for each error
if not msg in self.error_messages:
if msg not in self.error_messages:
self.error_messages.add(msg)
app.error(msg)

Expand Down
10 changes: 5 additions & 5 deletions fah/ClientConfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,11 +318,11 @@ def update_info(self, app):
category = category[1:]

# Frame
#frame = Gtk.Frame('<b>%s</b>' % name)
frame = Gtk.Frame()
frame.name = name
frame = Gtk.Frame.new('<b>%s</b>' % name)
frame.set_shadow_type(Gtk.ShadowType.ETCHED_IN)
vbox.pack_start(frame, False, True, 0)
frame.set_label_align(0.01, 0.5)
frame.get_label_widget().set_use_markup(True)
vbox.pack_start(frame, False, False, 0)

# Alignment
align = Gtk.Alignment.new(0, 0, 1, 1)
Expand Down Expand Up @@ -649,7 +649,7 @@ def check_option(model, path, iter, data):

# Removed options
for name in self.options:
if not name in used:
if name not in used:
options[name + '!'] = None

return options
Expand Down
26 changes: 10 additions & 16 deletions fah/Connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,11 @@ def open(self):
self.last_connect = time.time()

self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.socket.setblocking(0)
self.socket.setblocking(False)
ready = select.select([self.socket], [self.socket], [], 10)
if ready[0]:
err = self.socket.connect_ex((self.address, self.port))
if err != 0 and err != 115 and not err in [
if err != 0 and err != 115 and err not in [
errno.EINPROGRESS, errno.EWOULDBLOCK, WSAEWOULDBLOCK]:
self.fail_reason = 'connect'
raise Exception('Connection failed: ' + errno.errorcode[err])
Expand Down Expand Up @@ -160,14 +160,11 @@ def read_some(self):
self.connection_lost()
return 0

except socket.error as xxx_todo_changeme:
except socket.error as err:
# Error codes for nothing to read
(err, msg) = xxx_todo_changeme.args
# Error codes for nothing to read
if err not in [errno.EAGAIN, errno.EWOULDBLOCK, WSAEWOULDBLOCK]:
if bytesRead:
return bytesRead
self.connection_error(err, msg)
if err.errno not in [errno.EAGAIN, errno.EWOULDBLOCK, WSAEWOULDBLOCK]:
if bytesRead: return bytesRead
self.connection_error(err.errno, err.strerror)
raise

return bytesRead
Expand All @@ -189,14 +186,11 @@ def write_some(self):
self.connection_lost()
return 0

except socket.error as xxx_todo_changeme1:
# Error codes for write buffer full
(err, msg) = xxx_todo_changeme1.args
except socket.error as err:
# Error codes for write buffer full
if err not in [errno.EAGAIN, errno.EWOULDBLOCK, WSAEWOULDBLOCK]:
if bytesWritten:
return bytesWritten
self.connection_error(err, msg)
if err.errno not in [errno.EAGAIN, errno.EWOULDBLOCK, WSAEWOULDBLOCK]:
if bytesWritten: return bytesWritten
self.connection_error(err.errno, err.strerror)
raise

return bytesWritten
Expand Down
Loading

0 comments on commit 6f370a3

Please sign in to comment.