-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflashboot.py
executable file
·49 lines (36 loc) · 1.21 KB
/
flashboot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/env python
# coding=utf-8
import sys
import logging
import dhcpserver
import tftpserver
import optparse
import socket
import os
import thread
def main():
usage = "Usage: %prog [options] <interface> <boot-file>"
parser = optparse.OptionParser(usage=usage)
parser.add_option("-v", "--verbose", dest="loglevel", action="store_const",
const=logging.INFO, help="Output messages.", default=logging.WARNING)
(options, args) = parser.parse_args()
if len(args) != 2:
parser.print_help()
return 1
iface, bootfile = args
logging.basicConfig(stream=sys.stdout, level=options.loglevel,
format='%(levelname)s(%(name)s): %(message)s')
try:
bootFullName = os.path.abspath(bootfile)
bootDir = os.path.dirname(bootFullName)
bootFile = os.path.basename(bootFullName)
thread.start_new_thread(dhcpserver.main_work,
(iface, bootFile, options.loglevel))
thread.start_new_thread(tftpserver.main_work,
(iface, bootDir, options.loglevel))
raw_input("")
except:
return 1
return 0
if __name__ == '__main__':
main()