share handling rework
authorDhananjay Sathe <dhananjaysathe@gmail.com>
Sun, 19 Jun 2011 18:27:50 +0000 (23:57 +0530)
committerDhananjay Sathe <dhananjaysathe@gmail.com>
Sun, 19 Jun 2011 18:27:50 +0000 (23:57 +0530)
images/network-folder-alternate.png [new file with mode: 0644]
images/network-folder-blue.png [new file with mode: 0644]
images/network-folder.png [new file with mode: 0644]
images/network-pipe-alt.png [new file with mode: 0644]
images/network-pipe.png [new file with mode: 0644]
images/network-printer.png [new file with mode: 0644]
pygwshare.py
srvsvc.py

diff --git a/images/network-folder-alternate.png b/images/network-folder-alternate.png
new file mode 100644 (file)
index 0000000..a49a77d
Binary files /dev/null and b/images/network-folder-alternate.png differ
diff --git a/images/network-folder-blue.png b/images/network-folder-blue.png
new file mode 100644 (file)
index 0000000..958039f
Binary files /dev/null and b/images/network-folder-blue.png differ
diff --git a/images/network-folder.png b/images/network-folder.png
new file mode 100644 (file)
index 0000000..311aa6f
Binary files /dev/null and b/images/network-folder.png differ
diff --git a/images/network-pipe-alt.png b/images/network-pipe-alt.png
new file mode 100644 (file)
index 0000000..8d1469f
Binary files /dev/null and b/images/network-pipe-alt.png differ
diff --git a/images/network-pipe.png b/images/network-pipe.png
new file mode 100644 (file)
index 0000000..9a70f36
Binary files /dev/null and b/images/network-pipe.png differ
diff --git a/images/network-printer.png b/images/network-printer.png
new file mode 100644 (file)
index 0000000..5590e52
Binary files /dev/null and b/images/network-printer.png differ
index 8330185a78ff53a95f37e806db5432af57776990..07878e95c004d00a22005dee95edfd20b1faa5c7 100644 (file)
@@ -62,7 +62,10 @@ class srvsvcPipeManager(object):
         # This should reduce the queries and improve performance
         # The share list will be locally maintained any via the get_share_local_cache
         
-        self.islocal = 0x00000000  # set to one if connect is to localhost........
+        if server_address == '127.0.0.1':
+            self.islocal = True
+        else:
+            self.islocal = False
         self.conn_list = []
         self.share_list = []
         self.share_names_list = []
@@ -74,6 +77,7 @@ class srvsvcPipeManager(object):
             self.list_shares()
         
 
+
     def close(self):
         pass
         # apparently there's no .Close() method for this pipe
@@ -114,28 +118,29 @@ class srvsvcPipeManager(object):
                     (stype_int, stype_comm) = (i[1], i[2])
                     return (stype_int, stype_comm)
                 else:
-                    raise KeyError
+                    raise KeyError('Invalid Share Type')
         if isinstance(stype, int):
             for i in stype_table:
                 if i[1] == stype:
                     (stype_str, stype_comm) = (i[0x00000000], i[2])
                     return (stype_str, stype_comm)
                 else:
-                    raise KeyError
+                    raise KeyError('Invalid Share Type')
 
-    @staticmethod
-    def fix_path_format(path='', islocal=0x00000000):
+
+
+    def fix_path_format(self,path=''):
         """ Fixes and checks the given path to make it in tthe correct format 
   
   Convert the unix path to relavant Info Struct path for samba share object 
   It also checks for validity of path if it is local.
   To be used for distktree (Files not IPC etc) type shares.
   Usage :
-  S.fix_path_format(path= \"\",islocal= 0) -> path
+  S.fix_path_format(path= "") -> path
   
   """
 
-        if self.islocal == 1:
+        if self.islocal :
             if os.path.exists(path):
                 path = os.path.realpath(path)  # gets canonical path
             else:
@@ -148,9 +153,10 @@ class srvsvcPipeManager(object):
             elif path.startswith('C:'):
                 path = unicode(path)
             else:
-                raise KeyError
+                raise TypeError('Invalid path Argument')
         return path
 
+
     
     # NOT supported yet
     def get_connections(
@@ -170,43 +176,27 @@ class srvsvcPipeManager(object):
                                  self.resume_handle_conn)
         for i in info_ctr.ctr.array :
             self.conn_list.append(i)
+
     
     
-    def modify_share(
-        self,
-        name='',
-        comment='',
-        max_users=0xFFFFFFFF,
-        password='',
-        path='',
-        permissions=None,
-        sd_buf=None,
-        islocal=0x00000000,
-        ):
+    def modify_share(self,share=None):
         """ Modifies share 502 object. 
   
   Usage:
-  S.modify_share(self,name= "",comment= "",max_users= 0xFFFFFFFF,password= "",path= "",permissions= None,sd_buf=None,islocal= 0) -> parm_error
+  S.modify_share(self,share)-> parm_error
 
   """
-
-        # FIXME sd_buf needs to be fixed 
-        name = unicode(name)
-        share = self.get_share_info_rpc(name)
-
-        if comment != '':
-            share.comment = comment
-        share.max_users = max_users
-        share.current_users = 0x00000000
-        share.password = password
-        share.path = self.fix_path_format(path, islocal)
-        share.permissions = None
-        share.sd_buf = security  # ### FIXME
+        if share is None:
+                       raise KeyError("Illegal to pass null share type.")
+               
         parm_error = 0x00000000
+        name = share.name
         parm_error = self.pipe.NetShareSetInfo(self.server_unc, name,
                 502, share, parm_error)
         return parm_error
 
+
+
     def list_shares(self):
         """ Gets a list of all (not hidden/special)active shares and update the share and share_name list. 
   
@@ -228,6 +218,8 @@ class srvsvcPipeManager(object):
             self.share_names_list.append(i.name)
             self.share_types_list.append(i.type)
 
+
+
     def list_shares_all(self):
         """ Gets a list of all (including hiden/special)active shares and update the share and share_name list. 
   
@@ -248,26 +240,28 @@ class srvsvcPipeManager(object):
             self.share_names_list.append(i.name)
             self.share_types_list.append(i.type)
 
-    def add_share(self, name='', stype=''):
+
+
+    def add_share(self, share=None):
         """Adds a share with a given name and type
   This uses a share info 502 object.
   Should be followed by modify_share to complete the addition of the share.
   
   Usage :
-  S.add_share(self,name= \"\",stype= \"\") -> parm_error
+  S.add_share(self,share=None) -> parm_error
   
   """
-
+        name = share.name
+        if share is None :
+                       raise KeyError("Illegal to pass null share type.")
         # Uses the default 502 share info
-        share = srvsvc.NetShareInfo502()
-        name = unicode(name)
-        share.name = name
-        (share.type, share.comment) = translate_types(stype)
         parm_error = 0x00000000
         parm_error = self.pipe.NetShareAdd(self.server_unc, 502, share,
                 parm_error)
         return parm_error
 
+
+
     def get_share_info_local(self, name=''):
         """ Gets share info for a share with a particular name from local cache lists.
   
@@ -280,6 +274,8 @@ class srvsvcPipeManager(object):
             if name == i:
                 return share_list[i.index()]
 
+
+
     def get_share_info_rpc(self, name=''):
         """ Gets share info for a share with a particular name from the rpc server.
   
@@ -291,6 +287,8 @@ class srvsvcPipeManager(object):
         info = self.pipe.NetShareGetInfo(self.server_unc, name, 502)
         return info
 
+
+
     def delete_share(self, name=''):
         """ Delete a share with the given name. 
 
@@ -302,6 +300,8 @@ class srvsvcPipeManager(object):
         name = unicode(name)
         self.pipe.NetShareDel(self.server_unc, name, reserved)
 
+
+
     # NOT supported yet 
     def remove_persistance(self, name=''):
         """ Removes persistance of a share .
@@ -314,6 +314,8 @@ class srvsvcPipeManager(object):
         name = unicode(name)
         self.pipe.NetShareDelSticky(self.server_unc, name, reserved)
 
+
+
     def get_share_type(self, name=''):
         """ Returns type of share code 
   uses local cache for now as the rpc server in samba4 does not support it yet
@@ -330,6 +332,8 @@ class srvsvcPipeManager(object):
                 raise KeyError
         return stype
 
+
+
     def update_tod(self):
         """ Updates Time and date (TOD) Info of the pipe object.
   ........
@@ -339,6 +343,8 @@ class srvsvcPipeManager(object):
 
         self.tod = self.pipe.NetRemoteTOD(self.server_unc)
 
+
+
     def get_list_disks(self):
         """ Returns a list of disks on the system.
   In samaba rpc server these are hard coded .
@@ -357,6 +363,9 @@ class srvsvcPipeManager(object):
             if i != '':  # disk lists returns a blank entry not of consequence to the program
                 self.disks_list.append(i)
 
+
+
+
     @staticmethod
     def get_platform_string(platform_id):
         """ Returns OS type string and description.
@@ -375,6 +384,8 @@ class srvsvcPipeManager(object):
         (typestring, platform_comment) = os_dict[platform_id]
         return (typestring, platform_comment)
 
+
+
     def get_file_security(
         self,
         secdesc,
@@ -393,6 +404,8 @@ class srvsvcPipeManager(object):
                 filename, secdesc)  # FIXME secdesc....
         return sd_buf
 
+
+
     def set_file_security(
         self,
         secdesc,
@@ -411,4 +424,38 @@ class srvsvcPipeManager(object):
         self.pipe.NetSetFileSecurity(self.server_unc, share, filename,
                 secdesc, sd_buf)  # FIXME secdesc,sd_buf
 
-
+    def get_share_object (
+        self,
+        name= None,
+        stype= None,
+        comment= '',
+        max_users=0xFFFFFFFF,
+        password= '',
+        path= '',
+        #permissions= None,
+        sd_buf= None
+        ):
+        """ Gets a 502 type share object. 
+  Usage:
+  S.get_share_object(self,name= "",comment= "",max_users= 0xFFFFFFFF,password= "",path= "",permissions= None,sd_buf=None) -> share (502 type share object)
+  """
+        share = srvsvc.NetShareInfo502()
+        
+        if name is None or stype is None :
+            raise KeyError('Missing name / type')
+        
+        if comment is'':
+            share.comment = self.translate_types(stype)[1]
+        else:
+            share.comment = comment
+        
+        share.name = unicode(name)
+        share.type = stype
+        share.current_users = 0x00000000
+        share.max_users= max_users
+        share.password = password
+        share.path = self.fix_path_format(path)
+        share.permissions = None
+        share.sd_buf = sd_buf  # ### FIXME
+        
+        return share
index 4af57a6386b7b312e5da09843969ed2d9a735fbc..9f416c21c747c672b6aa166484d6ccab0f991d43 100644 (file)
--- a/srvsvc.py
+++ b/srvsvc.py
@@ -182,12 +182,30 @@ class ShareAddEditDialog(gtk.Dialog):
 
     """ Share add and edit dialog 
  
- if edit is set to True then in Edit mode .
+ If 'edit_mode' is set to True then in Edit mode .
+ Immutable fields are automatically greyed out.
   """
 
     def __init__(self, pipe_manager, share=None):
         """ Class initialiser """
+        super(ShareAddEditDialog, self).__init__()
+        self.pipe = pipe_manager
+        if share is None :
+            self.edit_mode = 0
+            
+               else :
+            self.edit_mode =  1
+            self.share = share
+        
 
-        pass
-
-
+    def  create():
+        """ Create the window """
+        self.set_title([" New Share"," Edit Share : "][self.edit_mode]+ " " + self.share.name)
+        self.set_border_width(5)
+        self.icon_name = ["network-folder","network-printer","network-pipe"][self.share_category] 
+        self.set_icon_from_file(os.path.join(sys.path[0], "images", self.icon_name))
+        
+        
+        
+        
+