1. Vincenzo Ampolo
  2. Bluebat

Commits

Fabio Pozzi  committed ece30fc

changed the Element tree handling, added xml file initialization, fixed path handling, basic functionality now is working

  • Participants
  • Parent commits 30b78a5
  • Branches default

Comments (0)

Files changed (1)

File bluebatClient.py

View file
         from the previous execution
         """
         self.__output = open("data.xml","w+")
+        #init the data.xml file
+        root = ET.Element("root")
+        tree = ET.ElementTree(root)
+        tree.write("data.xml")
+
         LOG_FILENAME = 'logs.log'
         logging.basicConfig(filename=LOG_FILENAME,level=logging.INFO)
 
         """
         self.__output.close()
 
-    """
-    hack to obtain something similar to synchronized methods
-    TODO: Puo' essere utile??
-    """
-    #def synchronized(L):
-    #    def lock_around(f):
-    #        def locked(*a, **k):
-    #            with L:
-    #                return f(*a, **k)
-    #        locked.__name__ = f.__name__
-    #        locked.__doc__ = f.__doc__
-    #        return locked
-    #    return lock_around
-
-
     def update_file(self,msg):
         """
         Add data to the data.xml file
         self.__output.close()
         self.__output = open("data.xml","w")
 
-    def open_log(self, logpath):
-        
-
-#logger = logging.getLogger(logpath)
-        #hdlr = logging.FileHandler('log.txt')
-        #formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s')
-        #hdlr.setFormatter(formatter)
-        #logger.addHandler(hdlr)
-        #logger.setLevel(logging.INFO)
-        return logger
-
     def quit(self):
         """
         when called it quits gracefully the program
 
         while(1):
             time.sleep(5)            
-            for root, dirs, files in os.walk('/tmp/sobexfiles'):
-                for name in files:
-                    logging.info("bluebat.client.sobexsrv received %s" % name)
+            for rootp, dirs, files in os.walk('/tmp/sobexfiles'):
+                for n in files:
+                    logging.info("bluebat.client.sobexsrv received %s" % n)
                     #logger.info("received {0}".format(name))
-                    f = open(name)
+                    filename =  os.path.join(rootp,n)
+                    
+                    f = open(filename)
                     buf = f.read()
                     f.close()
                     
                     e = base64.b64encode(buf) #encode the file
                     
-                    tree = ElementTree(file="data.xml") # read the xml tree of data.xml
+                    tree = ET.parse("data.xml") # read the xml tree of data.xml
+                        
                     root = tree.getroot() # get the root node
+
                     el = ET.SubElement(root,"communication") #create a subelement
                     # build the substructure
                     el.set("address","unknow")
                     el.set("protocol","OBEX-PUSH")
                     f = ET.SubElement(el,"file")
                     f.set("encoded","base64")
-                    f.set("name", name)
+                    f.set("name", n)
                     f.text = e # put the encoded file into the text field
                     tree.write("data.xml") # write back the tree to disk
 
-                    p = os.path.join(root, name) # get the full path
+                    p = os.path.join(rootp, n) # get the full path
                     os.remove(p) #remove the file from the disk
 
                     logging.info("bluebat.client.sobexsrv File included in data.xml")
 
         enc_data = base64.b64encode(data) #encode the received data
 
-        tree = ElementTree(file="data.xml") # read the xml tree of data.xml
+        tree = ET(file="data.xml") # read the xml tree of data.xml
         root = tree.getroot() # get the root node
         el = ET.SubElement(root,"communication") #create a subelement