-
-
Save chipaca/4da751672cb1546aa214 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
import os | |
import random | |
import shutil | |
import sys | |
import tempfile | |
import yaml | |
multiVersions=False | |
def words(): | |
words = [] | |
with open("/usr/share/dict/british-english-insane", "rb") as f: | |
for line in f: | |
line=line.strip() | |
if len(line)>2 and line.isalnum() and line.islower(): | |
words.append(line.decode("utf-8")) | |
random.shuffle(words) | |
yield from words | |
rndsrc=words() | |
def rndservices(): | |
return [{ | |
"name": rndword(), | |
"description": " ".join(rndwords()), | |
"start": rndword(), | |
"stop": rndword(), | |
"poststop": rndword(), | |
"stop-timeout": 30, | |
"bus-name": ".".join(rndwords()), | |
"forking": not not random.randint(0,1), | |
} for i in range(random.randrange(2,5))] | |
def rndbinaries(): | |
return [{ | |
"name": rndword(), | |
"exec": rndword(), | |
} for i in range(random.randrange(2,5))] | |
def rndword(): | |
return next(rndsrc) | |
def rndwords(): | |
return [next(rndsrc) for i in range(random.randrange(2,10))] | |
def pkg(name, version, kind): | |
return { | |
"name": name, | |
"version": version, | |
"vendor": "The Random Benchmark Tests Company of Chessington, Plc.", | |
"icon": "/some/random/icon/yeah.png", | |
"type": kind, | |
"architectures": rndwords(), | |
"frameworks": rndwords(), | |
"services": rndservices(), | |
"binaries": rndbinaries(), | |
"explicit-license-agreement": False, | |
"license-version": 1, | |
} | |
def main(maxN): | |
try: | |
d=tempfile.mkdtemp(prefix='bnchroot') | |
n=0 | |
while n<maxN: | |
name=rndword() | |
if random.random() > .3: | |
kind="app" | |
this=name + "." + rndword() | |
else: | |
kind="framework" | |
this=name | |
if multiVersions: | |
versions=rndwords() | |
else: | |
versions=[rndword()] | |
for version in versions: | |
os.makedirs(os.path.join(d, "var", "lib", "apps", this, version, "canary")) | |
versions=versions[-3:] | |
for version in versions: | |
data=pkg(name, version, kind) | |
p=os.path.join(d, "apps", this, version, "meta") | |
os.makedirs(p) | |
with open(os.path.join(p, "package.yaml"), "w") as f: | |
yaml.dump(data, f, default_flow_style=False) | |
with open(os.path.join(p, "hashes.yaml"), "w") as f: | |
pass | |
n+=1 | |
if n>=maxN: | |
break | |
os.symlink(random.choice(versions), os.path.join(d, "apps", this, "current")) | |
print(d) | |
except StopIteration: | |
print(d) | |
except: | |
shutil.rmtree(d) | |
raise | |
if __name__=="__main__": | |
if len(sys.argv)>1: | |
maxN = int(sys.argv[1]) | |
else: | |
maxN = 100 | |
main(maxN) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment