Commits

Rob Lanphier committed bd1e5cf

Added jsonaddress alias and beefed up address book schema
The address book schema is now closer to the Portable Contacts spec:
http://portablecontacts.net/draft-spec.html
However, it's not fully conformant.

  • Participants
  • Parent commits aad1e68

Comments (0)

Files changed (3)

 Things to get done before version 0.1
 
 On deck:
-*  Add alias for editing address books
+*  Remove hardcoded 20 character label column
 
 Roadmap
 0.1.0:
+*  Remove hardcoded 13 character "Add field" button width
 *  Graceful error on mismatched schema
 *  Minimal check for urwid and simpleparse (and look for /etc/lsb-release to 
    figure out the right error message)
 *  Improve documentation in __init__.py
-*  Remove hardcoded 20 character label column
-*  Remove hardcoded 13 character "Add field" button width
 *  Put "Add field" over in the data area
 *  "Space" and "enter" should toggle expand/collapse on parent nodes
 
 *  Keep item highlighted while deleting
 *  Change "add fields" to "add items" for sequences
 *  Clean up imports in "jsonedit"
+*  Add alias for editing address books
 
+#!/usr/bin/python -tt
+# jsonaddress - urwid-based JSON address book editor
+#
+# Copyright (c) 2010, Rob Lanphier
+# All rights reserved.
+# Licensed under BSD-style license.  See LICENSE.txt for details.
+
+import optparse
+import sys
+import jsonwidget.termedit
+
+def run_editor(addressbook):
+    form = jsonwidget.termedit.JsonEditor(jsonfile=addressbook, 
+                                          schemafile="schema/addressbookschema.json",
+                                          program_name="jsonaddress 0.1pre")
+    form.run()
+
+
+def main():
+    '''standard option parsing stuff'''
+    usage = "usage: %prog [options] arg"
+    parser = optparse.OptionParser(usage)
+    (options, args) = parser.parse_args()
+
+    if len(args) > 1:
+        parser.error("Too many arguments." +
+                     "  Just one adddressbook file at a time, please.")
+    if len(args) == 1:
+        addressbook = args[0]
+    else:
+        addressbook = None
+    run_editor(addressbook)
+
+if __name__ == "__main__":
+    main()
+

schema/addressbookschema.json

           "title":"Last Name",
           "required":true
         },
-        "address":
+        "organizations":
         {
-          "type":"map",
-          "title":"Address",
-          "mapping":
-          {
-            "streetAddress":
+          "type":"seq",
+          "title":"Affiliations",
+          "sequence":
+          [
             {
-              "type":"str",
-              "title":"Street Address",
-              "required":true
-            },
-            "city":
+              "type":"map",
+              "required":true,
+              "mapping":
+              {
+                "name":
+                {
+                  "type":"str",
+                  "required":true,
+                  "title":"Organization Name"
+                },
+                "title":
+                {
+                  "type":"str",
+                  "title":"Title/Role"
+                },
+                "department":
+                {
+                  "type":"str",
+                  "title":"Department"
+                },
+                "type":
+                {
+                  "type":"str",
+                  "enum":
+                  [
+                    "job",
+                    "school",
+                    "other"
+                  ],
+                  "title":"Type"
+                }
+              },
+              "title":"Organization"
+            }
+          ]
+        },
+        "addresses":
+        {
+          "type":"seq",
+          "title":"Addresses",
+          "sequence":
+          [
             {
-              "type":"str",
-              "title":"City",
-              "required":true
-            },
-            "state":
-            {
-              "type":"str",
-              "title":"State",
-              "required":true
-            },
-            "postalCode":
-            {
-              "type":"str",
-              "title":"Postal (Zip) Code",
-              "required":true
+              "type":"map",
+              "title":"Address",
+              "required":true,
+              "mapping":
+              {
+                "streetAddress":
+                {
+                  "type":"str",
+                  "title":"Street Address",
+                  "required":true
+                },
+                "locality":
+                {
+                  "type":"str",
+                  "title":"City (locality)",
+                  "required":true
+                },
+                "region":
+                {
+                  "type":"str",
+                  "title":"State/Provence/Region",
+                  "required":true
+                },
+                "postalCode":
+                {
+                  "type":"str",
+                  "title":"Postal (Zip) Code",
+                  "required":true
+                },
+                "country":
+                {
+                  "type":"str",
+                  "title":"Country",
+                  "required":true
+                }
+              }
             }
-          }
+          ]
         },
         "phoneNumbers":
         {
               }
             }
           ]
+        },
+        "emails":
+        {
+          "type":"seq",
+          "title":"Email addresses",
+          "sequence":
+          [
+            {
+              "type":"map",
+              "title":"Email",
+              "required":true,
+              "mapping":
+              {
+                "type":
+                {
+                  "type":"str",
+                  "required":true,
+                  "title":"Work/Home/Other",
+                  "enum":
+                  [
+                    "work",
+                    "home",
+                    "other"
+                  ]
+                },
+                "value":
+                {
+                  "type":"str",
+                  "required":true,
+                  "title":"Address"
+                },
+                "primary":
+                {
+                  "type":"bool",
+                  "required":true,
+                  "title":"Primary?"
+                }
+              }
+            }
+          ]
+        },
+        "ims":
+        {
+          "type":"seq",
+          "title":"IMs (Instant Messaging Accounts)",
+          "sequence":
+          [
+            {
+              "type":"map",
+              "title":"Account",
+              "required":true,
+              "mapping":
+              {
+                "type":
+                {
+                  "type":"str",
+                  "required":true,
+                  "title":"Service",
+                  "enum":
+                  [
+                    "aim",
+                    "gtalk",
+                    "icq",
+                    "xmpp",
+                    "msn",
+                    "skype",
+                    "qq",
+                    "yahoo"
+                  ],
+                  "desc_enum":
+                  {
+                    "aim":"AIM (AOL)",
+                    "gtalk":"GTalk (Google)",
+                    "icq":"ICQ",
+                    "xmpp":"XMPP/Jabber",
+                    "msn":"MSN (Microsoft)",
+                    "skype":"Skype",
+                    "qq":"QQ (Tencent)",
+                    "yahoo":"Yahoo!"
+                  }
+                },
+                "value":
+                {
+                  "type":"str",
+                  "required":true,
+                  "title":"Account ID"
+                }
+              }
+            }
+          ]
         }
       }
     }