Edgewall Software
Modify

Opened 6 years ago

Closed 6 years ago

Last modified 5 years ago

#11925 closed defect (fixed)

Traceback on About page when htdocs directory does not exist

Reported by: Ryan J Ollos Owned by: Jun Omae
Priority: normal Milestone: 1.0.4
Component: general Version:
Severity: normal Keywords: site-customization
Cc: Branch:
Release Notes:

Don't raise an exception when generating list of static resources and templates for About page if the environment htdocs or templates directory is missing.

API Changes:
Internal Changes:

Description (last modified by Ryan J Ollos)

This is a regression from #11548. The following traceback is seen:

File "/srv/trac-hacks.org/pve/lib/python2.6/site-packages/Trac-1.0.3-py2.6.egg/trac/web/main.py", line 513, in _dispatch_request
  dispatcher.dispatch(req)
File "/srv/trac-hacks.org/pve/lib/python2.6/site-packages/Trac-1.0.3-py2.6.egg/trac/web/main.py", line 222, in dispatch
  resp = chosen_handler.process_request(req)
File "/srv/trac-hacks.org/pve/lib/python2.6/site-packages/Trac-1.0.3-py2.6.egg/trac/about.py", line 75, in process_request
  Chrome(self.env).get_interface_customization_files()
File "/srv/trac-hacks.org/pve/lib/python2.6/site-packages/Trac-1.0.3-py2.6.egg/trac/web/chrome.py", line 1132, in get_interface_customization_files
  site_htdocs = sorted(os.listdir(self.env.get_htdocs_dir()))

I need to look more closely at the code, but it appears to result when [trac] htdocs_location is empty or not defined. On trac-hacks.org we have:

[trac]
htdocs_location = 

It appears this is because the webserver is configured to serve these files:

Alias   /chrome/common  /srv/trac-hacks.org/www/htdocs/common
Alias   /chrome/site    /srv/trac-hacks.org/www/htdocs/site

Please correct me if I'm assuming wrong.

The workaround is to simply create the missing htdocs directory.

Attachments (0)

Change History (5)

comment:1 by Ryan J Ollos, 6 years ago

Status: newassigned

in reply to:  description comment:2 by Jun Omae, 6 years ago

Replying to rjollos:

I need to look more closely at the code, but it appears to result when [trac] htdocs_location is empty or not define. On trac-hacks.org we have:

Not a defect. Environment.get_htdocs_dir() is to retrieve $ENV/htdocs directory as site htdocs. The directory is created when environment is created at the same time. It generally isn't deleted.

However, we could make it robust.

  • trac/web/chrome.py

    diff --git a/trac/web/chrome.py b/trac/web/chrome.py
    index 024ca03..a021b9d 100644
    a b class Chrome(Component):  
    11171117        """Returns a dictionary containing the lists of files present in the
    11181118        site and shared templates and htdocs directories.
    11191119        """
     1120        def listdir(path, suffix=None):
     1121            if not os.path.isdir(path):
     1122                return []
     1123            return sorted(name for name in os.listdir(path)
     1124                               if suffix is None or name.endswith(suffix))
     1125
    11201126        files = {}
    11211127        # Collect templates list
    1122         site_templates = sorted(os.listdir(self.env.get_templates_dir()))
    1123         site_templates = [t for t in site_templates
    1124                             if t.endswith('.html')]
    1125         shared_templates = []
    1126         shared_templates_dir = Chrome(self.env).shared_templates_dir
    1127         if os.path.exists(shared_templates_dir):
    1128             shared_templates = sorted(os.listdir(shared_templates_dir))
    1129             shared_templates = [t for t in shared_templates
    1130                                   if t.endswith('.html')]
     1128        site_templates = listdir(self.env.get_templates_dir(), '.html')
     1129        shared_templates = listdir(Chrome(self.env).shared_templates_dir,
     1130                                   '.html')
    11311131        # Collect static resources list
    1132         site_htdocs = sorted(os.listdir(self.env.get_htdocs_dir()))
    1133         shared_htdocs = []
    1134         shared_htdocs_dir = Chrome(self.env).shared_htdocs_dir
    1135         if os.path.exists(shared_htdocs_dir):
    1136             shared_htdocs = sorted(os.listdir(shared_htdocs_dir))
     1132        site_htdocs = listdir(self.env.get_htdocs_dir())
     1133        shared_htdocs = listdir(Chrome(self.env).shared_htdocs_dir)
     1134
    11371135        if any((site_templates, shared_templates, site_htdocs, shared_htdocs)):
    11381136            files = {
    11391137                'site-templates': site_templates,

comment:3 by Ryan J Ollos, 6 years ago

Release Notes: modified (diff)
Resolution: fixed
Status: assignedclosed

Thanks for the patch. Committed to 1.0-stable in [13709], merged to trunk in [13710].

comment:4 by Ryan J Ollos, 6 years ago

Owner: changed from Ryan J Ollos to Jun Omae

comment:5 by Ryan J Ollos, 5 years ago

Description: modified (diff)

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Jun Omae.
The resolution will be deleted. Next status will be 'reopened'.
to The owner will be changed from Jun Omae to the specified user.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.