Hi friends
 
Sorry i troubled someone too much by mailing direct into his account. I am sorry for that.but i was not aware of any of his mail saying me to post query somewhere else.any ways it will not happen again.
 
I am still hanging at my point how to hide that data in .fs file as i can see completely all the data if i open that file in notepad or any other editor. I will attach a sample data.fs file and my sample code with this mail . See if any one can guide me inthis context. Its a small code which add some organisation and then employees in that organisation.
 
I have added an organisation Named EagleHawk and Employee monica with age 26. Now if u open that file u can easily read eaglehawk and monica in the file. I just want to avoid this.
 
Thanks
Monica


Regards
 
Monica Chopra
Sr.Programmer
Medonline Ltd.
Tel:(09) 524 0324


Yahoo! Photos
Ring in the New Year with Photo Calendars. Add photos, events, holidays, whatever.

Attachment: data.fs
Description: 122756374-data.fs

from ZODB import FileStorage, DB
from ZODB.PersistentMapping import PersistentMapping
from persistent import Persistent
import unicodedata

#import logging
#logging.basicConfig()

class Employee(Persistent):
                        """An employee"""
                        def __init__(self, name,age,organisation,manager=None):
                                #self.name=name.encode('utf-16')
                                self.name=name
                                self.age=age
                                self.organisation=organisation
                                self.type="E"
                                self.manager=manager
                                
class Organisation(Persistent):
                        """An organisation"""
                        def __init__(self, name,Id):
                                self.Id=Id
                                #self.name=unicode( name, "utf-16" )
                                #self.name=name.encode('utf-16')
                                #self.name=unicode(name)
                                self.name=name
                                self.type="O"
                                
                        
# setup the database
import transaction
storage =FileStorage.FileStorage('Data\data.fs')
db=DB(storage)
connection=db.open()
root=connection.root()
  

if not root.has_key("sbx"):
   root["sbx"] = []
   #root["lstOrg"] = {}
   #lstOrg=root["lstOrg"]
   #sbx=root["sbx"],root["organisation"] # get the sbx mapping, creating an 
empty mapping if
   sbx=root["sbx"]
   transaction.commit()
else:
   sbx=root["sbx"]
   transaction.commit()
   #lstOrg=root["lstOrg"]
#   # get the sbx mapping, creating an empty mapping if
#   # necessary
#if not root.has_key('sbx'):
#    from BTrees.OOBTree import OOBTree
#    root['sbx'] = OOBTree()

#sbx = root['sbx']

def AddOrganisation(name,id):
        #if sbx.has_key(name):
        #       print "There is already an employee with this name."
        #       return
        
        #lstOrg[id]=Organisation(name,id)
        #root['lstOrg'] = lstOrg # reassign to change
        
        sbx.append(Organisation(name,id))
        root['sbx'] = sbx # reassign to change
                
        print "Organisation %s added." % name
        transaction.commit()
        print
        #for key in sbx.keys():
        #       obj= sbx[key]
        #       print obj.name
        for organisation in sbx:#.values():
                if organisation.type=="O":
                        print organisation.name
                

def listEmployees():
    if len(sbx)==0: #values()
       print "There are no employees."
       print
       return
           
    for employee in sbx:#.values():
                #print employee.type
                if employee.type=="E":
                        print "Name: %s " % employee.name           
                        print "Age: %s" % employee.age
                        print "Organisation: %s" % employee.organisation.name
                        if employee.manager is not None:
                                print "Manager's name: %s" % 
employee.manager.name
                
#def listorgZemp(name):
def listorgZemp():
    if len(sbx)==0: #.values()
       print "There are no employees."
       print
       return
           
    for employee in sbx:#.values():
                #print employee.type
                #if employee.type=="E":
                if employee.type=="O":
                        #if employee.organisation.name==name:
                        print "Name: %s " % employee.name           
                        #       print "Age: %s" % employee.age
                        #       print "Organisation: %s" % 
employee.organisation.name
                        #       if employee.manager is not None:
                        #               print "Manager's name: %s" % 
employee.manager.name
                        
def empDetails(name):
        if not sbx.has_key(name):
                print "There is no employee with this name."
                return
        else:
                empObject=sbx[name]
                print "Name: %s " % empObject.name          
                print "Age: %s" % empObject.age
                print "Organisation: %s" % employee.organisation.name
                if empObject.manager is not None:
                        print "Manager's name: %s" % empObject.manager.name
                
                        
def addEmployee(name,age,organisationName,manager_name=None):
        #if sbx.has_key(name):
        #       print "There is already an employee with this name."
        #       return
        if manager_name:
                try:
                        x=0
                        for organisation in sbx:    #.values():
                                if organisation.name==manager_name:
                                        manager=sbx[x]
                                else:
                                        x=x+1

                except KeyError:
                        print
                        print "No such manager"
                        print
                        return
                #for organisation in lstOrg.values():
                #       if organisation.name==organisationName:
                #               orgObject=lstOrg[organisation.id]
                x=0
                for organisation in sbx:    #.values():
                        if organisation.name==organisationName:
                                orgObject=sbx[x]
                                                                
                        else:
                                x=x+1
                #sbx[name]=Employee(name,age,orgObject,manager)
                sbx.append(Employee(name,age,orgObject,manager))
                root['sbx'] = sbx # reassign to change
                print "Employee %s added." % name
                print "Age: %s" % age
                transaction.commit()
       
        else:
                #orgObject=sbx[organisation]
                #for organisation in lstOrg.values():
                #       if organisation.name==organisationName:
                #               id=organisation.Id
                #               orgObject=lstOrg[id]
                x=0
                for organisation in sbx:    #.values():
                        if organisation.name==organisationName:
                                orgObject=sbx[x]
                                                        
                        else:
                                x=x+1
                                
                ##sbx[name]=Employee(name,age,orgObject)
                sbx.append(Employee(name,age,orgObject))
                root['sbx'] = sbx # reassign to change
                print "Employee %s added." % name
                print "Age: %s" % age
                transaction.commit()
                print
def EditEmployee(name,age,organisation,manager_name=None):
        if not sbx.has_key(name):
                print "There is no such employee with this name."
                return
        if manager_name:
                try:
                         manager=sbx[manager_name]
                except KeyError:
                        print
                        print "There is no such manager"
                        print
                        return
                editEmpObject=sbx[name]
                editEmpObject.manager=manager
                root['sbx'] = sbx # reassign to change
                transaction.commit()
        
        if age:
                editEmpObject=sbx[name]
                editEmpObject.age=age
                root['sbx'] = sbx # reassign to change
                transaction.commit()
        if organisation:
                orgObject=sbx[organisation]
                editEmpObject=sbx[name]
                editEmpObject.organisation=orgObject
                root['sbx'] = sbx # reassign to change
                transaction.commit()
        print "Employee %s ediited." % name
        empDetails(name)
def deleteall(name):
        if sbx.has_key(name):
                del(sbx[name])
                root['sbx'] = sbx 
                transaction.commit()
                print "Employee %s deleted." % name
                
                
if __name__=="__main__":
        
     while 1:
                choice=raw_input("Press 'O' to Add Organisation,Press 'OL' to 
List Organisations,Press 'L' to list employees,'A' to add an employee, or 'Q' 
to quit:")
                choice=choice.lower()
                if choice=="l":
                        listEmployees()
                        
                elif choice=="o":
                        name=raw_input("Organisation name:")
                        id=raw_input("Organisation Id:")
                        AddOrganisation(name,id)
                elif choice=="ol":
                        #name=raw_input("Organisation name:")
                        #listorgZemp(name)
                        listorgZemp()
                elif choice=="a":
                        name=raw_input("Employee name:")
                        organisation=raw_input("Organisation name:")
                        manager_name=raw_input("Manager name:")
                        age=raw_input("Age :")
                        addEmployee(name,age,organisation,manager_name)
                elif choice=="e":
                        name=raw_input("Employee name:")

                        manager_name=raw_input("Manager name:")
                        organisation=raw_input("Organisation name:")
                        age=raw_input("Age :")
                        EditEmployee(name,age,organisation,manager_name)
                elif choice=="d":
                        
                        name=raw_input("Employee name:")
                        deleteall(name)
                elif choice=="s":
                        
                        name=raw_input("Employee name:")
                        empDetails(name)
                elif choice=="q":
                        connection.close()
                        db.close()
                        
                        break

     # close database
#connection.close()
_______________________________________________
For more information about ZODB, see the ZODB Wiki:
http://www.zope.org/Wikis/ZODB/

ZODB-Dev mailing list  -  ZODB-Dev@zope.org
http://mail.zope.org/mailman/listinfo/zodb-dev

Reply via email to