-
Notifications
You must be signed in to change notification settings - Fork 0
/
pcraft.py
executable file
·76 lines (57 loc) · 2.48 KB
/
pcraft.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/python3 -B
import sys
import os
import time
import argparse
import pyami
from pcraft.confnames import *
from pcraft.PackageManager import PackageManager
from pcraft.PcapBuilder import PcapBuilder
from pcraft.LogsBuilder import LogsBuilder
verbose = False
def debug(message):
if verbose:
print(message)
class RunPcraft(object):
def __init__(self, pkg, args):
self.current_time = time.time()
self.pkg = pkg
self.args = args
self.ami = pyami.Ami()
self.ami_cache = self.args["script"]
if not args["script"].endswith(".amic"):
self.ami_cache = os.path.join(os.path.dirname(self.args["script"]), "." + os.path.basename(self.args["script"]) + "c")
self.build_cache()
else:
print("Reading cache file %s" % self.ami_cache)
if self.args["pcap"]:
self.build_pcap(self.args["pcap"])
if self.args["log_folder"]:
self.build_logs(self.args["log_folder"], self.args["force"], self.args["no_triggers"])
def build_cache(self):
debug("Building cache: %s" % self.ami_cache)
self.ami.Cache(self.args["script"], self.ami_cache)
debug("Done building cache")
def build_pcap(self, pcapfile):
pcap_builder = PcapBuilder(self.pkg, self.ami_cache)
pcap_builder.build(pcapfile)
def build_logs(self, log_folder, force, triggers):
logs = LogsBuilder(self.pkg, self.ami_cache, log_folder, force, triggers)
logs.build()
if __name__ == "__main__":
parser = argparse.ArgumentParser(exit_on_error=True)
parser.add_argument("script", type=str, help="The script to run")
parser.add_argument("-p", "--pcap", type=str, help="The pcap to build")
parser.add_argument("-l", "--log-folder", type=str, help="The log folder")
parser.add_argument("-f", "--force", help="overwrite the log folder", action="store_true")
parser.add_argument("-t", "--no-triggers", help="Do not run automatic triggers", action="store_false")
parser.add_argument("-v", "--verbose", action="store_true")
args = parser.parse_args()
vargs = vars(args)
verbose = vargs["verbose"]
if (not vargs["pcap"]) and (not vargs["log_folder"]):
parser.print_usage()
print("%s: error: argument -p/--pcap OR -l/--log-folder required" % sys.argv[0])
sys.exit(1)
pkg = PackageManager()
pe = RunPcraft(pkg, vargs)