-
Notifications
You must be signed in to change notification settings - Fork 0
/
create.py
212 lines (158 loc) · 5.4 KB
/
create.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
import random
from .mod import Mod, File, Download
DEFAULT_EXTENSION = "7z"
class CreateMods:
def name(self):
return "mods"
def create_parser(self, sp):
p = sp.add_parser(
self.name(),
help="creates mods with files in each",
description="creates mods with files in each")
p.add_argument(
"--duplicate-hidden",
action="store_true",
help="creates a duplicate of each file by appending .mohidden to " +
"filenames")
p.add_argument(
"--esm",
action="store_true",
help="adds a .esm in every mod")
p.add_argument(
"--huge",
action="store_true",
help="creates mods with lots of files")
p.add_argument(
"count",
type=int,
help="number of mods to create")
p.add_argument(
"--files",
type=int,
default=5,
help="number of files to create per mod")
return p
def run(self, cx):
cx.clear_directory(cx.mods_directory())
for i in range(cx.options.count):
name = "mod-" + str(i + 1)
m = Mod(name)
if cx.options.huge:
self.create_huge(cx, m)
else:
for i in range(cx.options.files):
self.add_text_file(cx, m, str(i + 1), ".txt")
self.add_text_file(cx, m, str(i + 1), ".ini")
if cx.options.esm:
m.add_file(File(name + ".esm", ""))
m.create(cx)
return 0
def create_huge(self, cx, m):
count = 100000
txt_count = count
ini_count = count
image_count = count
esp_count = count
print("txt")
dir = ""
for i in range(txt_count):
if (i % 50) == 0:
dir = "txt_" + str(i)
self.add_text_file(cx, m, dir + "/" + str(i + 1), ".txt")
print("ini")
dir = ""
for i in range(ini_count):
if (i % 50) == 0:
dir = "ini_" + str(i)
self.add_text_file(cx, m, dir + "/" + str(i + 1), ".ini")
print("images")
image = ""
with open(cx.res_file("image.png"), "rb") as f:
image = f.read()
dir = ""
for i in range(image_count):
if (i % 50) == 0:
dir = "image_" + str(i)
m.add_file(File(dir + "/" + str(i + 1) + ".png", image))
print("esp")
esp = ""
with open(cx.res_file("dummy.esp"), "rb") as f:
esp = f.read()
dir = ""
for i in range(esp_count):
if (i % 50) == 0:
dir = "esp_" + str(i)
m.add_file(File(dir + "/" + str(i + 1) + ".esp", esp))
def add_text_file(self, cx, m, name, ext):
filename = name + ext
content = m.name() + " " + filename
m.add_file(File(filename, content))
if cx.options.duplicate_hidden:
m.add_file(File(filename + ".mohidden", content))
class CreateDownloads:
def name(self):
return "dls"
def create_parser(self, sp):
p = sp.add_parser(
self.name(),
help="creates dummy downloads",
description="creates dummy downloads")
p.add_argument(
"--no-meta",
action="store_true",
help="disables creation of .meta files")
p.add_argument(
"--no-nexus",
action="store_true",
help="disables generation of random nexus ids")
p.add_argument(
"--ext",
type=str,
default=DEFAULT_EXTENSION,
help="specifies extension (defaults to " +
"'" + DEFAULT_EXTENSION + "')")
p.add_argument(
"count",
type=int,
help="number of downloads to create")
return p
def run(self, cx):
cx.clear_directory(cx.downloads_directory())
for i in range(cx.options.count):
name = "mod " + str(i + 1)
d = self.create_download(cx, name)
d.create(cx)
def create_download(self, cx, name):
nexus_id = None
file_id = None
version = self.generate_version()
ext = cx.options.ext
meta = not cx.options.no_meta
if not cx.options.no_nexus:
nexus_id = self.generate_nexus_id()
file_id = self.generate_file_id()
return Download(name, nexus_id, file_id, version, ext, meta)
def generate_nexus_id(self):
return random.randint(1000, 10000)
def generate_file_id(self):
return random.randint(1000, 10000)
def generate_version(self):
s = ""
for i in range(random.randint(2, 3)):
if s != "":
s += "."
s += str(random.randint(1, 10))
return s
class Overwrite:
def name(self):
return "overwrite"
def create_parser(self, sp):
p = sp.add_parser(
self.name(),
help="creates files in the overwrite directory",
description="creates files in the overwrite directory")
return p
def run(self, cx):
cx.clear_directory(cx.overwrite_directory())
File("a.txt", "a").create(cx, cx.overwrite_directory())
File("b.txt", "b").create(cx, cx.overwrite_directory())