Adding iotlab as a package in setup.py.
authorSandrine Avakian <sandrine.avakian@inria.fr>
Tue, 2 Jul 2013 16:15:49 +0000 (18:15 +0200)
committerMohamed Larabi <mohamed.larabi@inria.fr>
Fri, 26 Jul 2013 15:52:45 +0000 (17:52 +0200)
setup.py
sfa/iotlab/LDAPapi.py
sfa/rspecs/versions/iotlabv1.py

index e6c041a..162d057 100755 (executable)
--- a/setup.py
+++ b/setup.py
@@ -16,22 +16,22 @@ except:
     version_tag='cleaningup'
 
 scripts = glob("clientbin/*.py") + \
-    [ 
+    [
     'config/sfa-config-tty',
     'config/sfa-config',
 #    'config/gen-sfa-cm-config.py',
-    'sfa/server/sfa-start.py', 
-#    'sfa/server/sfa_component_setup.py', 
+    'sfa/server/sfa-start.py',
+#    'sfa/server/sfa_component_setup.py',
     'sfatables/sfatables',
     'keyconvert/keyconvert.py',
     'flashpolicy/sfa_flashpolicy.py',
     ]
 
 packages = [
-    'sfa', 
+    'sfa',
     'sfa/trust',
     'sfa/storage',
-    'sfa/util', 
+    'sfa/util',
     'sfa/server',
     'sfa/methods',
     'sfa/generic',
@@ -48,7 +48,7 @@ packages = [
     'sfa/dummy',
     'sfa/openstack',
     'sfa/federica',
-    'sfa/senslab',
+    'sfa/iotlab',
     'sfatables',
     'sfatables/commands',
     'sfatables/processors',
@@ -96,24 +96,24 @@ if sys.argv[1] in ['uninstall', 'remove', 'delete', 'clean']:
     remove_bins = [ '/usr/bin/' + os.path.basename(bin) for bin in scripts ]
     remove_files = remove_bins + [ "/etc/init.d/%s"%x for x in initscripts ]
 
-    # remove files   
+    # remove files
     for filepath in remove_files:
         print "removing", filepath, "...",
-        try: 
+        try:
             os.remove(filepath)
             print "success"
         except: print "failed"
-    # remove directories 
-    for directory in remove_dirs: 
+    # remove directories
+    for directory in remove_dirs:
         print "removing", directory, "...",
-        try: 
+        try:
             shutil.rmtree(directory)
             print "success"
         except: print "failed"
 else:
     # avoid repeating what's in the specfile already
     setup(name='sfa',
-          packages = packages, 
+          packages = packages,
           data_files = data_files,
           scripts = scripts,
           url="http://svn.planet-lab.org/wiki/SFATutorial",
index fda3515..75649e3 100644 (file)
@@ -46,21 +46,23 @@ class ldap_co:
         self.ldapSearchScope = ldap.SCOPE_SUBTREE
 
 
-    def connect(self, bind = True):
+    def connect(self, bind=True):
         """
         Enables connection to the LDAP server.
         :param bind : Set the bind parameter to True if a bind is needed
         (for add/modify/delete operations).
         Set to False otherwise.
+
         :type bind : boolean
         :return: dictionary with status of the connection. True if Successful,
         False if not and in this case the error message( {'bool', 'message'} )
         :rtype:dict
+
         """
         try:
             self.ldapserv = ldap.open(self.ldapHost)
         except ldap.LDAPError, error:
-            return {'bool' : False, 'message' : error }
+            return {'bool': False, 'message': error}
 
         # Bind with authentification
         if(bind):
@@ -71,6 +73,7 @@ class ldap_co:
 
     def bind(self):
         """ Binding method.
+
         :return: dictionary with the bind status. True if Successful,
         False if not and in this case the error message( {'bool', 'message'} )
         :rtype: dict
@@ -86,65 +89,72 @@ class ldap_co:
                                     self.ldapAdminPassword)
 
         except ldap.LDAPError, error:
-            return {'bool' : False, 'message' : error }
+            return {'bool': False, 'message': error}
 
         return {'bool': True}
 
     def close(self):
         """ Close the LDAP connection.
+
         Can throw an exception if the unbinding fails.
+
         """
         try:
             self.ldapserv.unbind_s()
         except ldap.LDAPError, error:
-            return {'bool' : False, 'message' : error }
+            return {'bool': False, 'message': error}
+
 
 class LoginPassword():
     """
+
     Class to handle login and password generation, using custom login generation
     algorithm.
+
     """
     def __init__(self):
         """
+
         Sets password  and login maximum length, and defines the characters
         that can be found in a random generated password.
+
         """
-        self.login_max_length  = 8
+        self.login_max_length = 8
         self.length_password = 8
-        self.chars_password = [ '!', '$', '(',')', '*', '+', ',', '-', '.', \
-                                '0', '1', '2', '3', '4', '5', '6', '7', '8', \
-                                '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', \
-                                'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', \
-                                'R', 'S', 'T',  'U', 'V', 'W', 'X', 'Y', 'Z', \
-                                '_', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', \
-                                'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p' ,'q', \
-                                'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', \
-                                '\'']
-
-
-
+        self.chars_password = ['!', '$', '(',')', '*', '+', ',', '-', '.',
+                               '0', '1', '2', '3', '4', '5', '6', '7', '8',
+                               '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
+                               'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q',
+                               'R', 'S', 'T',  'U', 'V', 'W', 'X', 'Y', 'Z',
+                               '_', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h',
+                               'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q',
+                               'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
+                               '\'']
 
     @staticmethod
     def clean_user_names(record):
         """
+
         Removes special characters such as
         '-', '_' , '[', ']' and ' ' from the first name and last name.
+
         :param record: user's record
         :type record:dict
         :return: lower_first_name and lower_last_name if they were found
         in the user's record. Return None, none otherwise.
         :rtype: string, string or None, None.
+
         """
         if 'first_name' in record and 'last_name' in record:
             #Remove all special characters from first_name/last name
-            lower_first_name = record['first_name'].replace('-','')\
-                                            .replace('_','').replace('[','')\
-                                            .replace(']','').replace(' ','')\
-                                            .lower()
-            lower_last_name = record['last_name'].replace('-','')\
-                                            .replace('_','').replace('[','')\
-                                            .replace(']','').replace(' ','')\
-                                            .lower()
+            lower_first_name = record['first_name'].replace('-', '')\
+                .replace('_', '').replace('[', '')\
+                .replace(']', '').replace(' ', '')\
+                .lower()
+            lower_last_name = record['last_name'].replace('-', '')\
+                .replace('_', '').replace('[', '')\
+                .replace(']', '').replace(' ', '')\
+                .lower()
             return lower_first_name, lower_last_name
         else:
             return None, None
@@ -310,14 +320,17 @@ class LDAPapi :
 
     def LdapGenerateUniqueLogin(self, record):
         """
+
         Generate login for adding a new user in LDAP Directory
         (four characters minimum length). Get proper last name and
         first name so that the user's login can be generated.
+
         :param record: Record must contain first_name and last_name.
         :param record: dict
         :return: the generated login for the user described with record if the
         login generation is successful, None if it fails.
         :rtype: string or None
+
         """
         #For compatibility with other ldap func
         if 'mail' in record and 'email' not in record:
@@ -568,7 +581,7 @@ class LDAPapi :
 
             except ldap.LDAPError, error:
                 logger.log_exc("LDAP Add Error %s" %error)
-                return {'bool' : False, 'message' : error }
+                return {'bool': False, 'message': error}
 
             self.conn.close()
             return {'bool': True, 'uid':user_ldap_attrs['uid']}
index 6d15973..a4a8300 100644 (file)
@@ -3,7 +3,7 @@ from copy import deepcopy
 
 from sfa.rspecs.version import RSpecVersion
 import sys
-from sfa.rspecs.elements.versions.iotlabv1Lease import Iotlabv1Lease
+from sfa.rspecs.elements.versions.iotlabv1Lease import Iotlabv1Lease
 from sfa.rspecs.elements.versions.iotlabv1Node import Iotlabv1Node
 from sfa.rspecs.elements.versions.iotlabv1Sliver import Iotlabv1Sliver
 
@@ -12,7 +12,12 @@ from sfa.rspecs.elements.versions.sfav1Lease import SFAv1Lease
 
 from sfa.util.sfalogging import logger
 
+
 class Iotlabv1(RSpecVersion):
+    """
+    Defines Iotlab style RSpec and associated methods to parse and create a
+    valid Iotlab XML Rspec.
+    """
     #enabled = True
     type = 'Slab'
     content_type = 'ad'
@@ -38,7 +43,6 @@ class Iotlabv1(RSpecVersion):
                     network_elem in network_elems]
         return networks
 
-
     def add_network(self, network):
         network_tags = self.xml.xpath('//network[@name="%s"]' % network)
         if not network_tags:
@@ -47,9 +51,7 @@ class Iotlabv1(RSpecVersion):
             network_tag = network_tags[0]
         return network_tag
 
-
     # Nodes
-
     def get_nodes(self, filter=None):
         return Iotlabv1Node.get_nodes(self.xml, filter)