-
Notifications
You must be signed in to change notification settings - Fork 22
/
create.py
90 lines (72 loc) · 2.48 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
# http://inamidst.com/saxo/
# Created by Sean B. Palmer
import os.path
import random
import sys
# Save PEP 3122!
if "." in __name__:
from . import common
from .saxo import path as saxo_path
else:
import common
from saxo import path as saxo_path
DEFAULT_CONFIG = """\
# See docs/config.md for more options
[server]
host = irc.freenode.net
port = 6667
[client]
nick = saxo%05i
channels = ##saxo #test
prefix = .
"""
E_DIRECTORY_EXISTS = """
You tried to make a directory that already exists. This is usually caused by
saxo already existing through a previous creation command. It may also be
caused by a path conflict, for example if you thought that you needed to
manually create the saxo directory beforehand.
This script won't write new material into any existing directories in case of
data corruption.
"""
E_UNMAKEABLE_DIRECTORY = """
The attempt to make this directory recursively, creating any necessary parent
directories in the process, failed. Check permissions on all parent directories
to make sure that we can write here. Also make sure that the parent path is a
directory.
"""
E_UNWRITEABLE_CONFIG = """
The saxo config file could not be written. Check that it exists, that it's a
regular file, and that you have adequate permissions to write on all parent
directories.
"""
def default(base=None):
if base is None:
base = os.path.expanduser("~/.saxo")
if os.path.isdir(base):
common.error("the directory `%s` already exists" % base,
E_DIRECTORY_EXISTS)
try: os.makedirs(base)
except Exception as err:
common.error("could not create the directory `%s`" % base,
E_UNMAKEABLE_DIRECTORY, err)
config = os.path.join(base, "config")
try:
with open(config, "w", encoding="ascii") as f:
# Generates a random bot name, from saxo00000 to saxo99999 inclusive
f.write(DEFAULT_CONFIG % random.randrange(0, 100000))
except Exception as err:
common.error("could not write the config file `%s`" % config,
E_UNWRITEABLE_CONFIG, err)
plugins = os.path.join(base, "plugins")
os.mkdir(plugins)
commands = os.path.join(base, "commands")
os.mkdir(commands)
common.populate(saxo_path, base)
print("Created %s" % config)
print("Modify this file with your own settings, and then run:")
print("")
if base:
print(" %s start %s" % (sys.argv[0], base))
else:
print(" %s start" % sys.argv[0])
return True