Crossfire Server, Trunk
convert.py
Go to the documentation of this file.
1 #! /usr/bin/env python3
2 # -*- coding: utf-8 -*-
3 
4 # This script generates the various files for a guild, and installs them
5 # to the correct location.
6 # It should be launched with templates/guilds as working directory.
7 #
8 # Files that will be copied are specified in 'filelist.py'.
9 #
10 # Parameters are in the form:
11 # name region directory entrance x y storage x y
12 # with:
13 # - name: guild name, like PoisonedDagger; must not contain spaces
14 # - region: what region to give the maps of the guild (eg "scorn")
15 # - directory: where to put maps for this guild, relative to the maps's root directory
16 # - entrance: map with the entrance to the guild, relative to maps's root directory
17 # - x and y: coordinates in 'entrance' with the guild entrance
18 # - storage: map with the storage room's entrance, can be 'same' to be equal to 'entrance'
19 # - x and y: coordinates in 'storage' for the storage room's entrance
20 
21 import os, sys
22 from filelist import filelist
23 from optparse import OptionParser
24 parser = OptionParser()
25 parser.add_option("--local-copy",dest="local_copy",help="puts a copy of generated files in a templates/guild/<guildname>",default=False,action="store_true")
26 parser.add_option("--no-install-copy",dest="install_copy",help="installs a remote copy to the destination directory. If false, only configures the files for installation.",default=True,action="store_false")
27 (options, args) = parser.parse_args(sys.argv)
28 ToGuild=args[1]
29 ToRegion=args[2]
30 
31 # set to 1 to put a copy of generated files in a subdirectory of templates/guild
32 local_copy = options.local_copy
33 
34 
35 Ctl=0
36 if len(sys.argv)>=7:
37  ToFolder=args[3]
38  ExitPath=args[4]
39  ExitX,ExitY=args[5],args[6]
40  Ctl=1
41  if args[7]=="same":
42  args[7]=args[4]
43  StorageExit=args[7]
44  StorageX,StorageY=args[8],args[9]
45  GuildName = ' '.join(args[10:])
46 
47 if local_copy:
48  os.system('mkdir '+ToGuild)
49 
50 for i in filelist:
51  fromfile=open(i, 'r')
52  filecontents=fromfile.read()
53  fromfile.close()
54  filecontents=filecontents.replace('GUILD_TEMPLATE', ToGuild)
55  if Ctl==1:
56  filecontents=filecontents.replace("region Template","region "+ToRegion).replace("TemplateExit", ExitPath).replace("TemplateHP", ExitX).replace("TemplateSP", ExitY).replace("Exit+1X", StorageX).replace("ExitY",StorageY).replace("ExitX",StorageX).replace("ExitPath",StorageExit)
57  filecontents=filecontents.replace("[Template]",GuildName)
58 
59  if local_copy:
60  tofile=open('./'+ToGuild+'/'+i, 'w')
61  tofile.write(filecontents)
62  tofile.close()
63 
64  if Ctl==1:
65  secondtofile=open('../../'+ToFolder+"/"+i,'w')
66  secondtofile.write(filecontents)
67  secondtofile.close()
CFBank.open
def open()
Definition: CFBank.py:69
replace
Definition: replace.py:1