Skip to content

Commit 869d4ec

Browse files
committed
Add support for not adding the current system hostname
1 parent 3f92933 commit 869d4ec

File tree

3 files changed

+18
-6
lines changed

3 files changed

+18
-6
lines changed

makeHosts.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,10 @@ def recursively_loop_extensions(extension, extensions, current_extensions):
6767

6868
name = "-".join(c_current_extensions)
6969

70-
params = ("-a", "-n", "-o", "alternates/"+name, "-e") + tuple(c_current_extensions)
70+
params = ("-a", "-d", "-n", "-o", "alternates/"+name, "-e") + tuple(c_current_extensions)
7171
update_hosts_file(*params)
7272

73-
params = ("-a", "-n", "-s", "--nounifiedhosts", "-o", "alternates/"+name+"-only", "-e") + tuple(c_current_extensions)
73+
params = ("-a", "-d", "-n", "-s", "--nounifiedhosts", "-o", "alternates/"+name+"-only", "-e") + tuple(c_current_extensions)
7474
update_hosts_file(*params)
7575

7676
while len(c_extensions) > 0:
@@ -96,9 +96,9 @@ def main():
9696

9797
# Update the unified hosts file
9898
if options["noupdate"]:
99-
update_hosts_file("-a", "-n")
99+
update_hosts_file("-a", "-d", "-n")
100100
else:
101-
update_hosts_file("-a")
101+
update_hosts_file("-a", "-d")
102102

103103
# List of extensions we want to generate, we will loop over them recursively to prevent manual definitions
104104
# Only add new extensions to the end of the array, to avoid relocating existing hosts-files

testUpdateHostsFile.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ def test_get_defaults(self):
131131
"commonexclusions": ["hulu.com"],
132132
"blacklistfile": "foo" + self.sep + "blacklist",
133133
"whitelistfile": "foo" + self.sep + "whitelist",
134+
"addsystemhostname": True,
134135
}
135136
self.assertDictEqual(actual, expected)
136137

@@ -1092,7 +1093,7 @@ def test_basic_include_static_hosts(self):
10921093

10931094
def test_basic_include_static_hosts_linux(self):
10941095
kwargs = dict(
1095-
extensions="", outputsubfolder="", numberofrules=5, skipstatichosts=False, nounifiedhosts=False
1096+
extensions="", outputsubfolder="", numberofrules=5, skipstatichosts=False, nounifiedhosts=False, addsystemhostname=True
10961097
)
10971098
with self.mock_property("platform.system") as system:
10981099
system.return_value = "Linux"

updateHostsFile.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ def get_defaults():
9191
"commonexclusions": ["hulu.com"],
9292
"blacklistfile": path_join_robust(BASEDIR_PATH, "blacklist"),
9393
"whitelistfile": path_join_robust(BASEDIR_PATH, "whitelist"),
94+
"addsystemhostname": True,
9495
}
9596

9697

@@ -229,6 +230,14 @@ def main():
229230
default=path_join_robust(BASEDIR_PATH, "blacklist"),
230231
help="Blacklist file to use while generating hosts files.",
231232
)
233+
parser.add_argument(
234+
"--dont-add-system-hostname",
235+
"-d",
236+
dest="addsystemhostname",
237+
default=True,
238+
action="store_false",
239+
help="Don't add the current system hostname while generating hosts files.",
240+
)
232241

233242
global settings
234243

@@ -327,6 +336,7 @@ def main():
327336
outputsubfolder=outputsubfolder,
328337
skipstatichosts=skipstatichosts,
329338
nounifiedhosts=nounifiedhosts,
339+
addsystemhostname=settings["addsystemhostname"],
330340
)
331341
finalfile.close()
332342

@@ -1272,6 +1282,7 @@ def write_opening_header(finalfile, **headerparams):
12721282
3) outputsubfolder
12731283
4) skipstatichosts
12741284
5) nounifiedhosts
1285+
6) hostfilename
12751286
"""
12761287

12771288
finalfile.seek(0) # Reset file pointer.
@@ -1389,7 +1400,7 @@ def write_opening_header(finalfile, **headerparams):
13891400
write_data(finalfile, "ff02::3 ip6-allhosts\n")
13901401
write_data(finalfile, "0.0.0.0 0.0.0.0\n")
13911402

1392-
if platform.system() == "Linux":
1403+
if platform.system() == "Linux" and "addsystemhostname" in headerparams.keys() and headerparams["addsystemhostname"]:
13931404
write_data(finalfile, "127.0.1.1 " + socket.gethostname() + "\n")
13941405
write_data(finalfile, "127.0.0.53 " + socket.gethostname() + "\n")
13951406

0 commit comments

Comments
 (0)