← Back to team overview

mlhim-specs-dev team mailing list archive

[Branch ~cdd-dev/cdd/trunk] Rev 181: Integrate the generator into CDD.

 

------------------------------------------------------------
revno: 181
committer: Eduardo César <xcesar@xxxxxxxxx>
branch nick: cdd
timestamp: Thu 2012-07-19 19:21:28 -0300
message:
  Integrate the generator into CDD.
modified:
  src/cdd.py
  src/cdg_custom.py
  src/cdg_extra.py
  src/cdg_main.py


--
lp:cdd
https://code.launchpad.net/~cdd-dev/cdd/trunk

Your team MLHIM Specifications Developers is subscribed to branch lp:cdd.
To unsubscribe from this branch go to https://code.launchpad.net/~cdd-dev/cdd/trunk/+edit-subscription
=== modified file 'src/cdd.py'
--- src/cdd.py	2012-07-18 01:11:04 +0000
+++ src/cdd.py	2012-07-19 22:21:28 +0000
@@ -7,12 +7,18 @@
 import wx
 from wx.lib.wordwrap import wordwrap
 
+import cdg_custom
+import cdg_extra
 import mlhim2
 
 gettext.bindtextdomain('CDD','locales/en')
 gettext.textdomain('CDD')
 _ = gettext.gettext
 
+
+#Where the info will be stored
+info = cdg_custom.Info()
+
 class MainFrame(wx.Frame):
     def __init__(self, parent, id):
         super(MainFrame, self).__init__(parent,
@@ -154,6 +160,7 @@
             _data = mlhim2.Metadata(self)
             result = _data.ShowModal()
             if result == wx.ID_OK:
+                cdg_extra.extract_info(_data, info)
                 _data.c.get_panel_configs()
                 _data.c.save_config()
 
@@ -286,13 +293,25 @@
         dlg.Destroy()
 
     def genFile(self, evt):
-#TODO: Eduardo to add the generator portion here.
-        msg = "File->Generate Not Yet Implemented."
-        dlg = wx.MessageDialog(self, msg,
-                               'Menu Msg.',
-                               wx.OK | wx.ICON_INFORMATION)
-        dlg.ShowModal()
-        dlg.Destroy()
+
+        
+        # Get the path
+        path = cdg_extra.get_path(self)
+        if not path:
+            return
+
+        info.generate_file(path)
+        # Show dialog
+        cdg_extra.popup_message(self, '%s.xsd' % info.ccd_id, 'Generated the file', wx.OK | wx.ICON_INFORMATION)
+
+
+        #TODO: Eduardo to add the generator portion here.
+        # msg = "File->Generate Not Yet Implemented."
+        # dlg = wx.MessageDialog(self, msg,
+        #                        'Menu Msg.',
+        #                        wx.OK | wx.ICON_INFORMATION)
+        # dlg.ShowModal()
+        # dlg.Destroy()
 
     def onQuit(self, e):
         dlg = wx.MessageDialog(self,

=== modified file 'src/cdg_custom.py'
--- src/cdg_custom.py	2012-07-18 00:27:38 +0000
+++ src/cdg_custom.py	2012-07-19 22:21:28 +0000
@@ -4,22 +4,61 @@
 import ConfigParser
 from xml.sax.saxutils import escape
 
-def generate_files(path, title, description, date, creator, creator_email, contributor, language, publisher, subject, source, rights, relation, coverage):
-
-    choice_definition = "String"
-    ccd_id = "ccd_"+str(uuid.uuid4()).replace('-','_')
-    UUID_definition = "ct_"+str(uuid.uuid4()).replace('-','_')
-    UUID_string = "ct_"+str(uuid.uuid4()).replace('-','_')
-
-    schema = ccd_id + ".xsd"
-
-    contributors_formated = '<dc:contributor>' + \
-        '</dc:contributor>\n<dc:contributor>'.join([ escape(i).strip() for i in contributor.split(';')]) + \
-        '</dc:contributor>'
-
-    f = open(path+'/'+schema,'w')
-
-    f.write("""<?xml version="1.1" encoding="UTF-8"?>
+class Info(object):
+    def __init__(self):
+        self.title = ''
+        self.description = ''
+        self.creator = ''
+        self.creator_email = ''
+        self.contributor = ''
+
+        self.publisher = ''
+        self.subject = ''
+        self.source = ''
+        self.rights = ''
+        self.relation = ''
+        self.coverage = ''
+
+        self.language = ''
+
+        self.date = ''
+
+        self.ccd_id = "ccd_"+str(uuid.uuid4()).replace('-','_')
+
+    def get_info(self, title, description, date, creator, creator_email, contributor, language, publisher, subject, source, rights, relation, coverage):
+        self.title = title 
+        self.description = description 
+        self.creator = creator 
+        self.creator_email = creator_email 
+        self.contributor = contributor 
+
+        self.publisher = publisher 
+        self.subject = subject 
+        self.source = source 
+        self.rights = rights 
+        self.relation = relation 
+        self.coverage = coverage 
+
+        self.language = language 
+
+        self.date = date
+
+
+    def generate_file(self, path):
+
+
+        UUID_definition = "ct_"+str(uuid.uuid4()).replace('-','_')
+        UUID_string = "ct_"+str(uuid.uuid4()).replace('-','_')
+
+        schema = self.ccd_id + ".xsd"
+
+        contributors_formated = '<dc:contributor>' + \
+            '</dc:contributor>\n<dc:contributor>'.join([ escape(i).strip() for i in self.contributor.split(';')]) + \
+            '</dc:contributor>'
+
+        f = open(path+'/'+schema,'w')
+
+        f.write("""<?xml version="1.1" encoding="UTF-8"?>
 
 <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema";
 	   xmlns:mlhim2="http://www.mlhim.org/xmls/mlhim2/2_3_0";
@@ -73,9 +112,9 @@
 
   <xs:complexType name="{UUID_definition}">
     <xs:complexContent>
-    <xs:restriction base="mlhim2:{choice}">
+    <xs:restriction base="mlhim2:String">
 	<xs:sequence>
-	  <xs:element name="{choice_dv}"  minOccurs="1"  maxOccurs="1" type="mlhim2:{UUID_DvString}"/>
+	  <xs:element name="String_dv"  minOccurs="1"  maxOccurs="1" type="mlhim2:{UUID_DvString}"/>
    	</xs:sequence>
     </xs:restriction>
     </xs:complexContent>
@@ -93,45 +132,40 @@
   </xs:complexType>
 
 </xs:schema>
-""".format(ccd_id = ccd_id,
+""".format(ccd_id = self.ccd_id,
            UUID_definition = UUID_definition,
            UUID_DvString = UUID_string,
 
-           choice = choice_definition,
-           choice_dv = choice_definition[:-4] + '_dv',
-
-           title = escape(title),
-           description = escape(description),
-           date = date,
-           creator = escape(creator),
-           creator_email = escape(creator_email),
+           title = escape(self.title),
+           description = escape(self.description),
+           date = self.date,
+           creator = escape(self.creator),
+           creator_email = escape(self.creator_email),
            contributors = contributors_formated,
-           language = language,
-           publisher = escape(publisher),
-           subject = escape(subject),
-           source = escape(source),
-           rights = escape(rights),
-           relation = escape(relation),
-           coverage = escape(coverage),
+           language = self.language,
+           publisher = escape(self.publisher),
+           subject = escape(self.subject),
+           source = escape(self.source),
+           rights = escape(self.rights),
+           relation = escape(self.relation),
+           coverage = escape(self.coverage),
 
            resource_type = "MLHIM Concept Constraint Definition (CCD)",
            resource_format = "text/xml",
-           identifier = ccd_id,
+           identifier = self.ccd_id,
 
            ))
 
 
-    f.write("<!-- Here are some UUIDs to use for complexType names:\n\n")
-
-    for x in range(0,10):
-        f.write("ct_"+str(uuid.uuid4()).replace('-','_')+"\n\n")
-
-    f.write("-->")
-
-    f.close()
-    return ccd_id
-
-# TODO: Make a class to put the config part
+        f.write("<!-- Here are some UUIDs to use for complexType names:\n\n")
+
+        for x in range(0,10):
+            f.write("ct_"+str(uuid.uuid4()).replace('-','_')+"\n\n")
+
+        f.write("-->")
+
+        f.close()
+
 class Config(object):
     def __init__(self, panel):
 

=== modified file 'src/cdg_extra.py'
--- src/cdg_extra.py	2012-07-18 01:11:04 +0000
+++ src/cdg_extra.py	2012-07-19 22:21:28 +0000
@@ -21,6 +21,8 @@
                            )
     dlg.ShowModal()
     dlg.Destroy()
+
+
 def get_lang_list():
     l = list(set(locale.locale_alias.keys()))
     l.sort()
@@ -28,6 +30,26 @@
 
     return l2
 
+def get_path(self):
+    path = os.getcwd()
+
+    dlg = wx.DirDialog(self, "Choose a directory to put the generated files:",
+                       path,
+                       style=wx.DD_DEFAULT_STYLE
+                       #| wx.DD_DIR_MUST_EXIST
+                       #| wx.DD_CHANGE_DIR
+                       )
+
+
+    if dlg.ShowModal() == wx.ID_OK:
+        path = dlg.GetPath()
+    else:
+        return None
+
+    dlg.Destroy()
+    return path
+
+
 def popup_message(self, msg, tag, icons):
     dlg = wx.MessageDialog(self, msg, tag, icons)
     result = dlg.ShowModal()
@@ -36,3 +58,30 @@
         return True
     else:
         return False
+
+def extract_info(self, info):
+        title = self.text_ctrl_title.GetValue().encode('utf8')
+        description = self.text_ctrl_description.GetValue().encode('utf8')
+        creator = self.text_ctrl_creator.GetValue().encode('utf8')
+        creator_email = self.text_ctrl_creator_email.GetValue().encode('utf8')
+        contributor = self.text_ctrl_contributors.GetValue().encode('utf8')
+
+        publisher = self.text_ctrl_publisher.GetValue().encode('utf8')
+        subject = self.text_ctrl_subject.GetValue().encode('utf8')
+        source = self.text_ctrl_source.GetValue().encode('utf8')
+        rights = self.text_ctrl_rights.GetValue().encode('utf8')
+        relation = self.text_ctrl_relation.GetValue().encode('utf8')
+        coverage = self.text_ctrl_coverage.GetValue().encode('utf8')
+
+        language = self.choice_lang.GetStringSelection()
+
+        tempo = self.datepicker_ctrl_date.GetValue()
+        date = '{Y}-{M}-{D:02}'.format(Y=tempo.GetYear(), M=tempo.GetMonth(), D=tempo.GetDay())
+
+        info.get_info(title, description, date, creator, creator_email, contributor, language, publisher, subject, source, rights, relation, coverage)
+        # # Test if the mandatary fields are with something
+        # if not (title and date and description and creator and subject and rights):
+        #     cdg_extra.popup_message(self, 'The options marker with a "*" are mandatory. Please fill them before generating a CCD file.', 'Error', wx.OK|wx.ICON_EXCLAMATION)
+        #     return False
+        # return True
+        ################################################

=== modified file 'src/cdg_main.py'
--- src/cdg_main.py	2012-07-18 00:27:38 +0000
+++ src/cdg_main.py	2012-07-19 22:21:28 +0000
@@ -135,44 +135,6 @@
         self.Centre()
         # end wxGlade
 
-    def generate(self, event):  # wxGlade: MainDialog.<event_handler>
-        title = self.text_ctrl_title.GetValue().encode('utf8')
-        description = self.text_ctrl_description.GetValue().encode('utf8')
-        creator = self.text_ctrl_creator.GetValue().encode('utf8')
-        creator_email = self.text_ctrl_creator_email.GetValue().encode('utf8')
-        contributor = self.text_ctrl_contributors.GetValue().encode('utf8')
-
-        publisher = self.text_ctrl_publisher.GetValue().encode('utf8')
-        subject = self.text_ctrl_subject.GetValue().encode('utf8')
-        source = self.text_ctrl_source.GetValue().encode('utf8')
-        rights = self.text_ctrl_rights.GetValue().encode('utf8')
-        relation = self.text_ctrl_relation.GetValue().encode('utf8')
-        coverage = self.text_ctrl_coverage.GetValue().encode('utf8')
-
-        language = self.choice_lang.GetStringSelection()
-
-        tempo = self.datepicker_ctrl_date.GetValue()
-        date = '{Y}-{M}-{D:02}'.format(Y=tempo.GetYear(), M=tempo.GetMonth(), D=tempo.GetDay())
-
-
-        # Test if the mandatary fields are with something
-        if not (title and date and description and creator and subject and rights):
-            cdg_extra.popup_message(self, 'The options marker with a "*" are mandatory. Please fill them before generating a CCD file.', 'Error', wx.OK|wx.ICON_EXCLAMATION)
-            return
-        ################################################
-
-        # Get the path
-        path = cdg_extra.get_path(self)
-        if not path:
-            return
-
-
-        # Call the writing routine
-        ccd_id = cdg_custom.generate_files(path, title, description, date, creator, creator_email, contributor, language, publisher, subject, source, rights, relation, coverage)
-
-
-        # Show dialog
-        cdg_extra.popup_message(self, '%s.xsd' % ccd_id, 'Generated the file', wx.OK | wx.ICON_INFORMATION)
 
     def init_things(self):
         self.c = cdg_custom.Config(self)