Commits

pystew committed 4bc347c

0.2

Comments (0)

Files changed (4)

             if hasattr(self.config, 'admin_login'):
                 self._login = self.config.admin_login
             else:
-                self._login = raw_input('Admin LOGIN :')
+                self._login = raw_input('Admin LOGIN :')
         return self._login
     @property
     def admin_psw(self):
         return self.login(self.admin_login, self.admin_psw)
     def close(self):
         self.QUIT()
-        self.quit()
+        self.quit()
+    def server(self):
+        return self.INFO()
     def login(self, usr, psw):
-        return self.USER(usr) and self.PASS(psw)
-    def chku(self, usr, ignore=False):
+        return self.USER(usr) and self.PASS(psw)
+    def logout(self):
+        self.LOUT()
+    @property
+    def users(self): # users listing
+        for usr, level in sorted(self.LIST()):
+            if not usr.startswith('SYS_') and level<'6':
+                yield usr
+    def vcard(self, user, first, name, full): # post a vcard
+        msg = tpl.vcf%(user, user, name, first, full, user)
+        msg = msg.lstrip().split('\n')
+        self.ENT0(fmt='4', msg=msg)
+    def chkuser(self, usr, ignore=False): # is usr created
         return self.QUSR(usr, ignore=ignore)==usr
-    def creu(self, usr, psw, lvl='4'):
-        if self.chku(usr, ignore=True):  return True
+    def upduser(self, usr, psw, first, name, full): # update user info
+        self.login(usr, psw)
+        self.GOTO('My Citadel Config')
+        self.vcard(usr, first, name, full)
+        self.LOUT()
+    def deluser(self, usr): # delete usr
+        self.admin()
+        c = self.ASUP(usr, '0','0','0','0','0','0','0','0')
+        self.LOUT()
+        return c
+    def adduser(self, usr, psw, lvl='4'): # add usr
+        if self.chkuser(usr, ignore=True):  return True
         self.admin()
         self.CREU(usr, psw)
         valid = self.VALI(usr, lvl)
         self.LOUT()
-        return valid and self.chku(usr)
-    def delu(self, usr):
-        self.admin()
-        c = self.ASUP(usr, '0','0','0','0','0','0','0','0')
-        self.LOUT()
-        return c
-    def listu(self):
-        for usr, level in sorted(self.LIST()):
-            if not usr.startswith('SYS_') and level<'6':
-                yield usr
+        return valid and self.chkuser(usr)
+    def create_user(self, login, psw, first, name): # create usr
+        full = '%s %s'%(first.capitalize(), name.upper())
+        if self.adduser(login, psw):
+            self.upduser(login, psw, first, name, full)
     def mail(self, dst, sbj, txt): # post a mail
         self.GOTO('mail')
         msg = [' %s'%i for i in txt.split('\n')]
         self.ENT0(to=dst, sbj=sbj, msg=msg)
-    def vcard(self, user, first, name, full): # post a vcard
-        msg = tpl.vcf%(user, user, name, first, full, user)
-        msg = msg.lstrip().split('\n')
-        self.ENT0(fmt='4', msg=msg)
-    def updusr(self, usr, psw, pre, nom, full): # update user info
-        self.login(usr, psw)
-        self.GOTO('My Citadel Config')
-        self.vcard(usr, pre, nom, full)
-        self.LOUT()
-    def creuser(self, login, psw, pre, nom, full):
-        if self.creu(login, psw):
-            self.updusr(login, psw, pre, nom, full)
 
         c, a = self.get()
         self.log(a[0], 'w')
     def log(self, txt, mode='a'):
-        if hasattr(self, 'logfil'):
-            log = open(self.logf, mode)
+        if self.logfil:
+            log = open(self.logfil, mode)
             log.write('%s\n'%txt)
             log.close
     def connect(self, adr, port):
 setup(
     name = 'citadel',
     packages = ['citadel'],
-    version = '0.1',
+    version = '0.2',
     description = 'Citadel high level client library',
     author='Louis RIVIERE',
     author_email = "louis@pystew.net",
-from citadel import Citadel
-
+# import the Citadel class according to your PYTHONPATH
+from citadel.citadel import Citadel
+
+# get the "config" oject (anyway you want)
 import config
-
-citadel = Citadel(config)
-print citadel.INFO()
-print '\n'.join(citadel.listu())
+
+# instantiate the Citadel class passing it the "config" object
+# connecting to the server
+citadel = Citadel(config)
+
+# print server infos, showing everything is okay
+print citadel.server()
+
+# create a new user
+# implicity log in as "admin"
+# ! admin login and password will be seen in the log file !
+citadel.create_user('john', 'password', 'john', 'wayne')
+
+# list users
+for usr in citadel.users: print usr
+
+# log in as john
+#  ! "password" will appear in the log file !
+citadel.login('john', 'password')
+
+# send a mail to zorro (which must exist)
+citadel.mail('zorro', 'subject', 'message')
+
+# log out
+citadel.logout()
+
+# delete user
+citadel.deluser('john')
+
+# close the connection
 citadel.close()