Package schlachtfeld :: Package amov :: Package Skripte :: Package Kernskripte :: Package ein_und_ausgabe :: Module tag_zu_objekt
[hide private]
[frames] | no frames]

Source Code for Module schlachtfeld.amov.Skripte.Kernskripte.ein_und_ausgabe.tag_zu_objekt

 1  #!/bin/env python 
 2  # This Python file uses the following encoding=utf-8 
 3   
 4  # Amo - Allgemeine Modulare Objektverwaltung im lesbaren YAML Format 
 5  # Copyright © 2007 - 2007 Arne Babenhauserheide 
 6   
 7  # This program is free software; you can redistribute it and/or modify 
 8  # it under the terms of the GNU General Public License as published by 
 9  # the Free Software Foundation; either version 2 of the License, or 
10  # (at your option) any later version. 
11   
12  # This program is distributed in the hope that it will be useful, 
13  # but WITHOUT ANY WARRANTY; without even the implied warranty of 
14  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
15  # GNU General Public License for more details. 
16   
17  # You should have received a copy of the GNU General Public License 
18  # along with this program; if not, write to the Free Software 
19  # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, 
20  # MA 02110-1301 USA 
21   
22  # Dieses Skript übersetzt tag strings der Form 
23   
24  # tag:url,yyyy:name 
25   
26  # zu Objekten der Form (YAML-notiert):  
27   
28  # tag:  
29  #       Jahr: yyyy 
30  #       URL: url 
31  #       Name: Name 
32   
33  """Read a tag and return a dict with the 
34  tags information.""" 
35   
36 -class tag_zu_objekt:
37 """Read a tag and return a dict with the 38 tags information."""
39 - def __init__(self, tag):
40 self.tag = tag
41 - def tag_objekt(self):
42 43 # Erstmal definieren wir Grundformate. 44 FORMAT_JAHR = 'yyyy' 45 FORMAT_TAG = 'tag:' 46 # Und deren Längen. 47 length_yyyy = len(FORMAT_JAHR) 48 length_tag = len(FORMAT_TAG) 49 50 # Danach schmeißen wir den Prefix raus:'t ag:' 51 zwischenstring = self.tag[length_tag:] 52 # Dann müssen wir in der Lage sein den String zu teilen. 53 # Dafür suchen wir erstmal das Komma im String 54 ort_des_kommas = zwischenstring.find(',') 55 # Um Fehler auszuschließen, prüfen wir noch, ob mehr als ein Komma im tag vorkommt. TODO: Sauber schreiben! 56 anzahl_der_kommata = zwischenstring.count( ',' ) 57 if anzahl_der_kommata > 1: 58 print 'Meldung: Mehr als ein Komma im Tag! Prüfen!' 59 else: #print 'Meldung: Nur ein Komma im Tag. Alles OK' 60 pass 61 # Jetzt definieren wir uns die Funktion, 62 # die aus dem String ein Objekt macht. 63 URL = zwischenstring[:ort_des_kommas] 64 Jahr = zwischenstring[ort_des_kommas + 1:ort_des_kommas + length_yyyy + 1] 65 Name = zwischenstring[ort_des_kommas + length_yyyy + 2:] 66 tag_dict = {} 67 tag_dict['URL'] = URL 68 tag_dict['Jahr'] = Jahr 69 tag_dict['Name'] = Name 70 return tag_dict
71 72 # und rufen sie auf. 73