зеркало из https://github.com/nextcloud/desktop.git
Fix minor Python styling issues
* Do not use sapces inside parenthesis * make indend PEP8 * empty lines should not contain whitespaces
This commit is contained in:
Родитель
7618f29657
Коммит
ddfc7c75df
|
@ -7,7 +7,7 @@ import socket
|
||||||
from gi.repository import GObject, Nautilus
|
from gi.repository import GObject, Nautilus
|
||||||
|
|
||||||
class ownCloudExtension(GObject.GObject, Nautilus.ColumnProvider, Nautilus.InfoProvider):
|
class ownCloudExtension(GObject.GObject, Nautilus.ColumnProvider, Nautilus.InfoProvider):
|
||||||
|
|
||||||
nautilusVFSFile_table = {}
|
nautilusVFSFile_table = {}
|
||||||
registered_paths = {}
|
registered_paths = {}
|
||||||
remainder = ''
|
remainder = ''
|
||||||
|
@ -17,36 +17,35 @@ class ownCloudExtension(GObject.GObject, Nautilus.ColumnProvider, Nautilus.InfoP
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.connectToOwnCloud
|
self.connectToOwnCloud
|
||||||
if not self.connected:
|
if not self.connected:
|
||||||
# try again in 5 seconds - attention, logic inverted!
|
# try again in 5 seconds - attention, logic inverted!
|
||||||
GObject.timeout_add(5000, self.connectToOwnCloud)
|
GObject.timeout_add(5000, self.connectToOwnCloud)
|
||||||
|
|
||||||
def port(self):
|
def port(self):
|
||||||
return 34001 # Fixme, read from config file.
|
return 34001 # Fixme, read from config file.
|
||||||
|
|
||||||
def connectToOwnCloud(self):
|
def connectToOwnCloud(self):
|
||||||
try:
|
try:
|
||||||
self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||||
|
self.sock.connect(("localhost", self.port()))
|
||||||
self.sock.connect(("localhost", self.port()))
|
self.sock.settimeout(5)
|
||||||
self.sock.settimeout(5)
|
self.connected = True
|
||||||
self.connected = True
|
self.watch_id = GObject.io_add_watch(self.sock, GObject.IO_IN, self.handle_notify)
|
||||||
self.watch_id = GObject.io_add_watch(self.sock, GObject.IO_IN, self.handle_notify)
|
|
||||||
except:
|
except:
|
||||||
print( "Connect could not be established, try again later!" )
|
print("Connect could not be established, try again later!")
|
||||||
self.sock.close()
|
self.sock.close()
|
||||||
return not self.connected
|
return not self.connected
|
||||||
|
|
||||||
def sendCommand(self, cmd):
|
def sendCommand(self, cmd):
|
||||||
if self.connected:
|
if self.connected:
|
||||||
try:
|
try:
|
||||||
self.sock.send(cmd)
|
self.sock.send(cmd)
|
||||||
except:
|
except:
|
||||||
print( "Sending failed." )
|
print("Sending failed.")
|
||||||
GObject.source_remove( self.watch_id )
|
GObject.source_remove(self.watch_id)
|
||||||
self.connected = False
|
self.connected = False
|
||||||
GObject.timeout_add(5000, self.connectToOwnCloud)
|
GObject.timeout_add(5000, self.connectToOwnCloud)
|
||||||
|
|
||||||
def find_item_for_file( self, path ):
|
def find_item_for_file(self, path):
|
||||||
if path in self.nautilusVFSFile_table:
|
if path in self.nautilusVFSFile_table:
|
||||||
return self.nautilusVFSFile_table[path]
|
return self.nautilusVFSFile_table[path]
|
||||||
else:
|
else:
|
||||||
|
@ -55,14 +54,14 @@ class ownCloudExtension(GObject.GObject, Nautilus.ColumnProvider, Nautilus.InfoP
|
||||||
def askForOverlay(self, file):
|
def askForOverlay(self, file):
|
||||||
if os.path.isdir(file):
|
if os.path.isdir(file):
|
||||||
folderStatus = self.sendCommand("RETRIEVE_FOLDER_STATUS:"+file+"\n");
|
folderStatus = self.sendCommand("RETRIEVE_FOLDER_STATUS:"+file+"\n");
|
||||||
|
|
||||||
if os.path.isfile(file):
|
if os.path.isfile(file):
|
||||||
fileStatus = self.sendCommand("RETRIEVE_FILE_STATUS:"+file+"\n");
|
fileStatus = self.sendCommand("RETRIEVE_FILE_STATUS:"+file+"\n");
|
||||||
|
|
||||||
def invalidate_items_underneath( self, path ):
|
def invalidate_items_underneath(self, path):
|
||||||
update_items = []
|
update_items = []
|
||||||
for p in self.nautilusVFSFile_table:
|
for p in self.nautilusVFSFile_table:
|
||||||
if p == path or p.startswith( path ):
|
if p == path or p.startswith(path):
|
||||||
item = self.nautilusVFSFile_table[p]
|
item = self.nautilusVFSFile_table[p]
|
||||||
update_items.append(item)
|
update_items.append(item)
|
||||||
|
|
||||||
|
@ -85,7 +84,7 @@ class ownCloudExtension(GObject.GObject, Nautilus.ColumnProvider, Nautilus.InfoP
|
||||||
'NOP' : 'oC_error'
|
'NOP' : 'oC_error'
|
||||||
}
|
}
|
||||||
|
|
||||||
print( "Server response: "+l )
|
print("Server response: "+l)
|
||||||
parts = l.split(':')
|
parts = l.split(':')
|
||||||
if len(parts) > 0:
|
if len(parts) > 0:
|
||||||
action = parts[0]
|
action = parts[0]
|
||||||
|
@ -102,21 +101,21 @@ class ownCloudExtension(GObject.GObject, Nautilus.ColumnProvider, Nautilus.InfoP
|
||||||
elif action == 'UPDATE_VIEW':
|
elif action == 'UPDATE_VIEW':
|
||||||
# Search all items underneath this path and invalidate them
|
# Search all items underneath this path and invalidate them
|
||||||
if parts[1] in self.registered_paths:
|
if parts[1] in self.registered_paths:
|
||||||
self.invalidate_items_underneath( parts[1] )
|
self.invalidate_items_underneath(parts[1])
|
||||||
|
|
||||||
elif action == 'REGISTER_PATH':
|
elif action == 'REGISTER_PATH':
|
||||||
self.registered_paths[parts[1]] = 1
|
self.registered_paths[parts[1]] = 1
|
||||||
self.invalidate_items_underneath( parts[1] )
|
self.invalidate_items_underneath(parts[1])
|
||||||
elif action == 'UNREGISTER_PATH':
|
elif action == 'UNREGISTER_PATH':
|
||||||
del self.registered_paths[parts[1]]
|
del self.registered_paths[parts[1]]
|
||||||
self.invalidate_items_underneath( parts[1] )
|
self.invalidate_items_underneath(parts[1])
|
||||||
|
|
||||||
# check if there are non pathes any more, if so, its usual
|
# check if there are non pathes any more, if so, its usual
|
||||||
# that mirall went away. Try reconnect.
|
# that mirall went away. Try reconnect.
|
||||||
if not self.registered_paths:
|
if not self.registered_paths:
|
||||||
self.sock.close()
|
self.sock.close()
|
||||||
self.connected = False
|
self.connected = False
|
||||||
GObject.source_remove( self.watch_id )
|
GObject.source_remove(self.watch_id)
|
||||||
GObject.timeout_add(5000, self.connectToOwnCloud)
|
GObject.timeout_add(5000, self.connectToOwnCloud)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
@ -140,12 +139,12 @@ class ownCloudExtension(GObject.GObject, Nautilus.ColumnProvider, Nautilus.InfoP
|
||||||
data = data[:lastNL]
|
data = data[:lastNL]
|
||||||
|
|
||||||
for l in data.split('\n'):
|
for l in data.split('\n'):
|
||||||
self.handle_server_response( l )
|
self.handle_server_response(l)
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
return True # run again
|
return True # run again
|
||||||
|
|
||||||
def get_local_path(self, path):
|
def get_local_path(self, path):
|
||||||
return path.replace("file://", "")
|
return path.replace("file://", "")
|
||||||
|
|
||||||
|
@ -160,9 +159,9 @@ class ownCloudExtension(GObject.GObject, Nautilus.ColumnProvider, Nautilus.InfoP
|
||||||
for reg_path in self.registered_paths:
|
for reg_path in self.registered_paths:
|
||||||
if filename.startswith(reg_path):
|
if filename.startswith(reg_path):
|
||||||
self.nautilusVFSFile_table[filename] = item
|
self.nautilusVFSFile_table[filename] = item
|
||||||
|
|
||||||
# item.add_string_attribute('share_state', "share state")
|
# item.add_string_attribute('share_state', "share state")
|
||||||
self.askForOverlay(filename)
|
self.askForOverlay(filename)
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
print( "Not in scope:"+filename )
|
print("Not in scope:"+filename)
|
||||||
|
|
Загрузка…
Ссылка в новой задаче