Merge lp:~janos-gyerik/ubuntu-accomplishments-daemon/parse-the-optional-example-and-regex-sections-in-extrainformation into lp:ubuntu-accomplishments-daemon

Proposed by Janos Gyerik
Status: Merged
Merged at revision: 83
Proposed branch: lp:~janos-gyerik/ubuntu-accomplishments-daemon/parse-the-optional-example-and-regex-sections-in-extrainformation
Merge into: lp:ubuntu-accomplishments-daemon
Diff against target: 78 lines (+32/-2)
1 file modified
accomplishments/daemon/api.py (+32/-2)
To merge this branch: bzr merge lp:~janos-gyerik/ubuntu-accomplishments-daemon/parse-the-optional-example-and-regex-sections-in-extrainformation
Reviewer Review Type Date Requested Status
Ubuntu Accomplishments Daemon Developers Pending
Review via email: mp+111721@code.launchpad.net

Description of the change

Note the [example] and [regex] sections are still optional. If they are present in the extrainformation files, they will be parsed and passed on to dbus, so the client can get them when opening the identity screen with ctrl-i

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'accomplishments/daemon/api.py'
--- accomplishments/daemon/api.py 2012-06-12 20:23:01 +0000
+++ accomplishments/daemon/api.py 2012-06-23 18:42:17 +0000
@@ -628,6 +628,12 @@
628 for i in ei:628 for i in ei:
629 label = self.accDB[collection]['extra-information'][i]['label']629 label = self.accDB[collection]['extra-information'][i]['label']
630 desc = self.accDB[collection]['extra-information'][i]['description']630 desc = self.accDB[collection]['extra-information'][i]['description']
631 example = self.accDB[collection]['extra-information'][i].get('example')
632 if example is None:
633 example = ''
634 regex = self.accDB[collection]['extra-information'][i].get('regex')
635 if regex is None:
636 regex = ''
631 # we also need to know whether user has already set this item's value.637 # we also need to know whether user has already set this item's value.
632 # to do this, simply check whether trophies/.extrainformation/<item> file exists.638 # to do this, simply check whether trophies/.extrainformation/<item> file exists.
633 try:639 try:
@@ -642,6 +648,8 @@
642 "needs-information" : i,648 "needs-information" : i,
643 "label" : label,649 "label" : label,
644 "description" : desc,650 "description" : desc,
651 "example" : example,
652 "regex" : regex,
645 "value" : value}653 "value" : value}
646 except IOError as e:654 except IOError as e:
647 # we got an exception, so it seems that the file is not present - we'll use "" as the value, to indicate that it's empty655 # we got an exception, so it seems that the file is not present - we'll use "" as the value, to indicate that it's empty
@@ -649,7 +657,8 @@
649 "collection" : collection,657 "collection" : collection,
650 "needs-information" : i,658 "needs-information" : i,
651 "label" : label,659 "label" : label,
652 "description" : desc,660 "example" : example,
661 "regex" : regex,
653 "value" : ""}662 "value" : ""}
654663
655 # since the collected all data related to this particular ExtraInformation field, append it to the list664 # since the collected all data related to this particular ExtraInformation field, append it to the list
@@ -943,12 +952,14 @@
943 extrainfopath = os.path.join(extrainfodir,extrainfofile)952 extrainfopath = os.path.join(extrainfodir,extrainfofile)
944 eicfg = ConfigParser.RawConfigParser()953 eicfg = ConfigParser.RawConfigParser()
945 eicfg.read(extrainfopath)954 eicfg.read(extrainfopath)
955
946 if eicfg.has_option("label",self.lang):956 if eicfg.has_option("label",self.lang):
947 label = eicfg.get("label",self.lang)957 label = eicfg.get("label",self.lang)
948 elif eicfg.has_option("label",self.lang.split("_")[0]):958 elif eicfg.has_option("label",self.lang.split("_")[0]):
949 label = eicfg.get("label",self.lang.split("_")[0])959 label = eicfg.get("label",self.lang.split("_")[0])
950 else:960 else:
951 label = eicfg.get("label",langdefault)961 label = eicfg.get("label",langdefault)
962
952 if eicfg.has_option("description",self.lang):963 if eicfg.has_option("description",self.lang):
953 description = eicfg.get("description",self.lang)964 description = eicfg.get("description",self.lang)
954 elif eicfg.has_option("description",self.lang.split("_")[0]):965 elif eicfg.has_option("description",self.lang.split("_")[0]):
@@ -956,7 +967,26 @@
956 else:967 else:
957 description = eicfg.get("description",langdefault)968 description = eicfg.get("description",langdefault)
958 969
959 extrainfo[extrainfofile] = {'label':label,'description':description}970 if eicfg.has_option("example", self.lang):
971 example = eicfg.get("example", self.lang)
972 elif eicfg.has_option("example", self.lang.split("_")[0]):
973 example = eicfg.get("example", self.lang.split("_")[0])
974 elif eicfg.has_option("example", langdefault):
975 example = eicfg.get("example", langdefault)
976 else:
977 example = None
978
979 if eicfg.has_option("regex", "value"):
980 regex = eicfg.get("regex", "value")
981 else:
982 regex = None
983
984 extrainfo[extrainfofile] = {
985 'label': label,
986 'description': description,
987 'example': example,
988 'regex': regex,
989 }
960 990
961 # Store data about this colection991 # Store data about this colection
962 collectiondata = {'langdefault':langdefault,'name':collectionname, 'acc_num':accno, 'type':"collection", 'base-path': collpath, 'categories' : collcategories, 'extra-information': extrainfo, 'authors':collauthors}992 collectiondata = {'langdefault':langdefault,'name':collectionname, 'acc_num':accno, 'type':"collection", 'base-path': collpath, 'categories' : collcategories, 'extra-information': extrainfo, 'authors':collauthors}

Subscribers

People subscribed via source and target branches