From: W. Trevor King Date: Sat, 20 Feb 2010 18:12:38 +0000 (-0500) Subject: Merged Gianluca's truncated-IDs in `be html` output patch. X-Git-Tag: 1.0.0~59^2~10 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=4d1e4ad8aa2cb42648de90966cef904b555f9de9;p=be.git Merged Gianluca's truncated-IDs in `be html` output patch. Or at least merged the general idea. Changes in the implementation listed in #bea/01e/2f9#. --- 4d1e4ad8aa2cb42648de90966cef904b555f9de9 diff --cc .be/bea86499-824e-4e77-b085-2d581fa9ccab/bugs/01e7151c-6113-4c8f-9fc5-4d594431bd2b/comments/2f9beed6-4008-442a-8d44-a45cb7ce0a36/body index 0000000,0000000..d20af30 new file mode 100644 --- /dev/null +++ b/.be/bea86499-824e-4e77-b085-2d581fa9ccab/bugs/01e7151c-6113-4c8f-9fc5-4d594431bd2b/comments/2f9beed6-4008-442a-8d44-a45cb7ce0a36/body @@@ -1,0 -1,0 +1,9 @@@ ++I'm not sure that changing the URLs is a good idea. I'd rather use ++.htaccess and mod_rewrite to redirect short URLs to their permanent ++long equivalents. Nobody else seems to mind though, so I've merged ++Gianluca's solution with a few changes: ++ * Since we're truncating bug IDs, truncate comment IDs too. ++ * Use libbe.util.id._truncate to generate the short IDs, so that `be ++ html` truncation is consistent with general BE truncation. ++ * Updated cross-linking code to match. ++ diff --cc .be/bea86499-824e-4e77-b085-2d581fa9ccab/bugs/01e7151c-6113-4c8f-9fc5-4d594431bd2b/comments/2f9beed6-4008-442a-8d44-a45cb7ce0a36/values index 0000000,0000000..c7365f5 new file mode 100644 --- /dev/null +++ b/.be/bea86499-824e-4e77-b085-2d581fa9ccab/bugs/01e7151c-6113-4c8f-9fc5-4d594431bd2b/comments/2f9beed6-4008-442a-8d44-a45cb7ce0a36/values @@@ -1,0 -1,0 +1,8 @@@ ++Author: W. Trevor King ++ ++ ++Content-type: text/plain ++ ++ ++Date: Sat, 20 Feb 2010 18:10:42 +0000 ++ diff --cc .be/bea86499-824e-4e77-b085-2d581fa9ccab/bugs/01e7151c-6113-4c8f-9fc5-4d594431bd2b/values index 673423e,673423e..9efe209 --- a/.be/bea86499-824e-4e77-b085-2d581fa9ccab/bugs/01e7151c-6113-4c8f-9fc5-4d594431bd2b/values +++ b/.be/bea86499-824e-4e77-b085-2d581fa9ccab/bugs/01e7151c-6113-4c8f-9fc5-4d594431bd2b/values @@@ -7,7 -7,7 +7,7 @@@ reporter: Gianluca Montecchi > self.stdout, \ @@@ -171,6 -173,32 +173,16 @@@ bugs_inactive, title=self.title, index_header=self.index_header, bug_type='inactive') - def _create_file_name(self, bugid): - s = 4 - if not self.bug_list_dict.has_key(bugid[0:3]): - self.bug_list_dict[bugid[0:3]] = bugid - fname = bugid[0:3] - else: - for i in range(s, s+6): - if not self.bug_list_dict.has_key(bugid[0:s]): - self.bug_list_dict[bugid[0:s]] = bugid - fname = bugid[0:s] - break - if s == 8: - self.bug_list_dict[bugid] = bugid - fname = bugid - fpath = os.path.join(self.out_dir_bugs, fname) - return fpath - - def _find_file_name(self, bugid): - name = "" - for k in self.bug_list_dict: - if self.bug_list_dict[k] == bugid: - name = k - self.bug_list_dict.pop(k) - break - return name ++ def _truncated_bug_id(self, bug): ++ return libbe.util.id._truncate( ++ bug.uuid, bug.sibling_uuids(), ++ min_length=self.min_id_length) ++ ++ def _truncated_comment_id(self, comment): ++ return libbe.util.id._truncate( ++ comment.uuid, comment.sibling_uuids(), ++ min_length=self.min_id_length) + def _create_output_directories(self, out_dir): if self.verbose: print >> self.stdout, 'Creating output directories' @@@ -194,8 -222,8 +206,8 @@@ bug.load_comments(load_full=True) comment_entries = self._generate_bug_comment_entries(bug) - filename = '%s.html' % bug.uuid - filename = '%s.html' % fname -- fullpath = os.path.join(self.out_dir_bugs, filename) ++ dirname = self._truncated_bug_id(bug) ++ fullpath = os.path.join(self.out_dir_bugs, dirname, 'index.html') template_info = {'title':self.title, 'charset':self.encoding, 'up_link':up_link, @@@ -205,6 -233,6 +217,9 @@@ for attr in ['uuid', 'severity', 'status', 'assigned', 'reporter', 'creator', 'time_string', 'summary']: template_info[attr] = self._escape(getattr(bug, attr)) ++ fulldir = os.path.join(self.out_dir_bugs, dirname) ++ if not os.path.exists(fulldir): ++ os.mkdir(fulldir) self._write_file(self.bug_file % template_info, [fullpath]) def _generate_bug_comment_entries(self, bug): @@@ -227,7 -255,7 +242,9 @@@ else: comment_entries.append( '
' % comment.uuid) -- template_info = {'shortname': comment.id.user()} ++ template_info = { ++ 'shortname': comment.id.user(), ++ 'truncated_id': self._truncated_comment_id(comment)} for attr in ['uuid', 'author', 'date', 'body']: value = getattr(comment, attr) if attr == 'body': @@@ -241,11 -269,11 +258,14 @@@ elif comment.content_type.startswith('image/'): save_body = True value = '' \ -- % (bug.uuid, comment.uuid) ++ % (self._truncated_bug_id(bug), ++ self._truncated_comment_id(comment)) else: save_body = True value = 'Link to %s file.' \ -- % (bug.uuid, comment.uuid, comment.content_type) ++ % (self._truncated_bug_id(bug), ++ self._truncated_comment_id(comment), ++ comment.content_type) if link_long_ids == True: value = self._long_to_linked_user(value) if save_body == True: @@@ -274,7 -302,7 +294,7 @@@ >>> bd = libbe.bugdir.SimpleBugDir(memory=False) >>> h = HTMLGen(bd) >>> h._long_to_linked_user('A link #abc123/a#, and a non-link #x#y#.') -- 'A link abc/a, and a non-link #x#y#.' ++ 'A link abc/a, and a non-link #x#y#.' >>> bd.cleanup() """ replacer = libbe.util.id.IDreplacer( @@@ -298,9 -326,9 +318,9 @@@ >>> h._long_to_linked_user_replacer([bd], 'abc123') '#abc123#' >>> h._long_to_linked_user_replacer([bd], 'abc123/a') -- 'abc/a' ++ 'abc/a' >>> h._long_to_linked_user_replacer([bd], 'abc123/a/0123') -- 'abc/a/012' ++ 'abc/a/012' >>> h._long_to_linked_user_replacer([bd], 'x') '#x#' >>> h._long_to_linked_user_replacer([bd], '') @@@ -309,7 -337,7 +329,6 @@@ """ try: p = libbe.util.id.parse_user(bugdirs[0], long_id) -- short_id = libbe.util.id.long_to_short_user(bugdirs, long_id) except (libbe.util.id.MultipleIDMatches, libbe.util.id.NoIDMatches, libbe.util.id.InvalidIDStructure), e: @@@ -317,11 -345,11 +336,17 @@@ if p['type'] == 'bugdir': return '#%s#' % long_id elif p['type'] == 'bug': -- return '%s' \ -- % (p['bug'], short_id) ++ bug,comment = libbe.command.util.bug_comment_from_user_id( ++ bugdirs[0], long_id) ++ return '%s' \ ++ % (self._truncated_bug_id(bug), bug.id.user()) elif p['type'] == 'comment': -- return '%s' \ -- % (p['bug'], p['comment'], short_id) ++ bug,comment = libbe.command.util.bug_comment_from_user_id( ++ bugdirs[0], long_id) ++ return '%s' \ ++ % (self._truncated_bug_id(bug), ++ self._truncated_comment_id(comment), ++ comment.id.user()) raise Exception('Invalid id type %s for "%s"' % (p['type'], long_id)) @@@ -362,6 -390,8 +387,7 @@@ for attr in ['uuid', 'severity', 'status', 'assigned', 'reporter', 'creator', 'time_string', 'summary']: template_info[attr] = self._escape(getattr(bug, attr)) - template_info['uuid'] = fn ++ template_info['dir'] = self._truncated_bug_id(bug) bug_entries.append(self.index_bug_entry % template_info) return '\n'.join(bug_entries) @@@ -594,11 -624,11 +620,11 @@@ self.index_bug_entry =""" -- %(shortname)s -- %(status)s -- %(severity)s -- %(summary)s -- %(time_string)s ++ %(shortname)s ++ %(status)s ++ %(severity)s ++ %(summary)s ++ %(time_string)s """