[Pkg-owncloud-commits] [owncloud-client] 240/332: nautilus plugin: Adopted to latest socket api changes.

Sandro Knauß hefee-guest at moszumanska.debian.org
Thu Aug 14 21:07:05 UTC 2014


This is an automated email from the git hooks/post-receive script.

hefee-guest pushed a commit to branch master
in repository owncloud-client.

commit 00274722cebe99c7ec63838806bc0c2a63310570
Author: Klaas Freitag <freitag at owncloud.com>
Date:   Fri Jul 25 12:11:12 2014 +0200

    nautilus plugin: Adopted to latest socket api changes.
---
 shell_integration/nautilus/ownCloud.py | 96 +++++++++++++++++++++++++---------
 1 file changed, 71 insertions(+), 25 deletions(-)

diff --git a/shell_integration/nautilus/ownCloud.py b/shell_integration/nautilus/ownCloud.py
old mode 100644
new mode 100755
index e831203..968156f
--- a/shell_integration/nautilus/ownCloud.py
+++ b/shell_integration/nautilus/ownCloud.py
@@ -1,3 +1,5 @@
+#!/usr/bin/python3
+
 import os
 import urllib
 import socket
@@ -7,11 +9,13 @@ from gi.repository import GObject, Nautilus
 class ownCloudExtension(GObject.GObject, Nautilus.ColumnProvider, Nautilus.InfoProvider):
     
     nautilusVFSFile_table = {}
-	    
+    registered_paths = {}
+    remainder = ''
+
     def __init__(self):
-	self.sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
-	self.sock.connect("/home/kf/.local/share/data/ownCloud/socket")
-	self.sock.settimeout(15)
+	self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+	self.sock.connect(("localhost", 33001))
+	self.sock.settimeout(5)
 	
 	GObject.io_add_watch(self.sock, GObject.IO_IN, self.handle_notify)
 	
@@ -19,7 +23,10 @@ class ownCloudExtension(GObject.GObject, Nautilus.ColumnProvider, Nautilus.InfoP
 	self.sock.send(cmd)
 
     def find_item_for_file( self, path ):
-	return self.nautilusVFSFile_table[path]
+	if path in self.nautilusVFSFile_table:
+	    return self.nautilusVFSFile_table[path]
+	else:
+	    return None
     
     def callback_update_file( self, path ):
 	print "Got an update callback for " + path
@@ -33,32 +40,65 @@ class ownCloudExtension(GObject.GObject, Nautilus.ColumnProvider, Nautilus.InfoP
 
     # Handles a single line of server respoonse and sets the emblem
     def handle_server_response(self, l):
-        Emblems = { 'NOP': '',
-                    'NEED_SYNC':'view-refresh',
-                    'OK': 'dialog-ok' }
-    
+        Emblems = { 'OK'        : 'dialog-ok',
+		    'SYNC'      : 'view-refresh',
+		    'NEW'       : 'view-refresh',
+		    'IGNORE'    : '',
+		    'ERROR'     : '',
+		    'OK+SWM'    : '',
+		    'SYNC+SWM'  : '',
+		    'NEW+SWM'   : '',
+		    'IGNORE+SWM': '',
+		    'ERROR+SWM' : '',
+		    'NOP' : ''
+			}
+
+        print "Server response: "+l
         parts = l.split(':')
-        if len(parts) > 2:
-            if parts[0] == 'STATUS':
-                emblem = Emblems[parts[1]]
-            elif parts[0] == 'BROADCAST':
+        if len(parts) > 0:
+	    action = parts[0]
+
+	    # file = parts[1]
+	    # print "Action for " + file + ": "+parts[0]
+            if action == 'STATUS':
                 emblem = Emblems[parts[1]]
+                if emblem:
+                    item = self.find_item_for_file(parts[2])
+                    if item:
+                        item.add_emblem(emblem)
+	    elif action == 'UPDATE_VIEW':
+		if parts[1] in self.registered_paths:
+		    for p in self.nautilusVFSFile_table:
+			if p.startswith( parts[1] ):
+			    item = self.nautilusVFSFile_table[p]
+			    item.invalidate_extension_info()
+			    self.update_file_info(item)
+
+	    elif action == 'REGISTER_PATH':
+		self.registered_paths[parts[1]] = 1
             else:
-                print "We got unknown status " + parts[0]
-                
-            if emblem:
-                item = self.nautilusVFSFile_table[parts[2]]
-                if item:
-                    item.set_emblem(emblem)
+                # print "We got unknown action " + action
+                1
 
     # notify is the raw answer from the socket
     def handle_notify(self, source, condition):
-	print "T "
+
 	data = source.recv(1024)
+	# prepend the remaining data from last call
+	if len(self.remainder) > 0:
+	    data = self.remainder+data
+	    self.remainder = ''
+
 	if len(data) > 0:
+	    # remember the remainder for next round
+	    lastNL = data.rfind('\n');
+	    if lastNL > -1 and lastNL < len(data):
+		self.remainder = data[lastNL+1:]
+		data = data[:lastNL]
+
 	    for l in data.split('\n'):
 	        self.handle_server_response( l )
-	        
+
 	return True # run again
 	    
     def get_local_path(self, path):
@@ -75,9 +115,15 @@ class ownCloudExtension(GObject.GObject, Nautilus.ColumnProvider, Nautilus.InfoP
             return
 
         filename = urllib.unquote(item.get_uri()[7:])
+        if item.is_directory():
+	    filename += '/'
 
-	self.nautilusVFSFile_table[filename] = item
+	for reg_path in self.registered_paths:
+	    if filename.startswith(reg_path):
+		self.nautilusVFSFile_table[filename] = item
 	
-	print "XXX " + filename
-        item.add_string_attribute('share_state', "share state")
-        self.askForOverlay(filename)
+		# item.add_string_attribute('share_state', "share state")
+		self.askForOverlay(filename)
+		break
+	    else:
+		print "Not in scope:"+filename
\ No newline at end of file

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud-client.git



More information about the Pkg-owncloud-commits mailing list