Added support for .ign files to wesnoth_addon_manager
This commit is contained in:
parent
1b07c2c3b3
commit
49fb3688e8
2 changed files with 37 additions and 8 deletions
|
@ -1,5 +1,5 @@
|
|||
import gzip, zlib, StringIO
|
||||
import socket, struct, glob, sys, shutil, threading, os
|
||||
import socket, struct, glob, sys, shutil, threading, os, fnmatch
|
||||
import wesnoth.wmldata as wmldata
|
||||
import wesnoth.wmlparser as wmlparser
|
||||
|
||||
|
@ -11,8 +11,6 @@ dumpi = 0
|
|||
class CampaignClient:
|
||||
# First port listed will be used as default.
|
||||
portmap = (("15004", "1.7.x"), ("15003", "1.6.x"), ("15005", "1.4.x"))
|
||||
# Files with these suffixes will not be downloaded
|
||||
excluded = ("~", "-bak", ".pbl", ".exe", ".com", ".bat", ".scr", ".sh")
|
||||
|
||||
def __init__(self, address = None):
|
||||
"""
|
||||
|
@ -301,7 +299,7 @@ class CampaignClient:
|
|||
|
||||
return None
|
||||
|
||||
def put_campaign(self, name, cfgfile, directory, stuff):
|
||||
def put_campaign(self, name, cfgfile, directory, ign, stuff):
|
||||
"""
|
||||
Uploads a campaign to the server. The title, name, author, passphrase,
|
||||
description, version and icon parameters are what would normally be
|
||||
|
@ -320,6 +318,10 @@ class CampaignClient:
|
|||
request.insert(data)
|
||||
|
||||
def put_file(name, f):
|
||||
for ig in ign:
|
||||
if ig[-1] != "/" and fnmatch.fnmatch(name, ig):
|
||||
print("Ignored file", name)
|
||||
return None
|
||||
fileNode = wmldata.DataSub("file")
|
||||
|
||||
# Order in which we apply escape sequences matters.
|
||||
|
@ -336,16 +338,18 @@ class CampaignClient:
|
|||
return fileNode
|
||||
|
||||
def put_dir(name, path):
|
||||
for ig in ign:
|
||||
if ig[-1] == "/" and fnmatch.fnmatch(name, ig[:-1]):
|
||||
print("Ignored dir", name)
|
||||
return None
|
||||
dataNode = wmldata.DataSub("dir")
|
||||
dataNode.set_text_val("name", name)
|
||||
for fn in glob.glob(path + "/*"):
|
||||
if os.path.isdir(fn):
|
||||
sub = put_dir(os.path.basename(fn), fn)
|
||||
elif [x for x in CampaignClient.excluded if fn.endswith(x)]:
|
||||
continue
|
||||
else:
|
||||
sub = put_file(os.path.basename(fn), file(fn))
|
||||
dataNode.insert(sub)
|
||||
if sbu: dataNode.insert(sub)
|
||||
return dataNode
|
||||
|
||||
# Only used if it's an old-style campaign directory
|
||||
|
|
|
@ -269,6 +269,7 @@ if __name__ == "__main__":
|
|||
name = os.path.basename(options.upload)
|
||||
wmldir = options.upload
|
||||
cfgfile = None # _main.cfg will be uploaded with the rest
|
||||
ignfile = os.path.join(options.upload, "_server.ign")
|
||||
else:
|
||||
# Old style with external .pbl file
|
||||
pblfile = options.upload
|
||||
|
@ -276,15 +277,39 @@ if __name__ == "__main__":
|
|||
name = os.path.splitext(name)[0]
|
||||
wmldir = os.path.join(os.path.dirname(options.upload), name)
|
||||
cfgfile = options.upload.replace(".pbl", ".cfg")
|
||||
ignfile = options.upload.replace(".pbl", ".ign")
|
||||
|
||||
pbl = wmldata.read_file(pblfile, "PBL")
|
||||
if os.path.exists(ignfile):
|
||||
ign = open(ignfile).readlines()
|
||||
else:
|
||||
ign = [
|
||||
".*",
|
||||
".*/",
|
||||
"#*#",
|
||||
"*~",
|
||||
"*-bak",
|
||||
"*.swp",
|
||||
"*.pbl",
|
||||
"*.ign",
|
||||
"_info.cfg",
|
||||
"*.exe",
|
||||
"*.bat",
|
||||
"*.cmd",
|
||||
"*.com",
|
||||
"*.scr",
|
||||
"*.sh",
|
||||
"*.js",
|
||||
"*.vbs",
|
||||
"*.o",
|
||||
"Thumbs.db"]
|
||||
|
||||
stuff = {}
|
||||
for field in ["title", "author", "passphrase", "description",
|
||||
"version", "icon", "type", "email"]:
|
||||
stuff[field] = pbl.get_text_val(field)
|
||||
|
||||
mythread = cs.put_campaign_async(name, cfgfile, wmldir, stuff)
|
||||
mythread = cs.put_campaign_async(name, cfgfile, wmldir, ign, stuff)
|
||||
|
||||
pcounter = 0
|
||||
while not mythread.event.isSet():
|
||||
|
|
Loading…
Add table
Reference in a new issue