44 lines
899 B
Python
Executable file
44 lines
899 B
Python
Executable file
#!/usr/bin/python3
|
|
# -*- coding: utf-8 -*-
|
|
|
|
# Give me a random hostname!
|
|
|
|
import sys, os
|
|
import random
|
|
|
|
|
|
def read_file(filename) :
|
|
ret = []
|
|
with open(filename, 'r') as f_in :
|
|
for line in f_in.readlines():
|
|
line = line.strip()
|
|
if len(line) == 0 or line[0] in "#:!$%" : continue
|
|
ret.append(line)
|
|
return ret
|
|
|
|
|
|
if __name__ == "__main__" :
|
|
# Print 10 lines, 4 entries each line
|
|
n = 10
|
|
c = 4
|
|
|
|
args = sys.argv[1:]
|
|
hostnames = []
|
|
if len(args) == 0 :
|
|
# From all files
|
|
with os.scandir(".") as dirs:
|
|
for entry in dirs :
|
|
filename = entry.name
|
|
if filename.endswith(".txt") :
|
|
hostnames += read_file(filename)
|
|
else :
|
|
# Only from given files
|
|
for filename in args :
|
|
hostnames += read_file(filename)
|
|
|
|
|
|
for i in range(n) :
|
|
for j in range(c) :
|
|
hostname = hostnames[random.randint(0, len(hostnames))]
|
|
sys.stdout.write("%-20s" % (hostname))
|
|
sys.stdout.write("\n") |