Welcome to mirror list, hosted at ThFree Co, Russian Federation.

code.py « exp_control « expansions - github.com/alkorgun/blacksmith-2.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: cd2ad1178757b94cec45ecdfa1b1ada0f4a6c8d2 (plain)
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
# coding: utf-8

#  BlackSmith mark.2
exp_name = "exp_control" # /code.py v.x7
#  Id: 09~7b
#  Code © (2011-2012) by WitcherGeralt [alkorgun@gmail.com]

expansion_register(exp_name)

class expansion_temp(expansion):

	def __init__(self, name):
		expansion.__init__(self, name)

	def command_expinfo(self, ltype, source, body, disp):
		get_state = lambda filename: (self.AnsBase[1] if os.path.isfile(filename) else self.AnsBase[2])
		if body:
			exp_name = body.lower()
			if check_nosimbols(exp_name):
				if expansions.has_key(exp_name):
					answer = self.AnsBase[0]
					code_file = get_state(expansions[exp_name].file)
					insc_file = get_state(expansions[exp_name].insc)
					answer += "\n%s - %s - %s - %s" % (exp_name, self.AnsBase[3], code_file, insc_file)
					if expansions[exp_name].cmds:
						answer += self.AnsBase[4] % (", ".join(expansions[exp_name].cmds))
					if expansions[exp_name].desc:
						answer += self.AnsBase[5] % ("; ".join(["%s: (%s)" % (eh, ", ".join([inst.func_name for inst in ls])) for eh, ls in sorted(expansions[exp_name].desc.items())]))
				else:
					exp = expansion(exp_name)
					if os.path.exists(exp.path):
						answer = self.AnsBase[0]
						code_file = get_state(exp.file)
						insc_file = get_state(exp.insc)
						answer += "\n%s - %s - %s - %s" % (exp_name, self.AnsBase[6], code_file, insc_file)
					else:
						answer = self.AnsBase[7]
			else:
				answer = self.AnsBase[7]
		else:
			answer, Number = self.AnsBase[8], itypes.Number()
			for exp_name in sorted(expansions.keys()):
				code_file = get_state(expansions[exp_name].file)
				insc_file = get_state(expansions[exp_name].insc)
				answer += "\n%d) %s - %s - %s" % (Number.plus(), exp_name, code_file, insc_file)
			elexps = []
			for exp_name in sorted(os.listdir(ExpsDir)):
				if (".svn") == (exp_name) or expansions.has_key(exp_name):
					continue
				if os.path.isdir(os.path.join(ExpsDir, exp_name)):
					exp = expansion(exp_name)
					code_file = get_state(exp.file)
					insc_file = get_state(exp.insc)
					elexps.append("%d) %s - %s - %s" % (Number.plus(), exp_name, code_file, insc_file))
			elexps_len = len(elexps)
			if elexps_len:
				answer += self.AnsBase[9] % (elexps_len, chr(10).join(elexps))
		Answer(answer, ltype, source, disp)

	ReloadSemaphore = iThr.Semaphore()

	def command_expload(self, ltype, source, body, disp):
		if body:
			exp_name = body.lower()
			if check_nosimbols(exp_name):
				if expansions.has_key(exp_name):
					if os.path.isfile(expansions[exp_name].file):
						with self.ReloadSemaphore:
							rslt = expansions[exp_name].load()
							if rslt[1]:
								exp = expansion_temp(exp_name)
								exp.initialize_exp()
								exp.initialize_all()
								answer = self.AnsBase[10] % (rslt[0])
							else:
								expansions[exp_name].dels(True)
								answer = self.AnsBase[11] % (rslt[0], "\n\t* %s: %s") % (rslt[2])
					else:
						answer = self.AnsBase[12]
				else:
					expansions[exp_name] = exp = expansion(exp_name)
					if exp.isExp:
						with self.ReloadSemaphore:
							rslt = exp.load()
							if rslt[1] and expansions.has_key(exp_name):
								exp = expansion_temp(exp_name)
								exp.initialize_exp()
								exp.initialize_all()
								answer = self.AnsBase[10] % (rslt[0])
							else:
								exp.dels(True)
								if rslt[2]:
									answer = self.AnsBase[11] % (rslt[0], "\n\t* %s: %s") % (rslt[2])
								else:
									answer = self.AnsBase[13] % (rslt[0])
					else:
						exp.dels(True)
						answer = self.AnsBase[7]
			else:
				answer = self.AnsBase[7]
		else:
			answer = AnsBase[1]
		Answer(answer, ltype, source, disp)

	def command_expunload(self, ltype, source, body, disp):
		if body:
			body = body.split()
			exp_name = (body.pop(0)).lower()
			if expansions.has_key(exp_name):
				if body:
					handler, Name = None, body.pop(0)
					list = []
					for ls in expansions[exp_name].desc.values():
						for instance in ls:
							inst = instance.func_name
							list.append(inst)
							if inst == Name:
								handler = instance
								break
					if handler:
						with self.ReloadSemaphore:
							expansions[exp_name].funcs_del(handler)
						answer = AnsBase[4]
					elif list:
						answer = self.AnsBase[14] % (", ".join(sorted(list)))
					else:
						answer = self.AnsBase[15] % (exp_name)
				else:
					with self.ReloadSemaphore:
						expansions[exp_name].dels(True)
					answer = AnsBase[4]
			else:
				answer = self.AnsBase[7]
		else:
			answer = AnsBase[1]
		Answer(answer, ltype, source, disp)

	def command_tumbler(self, ltype, source, body, disp):
		if body:
			ls = body.split()
			command = (ls.pop(0)).lower()
			if Cmds.has_key(command):
				obj = Cmds.get(command)
				if ls:
					body = (ls.pop(0)).lower()
					if body in ("on", "вкл".decode("utf-8")):
						if not obj.isAvalable:
							if obj.handler:
								obj.isAvalable = True
								answer = AnsBase[4]
							else:
								answer = AnsBase[19] % (command)
						else:
							answer = self.AnsBase[16] % (command)
					elif body in ("off", "выкл".decode("utf-8")):
						if obj.isAvalable:
							if obj.handler:
								obj.isAvalable = False
								answer = AnsBase[4]
							else:
								answer = AnsBase[19] % (command)
						else:
							answer = self.AnsBase[17] % (command)
					else:
						answer = AnsBase[2]
				else:
					answer = self.AnsBase[16 if obj.isAvalable else 17] % (command)
			else:
				answer = AnsBase[6]
		else:
			oCmds = [cmd for cmd, obj in Cmds.iteritems() if not obj.isAvalable]
			if oCmds:
				answer = ", ".join(oCmds)
			else:
				answer = self.AnsBase[18]
		Answer(answer, ltype, source, disp)

	commands = (
		(command_expinfo, "expinfo", 7,),
		(command_expload, "expload", 8,),
		(command_expunload, "expunload", 8,),
		(command_tumbler, "tumbler", 8,)
					)