mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-04 05:53:43 +00:00 
			
		
		
		
	The comment that tabbott edited into my commit while wimpifying this function is wrong on multiple levels. Firstly, the way in which users might be “running our scripts” was never relevant. `__file__` is not the script that the user ran, it’s zulip_tools.py itself. What matters is not how the user ran the script, but rather how zulip_tools was imported. If zulip_tools was imported as scripts.lib.zulip_tools, then `__file__` must end with `scripts/lib/zulip_tools.py`, so running dirname three times on it is fine. In fact, in Python ≥ 3.4 (we don’t support anything older), `__file__` in an imported module is always an absolute path, so it must end with `scripts/lib/zulip_tools.py` in any case. (At present, there’s one script that imports lib.zulip_tools, and the installer runs scripts/lib/zulip_tools.py as a script, but those uses don’t hit this function.) Secondly, even if we do care about `__file__` being a funny relative path, there’s still no reason to have two calls to `realpath`. `realpath(dirname(dirname(dirname(realpath(…)))))` is equivalent to `dirname(dirname(dirname(realpath(…)))), as the inner `realpath` has already canonicalized symlinks at every level. This version also deals with `__file__` being a funny relative path (assuming none of scripts, lib, and zulip_tools.py are themselves symlinks), while making fewer `lstat` calls than either of the above constructions. Signed-off-by: Anders Kaseorg <andersk@mit.edu>
This directory contains scripts that:
- 
Generally do not require access to Django or the database (those are "management commands"), and thus are suitable to run operationally.
 - 
Are useful for managing a production deployment of Zulip (many are also used in a Zulip development environment, though development-only scripts live in
tools/). 
For more details, see https://zulip.readthedocs.io/en/latest/overview/directory-structure.html.