Merged Gianluca's truncated-IDs in `be html` output patch.
authorW. Trevor King <wking@drexel.edu>
Sat, 20 Feb 2010 18:12:38 +0000 (13:12 -0500)
committerW. Trevor King <wking@drexel.edu>
Sat, 20 Feb 2010 18:12:38 +0000 (13:12 -0500)
Or at least merged the general idea.  Changes in the implementation
listed in #bea/01e/2f9#.

1  2 
.be/bea86499-824e-4e77-b085-2d581fa9ccab/bugs/01e7151c-6113-4c8f-9fc5-4d594431bd2b/comments/2f9beed6-4008-442a-8d44-a45cb7ce0a36/body
.be/bea86499-824e-4e77-b085-2d581fa9ccab/bugs/01e7151c-6113-4c8f-9fc5-4d594431bd2b/comments/2f9beed6-4008-442a-8d44-a45cb7ce0a36/values
.be/bea86499-824e-4e77-b085-2d581fa9ccab/bugs/01e7151c-6113-4c8f-9fc5-4d594431bd2b/values
NEWS
libbe/command/html.py

index 0000000000000000000000000000000000000000,0000000000000000000000000000000000000000..d20af3029556c020c44010f4185c777d7b7eb72f
new file mode 100644 (file)
--- /dev/null
--- /dev/null
@@@ -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.
++
index 0000000000000000000000000000000000000000,0000000000000000000000000000000000000000..c7365f514d53f8a68762487addc19128f5ad7b4c
new file mode 100644 (file)
--- /dev/null
--- /dev/null
@@@ -1,0 -1,0 +1,8 @@@
++Author: W. Trevor King <wking@drexel.edu>
++
++
++Content-type: text/plain
++
++
++Date: Sat, 20 Feb 2010 18:10:42 +0000
++
index 673423ec2731c31de8aefb8584025619307feee3,673423ec2731c31de8aefb8584025619307feee3..9efe20966cf91a1d70ef150645350ef6328cdd71
@@@ -7,7 -7,7 +7,7 @@@ reporter: Gianluca Montecchi <gian@grys
  severity: minor
  
  
--status: open
++status: fixed
  
  
  summary: Short the files name used by the be html command
diff --cc NEWS
index 46eeb370383a1a599fd3c456277991a5ba1c9af5,46eeb370383a1a599fd3c456277991a5ba1c9af5..2defeb0c421b811475746840722a406d4eb4d2cc
--- 1/NEWS
--- 2/NEWS
+++ b/NEWS
@@@ -1,3 -1,3 +1,6 @@@
++February 20, 2010
++ * `be html` uses truncated IDs in comment and bug URLs and anchors.
++
  January 27, 2010
   * `be html` links (<a href="...) #-delimited references in text/*
     comment bodies.
index b769179b15d3609dda214bd402a55cea72f46fe7,4b878e0a6fe004c2d685861b651f8cb14709b8ab..43d4683c768b5e011536bd463900fc1526f949ae
@@@ -53,9 -53,9 +53,9 @@@ class HTML (libbe.command.Command)
      True
      >>> os.path.exists(os.path.join(bd.storage.repo, 'html_export', 'bugs'))
      True
--    >>> os.path.exists(os.path.join(bd.storage.repo, 'html_export', 'bugs', 'a.html'))
++    >>> os.path.exists(os.path.join(bd.storage.repo, 'html_export', 'bugs', 'a', 'index.html'))
      True
--    >>> os.path.exists(os.path.join(bd.storage.repo, 'html_export', 'bugs', 'b.html'))
++    >>> os.path.exists(os.path.join(bd.storage.repo, 'html_export', 'bugs', 'b', 'index.html'))
      True
      >>> ui.cleanup()
      >>> bd.cleanup()
@@@ -124,6 -124,6 +124,7 @@@ class HTMLGen (object)
      def __init__(self, bd, template=None,
                   title="Site Title", index_header="Index Header",
                   verbose=False, encoding=None, stdout=None,
++                 min_id_length=3
                   ):
          self.generation_time = time.ctime()
          self.bd = bd
          self._load_default_templates()
          if template != None:
              self._load_user_templates()
 -        self.bug_list_dict = {}
 -        
++        self.min_id_length = min_id_length
 +
      def run(self, out_dir):
          if self.verbose == True:
              print >> self.stdout, \
              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'
  
          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,
          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):
              else:
                  comment_entries.append(
                      '<div class="comment" id="%s">' % 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':
                      elif comment.content_type.startswith('image/'):
                          save_body = True
                          value = '<img src="./%s/%s" />' \
--                            % (bug.uuid, comment.uuid)
++                            % (self._truncated_bug_id(bug),
++                               self._truncated_comment_id(comment))
                      else:
                          save_body = True
                          value = '<a href="./%s/%s">Link to %s file</a>.' \
--                            % (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:
          >>> 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 <a href="./a.html">abc/a</a>, and a non-link #x#y#.'
++        'A link <a href="./a/">abc/a</a>, and a non-link #x#y#.'
          >>> bd.cleanup()
          """
          replacer = libbe.util.id.IDreplacer(
          >>> h._long_to_linked_user_replacer([bd], 'abc123')
          '#abc123#'
          >>> h._long_to_linked_user_replacer([bd], 'abc123/a')
--        '<a href="./a.html">abc/a</a>'
++        '<a href="./a/">abc/a</a>'
          >>> h._long_to_linked_user_replacer([bd], 'abc123/a/0123')
--        '<a href="./a.html#0123">abc/a/012</a>'
++        '<a href="./a/#012">abc/a/012</a>'
          >>> h._long_to_linked_user_replacer([bd], 'x')
          '#x#'
          >>> h._long_to_linked_user_replacer([bd], '')
          """
          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:
          if p['type'] == 'bugdir':
              return '#%s#' % long_id
          elif p['type'] == 'bug':
--            return '<a href="./%s.html">%s</a>' \
--                % (p['bug'], short_id)
++            bug,comment = libbe.command.util.bug_comment_from_user_id(
++                bugdirs[0], long_id)
++            return '<a href="./%s/">%s</a>' \
++                % (self._truncated_bug_id(bug), bug.id.user())
          elif p['type'] == 'comment':
--            return '<a href="./%s.html#%s">%s</a>' \
--                % (p['bug'], p['comment'], short_id)
++            bug,comment = libbe.command.util.bug_comment_from_user_id(
++                bugdirs[0], long_id)
++            return '<a href="./%s/#%s">%s</a>' \
++                % (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))
  
              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)
  
  
          self.index_bug_entry ="""
              <tr class="%(severity)s">
--              <td><a href="bugs/%(uuid)s.html">%(shortname)s</a></td>
--              <td><a href="bugs/%(uuid)s.html">%(status)s</a></td>
--              <td><a href="bugs/%(uuid)s.html">%(severity)s</a></td>
--              <td><a href="bugs/%(uuid)s.html">%(summary)s</a></td>
--              <td><a href="bugs/%(uuid)s.html">%(time_string)s</a></td>
++              <td><a href="bugs/%(dir)s/">%(shortname)s</a></td>
++              <td><a href="bugs/%(dir)s/">%(status)s</a></td>
++              <td><a href="bugs/%(dir)s/">%(severity)s</a></td>
++              <td><a href="bugs/%(dir)s/">%(summary)s</a></td>
++              <td><a href="bugs/%(dir)s/">%(time_string)s</a></td>
              </tr>
          """