mirror of
https://github.com/nmap/nmap.git
synced 2025-12-08 05:31:31 +00:00
Zenmap: keep data files within package
This commit is contained in:
@@ -68,38 +68,13 @@ from zenmapCore.BasePaths import base_paths
|
||||
from zenmapCore.Name import APP_NAME
|
||||
|
||||
|
||||
# Find out the prefix under which data files (interface definition XML,
|
||||
# pixmaps, etc.) are stored. This can vary depending on whether we are running
|
||||
# in an executable package and what type of package it is, which we check using
|
||||
# the sys.frozen attribute. See
|
||||
# http://mail.python.org/pipermail/pythonmac-sig/2004-November/012121.html.
|
||||
def get_prefix():
|
||||
from site import getsitepackages
|
||||
frozen = getattr(sys, "frozen", None)
|
||||
if frozen == "macosx_app" or "Zenmap.app" in sys.executable:
|
||||
# A py2app .app bundle.
|
||||
return os.path.join(dirname(sys.executable), "..", "Resources")
|
||||
elif frozen is not None:
|
||||
# Assume a py2exe executable.
|
||||
return dirname(sys.executable)
|
||||
elif any(__file__.startswith(pdir) for pdir in getsitepackages()):
|
||||
# Installed in site-packages; use configured prefix.
|
||||
return sys.prefix
|
||||
else:
|
||||
# Normal script execution. Look in the current directory to allow
|
||||
# running from the distribution.
|
||||
return os.path.abspath(os.path.dirname(sys.argv[0]))
|
||||
prefix = join(dirname(__file__), 'data')
|
||||
|
||||
prefix = get_prefix()
|
||||
|
||||
# These lines are overwritten by the installer to hard-code the installed
|
||||
# locations.
|
||||
CONFIG_DIR = join(prefix, "share", APP_NAME, "config")
|
||||
LOCALE_DIR = join(prefix, "share", APP_NAME, "locale")
|
||||
MISC_DIR = join(prefix, "share", APP_NAME, "misc")
|
||||
PIXMAPS_DIR = join(prefix, "share", "zenmap", "pixmaps")
|
||||
DOCS_DIR = join(prefix, "share", APP_NAME, "docs")
|
||||
NMAPDATADIR = join(prefix, "..")
|
||||
CONFIG_DIR = join(prefix, "config")
|
||||
LOCALE_DIR = join(prefix, "locale")
|
||||
MISC_DIR = join(prefix, "misc")
|
||||
PIXMAPS_DIR = join(prefix, "pixmaps")
|
||||
DOCS_DIR = join(prefix, "docs")
|
||||
|
||||
|
||||
def get_extra_executable_search_paths():
|
||||
@@ -125,7 +100,7 @@ class Paths(object):
|
||||
|
||||
config_files_list = ["config_file",
|
||||
"scan_profile",
|
||||
"version"]
|
||||
]
|
||||
|
||||
empty_config_files_list = ["target_list",
|
||||
"recent_scans",
|
||||
@@ -140,8 +115,16 @@ class Paths(object):
|
||||
self.pixmaps_dir = PIXMAPS_DIR
|
||||
self.misc_dir = MISC_DIR
|
||||
self.docs_dir = DOCS_DIR
|
||||
self.nmap_dir = NMAPDATADIR
|
||||
self._delayed_incomplete = True
|
||||
PATH = os.environ.get('PATH', os.defpath)
|
||||
extra = get_extra_executable_search_paths()
|
||||
if extra:
|
||||
PATH += ';' + ';'.join(extra)
|
||||
NMAPPATH = dirname(shutil.which("nmap", path=PATH))
|
||||
if sys.platform == 'win32':
|
||||
self.nmap_dir = NMAPPATH
|
||||
else:
|
||||
self.nmap_dir = join(NMAPPATH, "..", "share", "nmap")
|
||||
|
||||
# Delay initializing these paths so that
|
||||
# zenmapCore.I18N.install_gettext can install _() before modules that
|
||||
@@ -241,4 +224,3 @@ if __name__ == '__main__':
|
||||
print(">>> OPTIONS:", Path.options)
|
||||
print()
|
||||
print(">>> DB:", Path.db)
|
||||
print(">>> VERSION:", Path.version)
|
||||
|
||||
Reference in New Issue
Block a user