Codes divers: Check-in [6878617b04]

Divers bouts de code de ma composition

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Fix obvious bugs and display in buddies.py
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:6878617b047f4b79a99d4eb4c5ee3b64bac272ab
User & Date: milouse 2019-12-18 23:20:34
Context
2019-12-19
19:03
Another bug fix and improvement cycle on buddies.py Leaf check-in: cce3312fc0 user: milouse tags: trunk
2019-12-18
23:20
Fix obvious bugs and display in buddies.py check-in: 6878617b04 user: milouse tags: trunk
21:10
Add a new script, which allow to browse contacts in a vdir collection check-in: fa1a1fa487 user: milouse tags: trunk
Changes

Changes to buddies.py.


1
2
3
4
5
6
7
...
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132




133
134
135
136

137
138
139
140
141
142
143
144
145
146
147
148
149
...
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
...
231
232
233
234
235
236
237
238


239
240
241
242
243
244
245
...
260
261
262
263
264
265
266

267



268



269
270
271
272
273
274
275
276
277

import os
import re
import sys
import glob
import base64
import subprocess
from argparse import ArgumentParser
................................................................................
            values = [
                (v["value"], v["headers"].get("type", "other"))
                for v in content
            ]
            return list(values)
        return content.get("value", "")

    def _format_lines(self, title, value):
        if isinstance(value, list):
            results = []
            for v in value:
                if isinstance(v[1], list):
                    val = ", ".join(v[1])
                else:
                    val = v[1]
                results.append(("{}[{}]".format(title, val), v[0]))
            return results




        return [(title, value)]

    def __str__(self):
        data = self._format_lines("id", self.get("uid"))

        data += self._format_lines("Phone", self.get("tel"))
        data += self._format_lines("Email", self.get("email"))
        if self.get("photo") == "":
            data += self._format_lines("Has Photo", "no")
        else:
            data += self._format_lines("Has Photo", "yes")

        max_len = 0
        for line in data:
            n = len(line[0])
            if n > max_len:
                max_len = n

................................................................................
        if name == "":
            lines = ["Anonymous"]
        else:
            lines = [name]
        lines.append("-" * len(lines[0]))

        for line in data:
            lines.append("{}: {}".format(line[0].rjust(max_len), line[1]))
        lines.append("")
        return "\n".join(lines)

    def __repr__(self):
        return "[" + ", ".join(self.atoms.keys()) + "]"

    def __getattr__(self, name):
................................................................................
        # Compile regexp once for all
        queryx = [re.compile(q, re.I) for q in query]
        for mate in vcf_files:
            m = VCardParser(mate)
            email = m.get("email")
            if isinstance(email, list):
                email = " ".join([e[0] for e in email])
            data = " ".join([m.get("fn"), email]).strip()


            for qx in queryx:
                if qx.search(data) is None:
                    continue
                vcards.append(m)
                # One match is sufficient
                break
        return vcards
................................................................................
        else:
            template = "{name} <{email}>"
        name = card.get("fn")
        val = card.get("email")
        if val == "":
            return
        if isinstance(val, list):

            for v in val:



                print(template.format(name=name, email=v))



        else:
            print(template.format(name=name, email=val))

    def print_mutt(self, card):
        self.print_email(card, True)

    def open_photo(self, card):
        photo = card.get("photo")
        if photo == "":
>







 







|







|

>
>
>
>




>



|

|







 







|







 







|
>
>







 







>

>
>
>
|
>
>
>

|







1
2
3
4
5
6
7
8
...
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
...
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
...
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
...
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
#!/usr/bin/env python
import os
import re
import sys
import glob
import base64
import subprocess
from argparse import ArgumentParser
................................................................................
            values = [
                (v["value"], v["headers"].get("type", "other"))
                for v in content
            ]
            return list(values)
        return content.get("value", "")

    def _format_lines(self, title, value, default=None):
        if isinstance(value, list):
            results = []
            for v in value:
                if isinstance(v[1], list):
                    val = ", ".join(v[1])
                else:
                    val = v[1]
                results.append((title, "{} ({})".format(v[0], val)))
            return results
        if value == "":
            if default is None:
                return []
            value = default
        return [(title, value)]

    def __str__(self):
        data = self._format_lines("id", self.get("uid"))
        data = self._format_lines("Nick", self.get("nickname"))
        data += self._format_lines("Phone", self.get("tel"))
        data += self._format_lines("Email", self.get("email"))
        if self.get("photo") == "":
            data += self._format_lines("Photo", "no")
        else:
            data += self._format_lines("Photo", "yes")

        max_len = 0
        for line in data:
            n = len(line[0])
            if n > max_len:
                max_len = n

................................................................................
        if name == "":
            lines = ["Anonymous"]
        else:
            lines = [name]
        lines.append("-" * len(lines[0]))

        for line in data:
            lines.append("{}: {}".format(line[0].ljust(max_len), line[1]))
        lines.append("")
        return "\n".join(lines)

    def __repr__(self):
        return "[" + ", ".join(self.atoms.keys()) + "]"

    def __getattr__(self, name):
................................................................................
        # Compile regexp once for all
        queryx = [re.compile(q, re.I) for q in query]
        for mate in vcf_files:
            m = VCardParser(mate)
            email = m.get("email")
            if isinstance(email, list):
                email = " ".join([e[0] for e in email])
            data = " ".join(
                [m.get("fn"), email, m.get("nickname")]
            ).strip()
            for qx in queryx:
                if qx.search(data) is None:
                    continue
                vcards.append(m)
                # One match is sufficient
                break
        return vcards
................................................................................
        else:
            template = "{name} <{email}>"
        name = card.get("fn")
        val = card.get("email")
        if val == "":
            return
        if isinstance(val, list):
            answer = []
            for v in val:
                if "pref" in v[1]:
                    # There is a preferred value. Print only the first
                    # one found
                    print(template.format(name=name, email=v[0]))
                    return
                answer.append(template.format(name=name, email=v[0]))
            print("\n".join(answer))
        else:
            print(template.format(name=name, email=val[0]))

    def print_mutt(self, card):
        self.print_email(card, True)

    def open_photo(self, card):
        photo = card.get("photo")
        if photo == "":