#10318 closed defect (fixed)
trac-admin: Failed to create environment
Reported by: | Owned by: | ||
---|---|---|---|
Priority: | normal | Milestone: | 0.12.3 |
Component: | general | Version: | 0.11-stable |
Severity: | normal | Keywords: | trac-admin initenv env.py |
Cc: | Thijs Triemstra | Branch: | |
Release Notes: | |||
API Changes: | |||
Internal Changes: |
Description
Hello.
When creating a new Trac 0.11 environment, the Initenv will fail if the parent directory does not already exist. See below for an example where '/var/local/lib' does not exist. This appears to also affect the latest Trac 0.13 dev.
# trac-admin /var/local/lib/mytracinstall initenv Creating a new Trac environment at /var/local/lib/mytracinstall <snip> <snip> <snip> Creating and Initializing Project Initenv for '/var/local/lib/mytracinstall' failed. Failed to create environment. [Errno 2] No such file or directory: '/var/local/lib/mytracinstall' Traceback (most recent call last): File "/usr/lib/python2.6/dist-packages/trac/admin/console.py", line 583, in do_initenv options=options) File "/usr/lib/python2.6/dist-packages/trac/env.py", line 207, in __init__ self.create(options) File "/usr/lib/python2.6/dist-packages/trac/env.py", line 316, in create os.mkdir(self.path) OSError: [Errno 2] No such file or directory: '/var/local/lib/mytracinstall'
This is due to 'env.py' using os.mkdir() when os.makedirs() would be a better fit. The attached patch to 'env.py' will allow Trac to create all the intermediate directories if they don't exist.
Attachments (2)
Change History (13)
by , 13 years ago
Attachment: | trac.env.py.patch added |
---|
comment:1 by , 13 years ago
follow-up: 3 comment:2 by , 13 years ago
I understand where you are coming from but the difference between the word processor analogy and this one is that with a new file in a word processor, there is no context to start with. You create the file, then save it where ever you want. In this case, you are initializing a brand new Trac environment with context (ie. put the Trac env here). You are telling Trac that you want to create this new Trac environment in location X so IMO, if you are telling Trac that you want the environment in location X, you shouldn't have to pre-create location X first. This should happen automatically as you've told it that's where you want it. Perhaps a simple "Destination doesn't exist. Would you like to create this directory?" prompt would suffice.
The 'Creating a Project Environment' section of the Trac install documentation makes no reference to having to pre-create the dirname() of the Trac environment. If the os.makedirs() patch is not accepted then you may want to consider updating the installation documentation so that it is clear that the destination location needs to be created.
comment:3 by , 13 years ago
Resolution: | → wontfix |
---|---|
Status: | new → closed |
Replying to Derrick Karpo <dkarpo@…>:
You are telling Trac that you want to create this new Trac environment in location X so IMO, if you are telling Trac that you want the environment in location X, you shouldn't have to pre-create location X first. This should happen automatically as you've told it that's where you want it.
I disagree with that. Try the following (where subdir
doesn't exist):
$ touch testfile $ cp testfile subdir/testfile cp: cannot create regular file `subdir/testfile': No such file or directory
The cp
command reports an error, and certainly doesn't create the subdir
directory for you. Why should Trac? If you want the base directory to be created, simply precede your call to trac-admin
with mkdir -p /var/local/lib
.
Definitely a "wontfix".
follow-up: 5 comment:4 by , 13 years ago
Yes, I understand this. With respect to administrators who may be little out of their element when installing Trac I think the application should do its best to be nice. If you feel that Trac shouldn't make assumptions that the user knows what their are doing (which I get), then it should error out nicely during the environment initialization like it does when the "Directory exists and is not empty".
Would you be opposed to changes in do_initenv() in console.py that would check if dirname() doesn't exist and catch that error providing the user with a nicer prompt?
comment:5 by , 13 years ago
Milestone: | → next-major-0.1X |
---|---|
Resolution: | wontfix |
Status: | closed → reopened |
Replying to Derrick Karpo <dkarpo@…>:
Would you be opposed to changes in do_initenv() in console.py that would check if dirname() doesn't exist and catch that error providing the user with a nicer prompt?
No, that would be a nice addition. Currently, the error happens at the end of the creation process, after asking the few required questions, which is not too nice. A check (and abort) before asking the questions would be welcome.
Let's reopen this ticket for that, then.
comment:6 by , 13 years ago
If you do provide a patch, please make it for 0.12-stable or trunk, as the 0.11.x branch is unsupported.
comment:7 by , 13 years ago
Cc: | added |
---|
by , 13 years ago
Attachment: | trac.initenv.os.path.exists.patch added |
---|
comment:8 by , 13 years ago
Hello.
Here is a patch (attachment:trac.initenv.os.path.exists.patch) against trac-0.12.2 which should resolve this ticket. Please consider merging it. Trac will now check first if the base directory for the Trac environment initialization exists, if it doesn't, it fails immediately with a nice user prompt. This has been tested on Linux only.
With the patch:
$ trac-admin /home/dk/tmp/dir1/dir2/trac initenv Initenv for '/home/dk/tmp/dir1/dir2/trac' failed. Base directory '/home/dk/tmp/dir1/dir2' does not exist. Please create manually and retry.
Let's create the directory and retry:
$ mkdir -p /home/dk/tmp/dir1/dir2 $ trac-admin /home/dk/tmp/dir1/dir2/trac initenv Creating a new Trac environment at /home/dk/tmp/dir1/dir2/trac Trac will first ask a few questions about your environment in order to initialize and prepare the project database. Please enter the name of your project. <snip>
comment:9 by , 13 years ago
Milestone: | next-major-0.1X → 0.12.3 |
---|---|
Owner: | set to |
Status: | reopened → new |
Thanks for the patch.
comment:10 by , 13 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
Patch applied in [10807]. Thanks!
comment:11 by , 13 years ago
Owner: | changed from | to
---|
I don't think this is a good idea. When you create a new file e.g. in a word processor, it doesn't create all necessary subdirectories. So I would find it surprising if Trac did that.
Suggesting "wontfix".