コード例 #1
0
ファイル: wfile.py プロジェクト: kalininei/Tacma
    def write_data(self, fn=None):
        'saves current state to self.fname'
        root = ET.Element('TacmaData')
        root.attrib['version'] = tacmaopt.opt.ver
        #start date
        d = ET.SubElement(root, 'START_DATE')
        ET.SubElement(d, 'YEAR').text = str(self.start_date.year)
        ET.SubElement(d, 'MONTH').text = str(self.start_date.month)
        ET.SubElement(d, 'DAY').text = str(self.start_date.day)
        ET.SubElement(d, 'HOUR').text = str(self.start_date.hour)
        ET.SubElement(d, 'MIN').text = str(self.start_date.minute)
        ET.SubElement(d, 'SEC').text = str(self.start_date.second)
        #save date
        ET.SubElement(root, 'SAVE_TIME').text = \
                str(self.time_to_int(datetime.utcnow()))

        #actions
        d = ET.SubElement(root, 'ACTIONS')
        for a in self.acts:
            a.save_to_xml(d)

        #write to file
        bproc.xmlindent(root)
        tree = ET.ElementTree(root)
        if fn is None:
            fn = self.fname
        tree.write(fn, xml_declaration=True, encoding='utf-8')
コード例 #2
0
ファイル: wfile.py プロジェクト: kalininei/Tacma
    def write_data(self, fn=None):
        tm = self.time_to_int(datetime.utcnow())
        # check for archivation only in regular saves
        if fn is None:
            tm = self.archivate_if_needed(tm)
        'saves current state to self.fname'
        root = ET.Element('TacmaData')
        root.attrib['version'] = tacmaopt.opt.ver
        #start date
        d = ET.SubElement(root, 'START_DATE')
        ET.SubElement(d, 'YEAR').text = str(self.start_date.year)
        ET.SubElement(d, 'MONTH').text = str(self.start_date.month)
        ET.SubElement(d, 'DAY').text = str(self.start_date.day)
        ET.SubElement(d, 'HOUR').text = str(self.start_date.hour)
        ET.SubElement(d, 'MIN').text = str(self.start_date.minute)
        ET.SubElement(d, 'SEC').text = str(self.start_date.second)
        #previous data
        if self.previous_fn is not None:
            ET.SubElement(root, 'PREV_DATA').text = self.previous_fn
        #save date
        ET.SubElement(root, 'SAVE_TIME').text = str(tm)

        #actions
        d = ET.SubElement(root, 'ACTIONS')
        for a in self.acts:
            a.save_to_xml(d)

        #write to file
        bproc.xmlindent(root)
        tree = ET.ElementTree(root)
        if fn is None:
            fn = self.fname
        tree.write(fn, xml_declaration=True, encoding='utf-8')
コード例 #3
0
    def write(self):
        'writes options to default file'
        root = ET.Element('TacmaOptions')
        root.attrib['version'] = self.ver

        ET.SubElement(root, 'ADATAFILE').text = os.path.basename(self.wfile)
        ET.SubElement(root, 'ASAVE_INTERVAL').text = str(self.autosave)
        ET.SubElement(root, 'BDATAFILE').text = \
            os.path.basename(self.backup_fn)
        ET.SubElement(root, 'BSAVE_INTERVAL').text = str(self.backup_autosave)
        w = ET.SubElement(root, 'MAIN_WINDOW')
        ET.SubElement(w, 'HX').text = str(self.Hx)
        ET.SubElement(w, 'HY').text = str(self.Hy)
        ET.SubElement(w, 'X0').text = str(self.x0)
        ET.SubElement(w, 'Y0').text = str(self.y0)
        w = ET.SubElement(root, 'EDIT_WINDOW')
        ET.SubElement(w, 'HX').text = str(self.edit_window_Hx)
        ET.SubElement(w, 'HY').text = str(self.edit_window_Hy)
        ET.SubElement(w, 'X0').text = str(self.edit_window_x0)
        ET.SubElement(w, 'Y0').text = str(self.edit_window_y0)
        w = ET.SubElement(root, 'MOD_WINDOW')
        ET.SubElement(w, 'HX').text = str(self.mod_window_Hx)
        ET.SubElement(w, 'HY').text = str(self.mod_window_Hy)
        ET.SubElement(w, 'X0').text = str(self.mod_window_x0)
        ET.SubElement(w, 'Y0').text = str(self.mod_window_y0)
        w = ET.SubElement(root, 'COLUMN_OPTIONS')
        ks = self.colwidths.keys() + self.colvisible.keys()
        for k in set(ks):
            w1 = ET.SubElement(w, 'COL')
            w1.attrib['id'] = k
            try:
                v = self.colwidths[k]
                ET.SubElement(w1, 'WIDTH').text = str(v)
            except:
                pass
            try:
                v = self.colvisible[k]
                ET.SubElement(w1, 'VIS').text = str(int(v))
            except:
                pass
        ET.SubElement(root, 'UPDATE_INT').text = str(self.update_interval)
        ET.SubElement(root, 'ARCHIVATE').text = str(self.archivate)
        ET.SubElement(root, 'MINACTUAL').text = str(self.minactual)

        bproc.xmlindent(root)
        tree = ET.ElementTree(root)
        tree.write(self.opt_fn, xml_declaration=True, encoding='utf-8')
        print "written"