Maintain catalog: argument parsing
This commit is contained in:
+45
-14
@@ -6,11 +6,19 @@ import subprocess
|
|||||||
import shutil # for copy2
|
import shutil # for copy2
|
||||||
import catalogTags
|
import catalogTags
|
||||||
import sgprops
|
import sgprops
|
||||||
|
#from multiprocessing import Pool
|
||||||
|
import argparse
|
||||||
|
import urllib2
|
||||||
|
|
||||||
import svn_catalog_repository
|
import svn_catalog_repository
|
||||||
import git_catalog_repository
|
import git_catalog_repository
|
||||||
import git_discrete_repository
|
import git_discrete_repository
|
||||||
|
|
||||||
|
parser = argparse.ArgumentParser()
|
||||||
|
parser.add_argument("--clean", help="Regenerate every package", type=bool)
|
||||||
|
parser.add_argument("dir", help="Catalog directory")
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
standardTagSet = frozenset(catalogTags.tags)
|
standardTagSet = frozenset(catalogTags.tags)
|
||||||
def isNonstandardTag(t):
|
def isNonstandardTag(t):
|
||||||
return t not in standardTagSet
|
return t not in standardTagSet
|
||||||
@@ -244,7 +252,6 @@ def initScmRepository(node):
|
|||||||
raise RuntimeError("Unspported SCM type:" + scmType)
|
raise RuntimeError("Unspported SCM type:" + scmType)
|
||||||
|
|
||||||
def processUpload(node, outputPath):
|
def processUpload(node, outputPath):
|
||||||
print "Enabled value is:", node.getValue("enabled")
|
|
||||||
if not node.getValue("enabled", True):
|
if not node.getValue("enabled", True):
|
||||||
print "Upload disabled"
|
print "Upload disabled"
|
||||||
return
|
return
|
||||||
@@ -254,23 +261,25 @@ def processUpload(node, outputPath):
|
|||||||
subprocess.call(["rsync", node.getValue("args", "-az"), ".",
|
subprocess.call(["rsync", node.getValue("args", "-az"), ".",
|
||||||
node.getValue("remote")],
|
node.getValue("remote")],
|
||||||
cwd = outputPath)
|
cwd = outputPath)
|
||||||
|
elif (uploadType == "rsync-ssh"):
|
||||||
|
subprocess.call(["rsync", node.getValue("args", "-azve"),
|
||||||
|
"ssh", ".",
|
||||||
|
node.getValue("remote")],
|
||||||
|
cwd = outputPath)
|
||||||
elif (uploadType == "scp"):
|
elif (uploadType == "scp"):
|
||||||
subprocess.call(["scp", node.getValue("args", "-r"), outputPath,
|
subprocess.call(["scp", node.getValue("args", "-r"), ".",
|
||||||
node.getValue("remote")])
|
node.getValue("remote")],
|
||||||
|
cwd = outputPath)
|
||||||
else:
|
else:
|
||||||
raise RuntimeError("Unsupported upload type:" + uploadType)
|
raise RuntimeError("Unsupported upload type:" + uploadType)
|
||||||
|
|
||||||
# dictionary
|
# dictionary
|
||||||
packages = {}
|
packages = {}
|
||||||
|
|
||||||
if len(sys.argv) < 2:
|
rootDir = args.dir
|
||||||
raise RuntimeError("no root dir specified")
|
|
||||||
|
|
||||||
rootDir = sys.argv[1]
|
|
||||||
if not os.path.isabs(rootDir):
|
if not os.path.isabs(rootDir):
|
||||||
rootDir = os.path.abspath(rootDir)
|
rootDir = os.path.abspath(rootDir)
|
||||||
os.chdir(rootDir)
|
os.chdir(rootDir)
|
||||||
print "Root path is:", rootDir
|
|
||||||
|
|
||||||
configPath = 'catalog.config.xml'
|
configPath = 'catalog.config.xml'
|
||||||
if not os.path.exists(configPath):
|
if not os.path.exists(configPath):
|
||||||
@@ -286,19 +295,19 @@ if outPath is None:
|
|||||||
elif not os.path.isabs(outPath):
|
elif not os.path.isabs(outPath):
|
||||||
outPath = os.path.join(rootDir, "output")
|
outPath = os.path.join(rootDir, "output")
|
||||||
|
|
||||||
|
if args.clean:
|
||||||
|
print "Cleaning output"
|
||||||
|
shutil.rmtree(outPath)
|
||||||
|
|
||||||
if not os.path.exists(outPath):
|
if not os.path.exists(outPath):
|
||||||
os.mkdir(outPath)
|
os.mkdir(outPath)
|
||||||
|
|
||||||
print "Output path is:" + outPath
|
|
||||||
|
|
||||||
thumbnailPath = os.path.join(outPath, config.getValue('thumbnail-dir', "thumbnails"))
|
thumbnailPath = os.path.join(outPath, config.getValue('thumbnail-dir', "thumbnails"))
|
||||||
if not os.path.exists(thumbnailPath):
|
if not os.path.exists(thumbnailPath):
|
||||||
os.mkdir(thumbnailPath)
|
os.mkdir(thumbnailPath)
|
||||||
|
|
||||||
thumbnailUrl = config.getValue('thumbnail-url')
|
thumbnailUrl = config.getValue('thumbnail-url')
|
||||||
|
|
||||||
print "Thumbnail url is:", thumbnailUrl
|
|
||||||
|
|
||||||
for i in config.getChildren("include-dir"):
|
for i in config.getChildren("include-dir"):
|
||||||
if not os.path.exists(i.value):
|
if not os.path.exists(i.value):
|
||||||
print "Skipping missing include path:", i.value
|
print "Skipping missing include path:", i.value
|
||||||
@@ -317,6 +326,19 @@ for g in config.getChildren("aircraft-dir"):
|
|||||||
for p in scanPackages(g.value):
|
for p in scanPackages(g.value):
|
||||||
packages[p.id] = p
|
packages[p.id] = p
|
||||||
|
|
||||||
|
if not os.path.exists(existingCatalogPath):
|
||||||
|
try:
|
||||||
|
# can happen on new or from clean, try to pull current
|
||||||
|
# catalog from the upload location
|
||||||
|
response = urllib2.urlopen(config.getValue("template/url"), timeout = 5)
|
||||||
|
content = response.read()
|
||||||
|
f = open(existingCatalogPath, 'w' )
|
||||||
|
f.write( content )
|
||||||
|
f.close()
|
||||||
|
except urllib2.URLError as e:
|
||||||
|
print "Downloading current catalog failed", e
|
||||||
|
|
||||||
|
|
||||||
if os.path.exists(existingCatalogPath):
|
if os.path.exists(existingCatalogPath):
|
||||||
try:
|
try:
|
||||||
previousCatalog = sgprops.readProps(existingCatalogPath)
|
previousCatalog = sgprops.readProps(existingCatalogPath)
|
||||||
@@ -348,9 +370,18 @@ for p in packages.values():
|
|||||||
else:
|
else:
|
||||||
p.useExistingCatalogData()
|
p.useExistingCatalogData()
|
||||||
|
|
||||||
|
|
||||||
|
# def f(x):
|
||||||
|
# x.generateZip(outPath)
|
||||||
|
# x.extractThumbnails(thumbnailPath)
|
||||||
|
# return True
|
||||||
|
#
|
||||||
|
# p = Pool(8)
|
||||||
|
# print(p.map(f,packagesToGenerate))
|
||||||
|
|
||||||
for p in packagesToGenerate:
|
for p in packagesToGenerate:
|
||||||
p.generateZip(outPath)
|
p.generateZip(outPath)
|
||||||
p.extractThumbnails(thumbnailPath)
|
p.extractThumbnails(thumbnailPath)
|
||||||
|
|
||||||
print "Creating catalog"
|
print "Creating catalog"
|
||||||
for p in packages.values():
|
for p in packages.values():
|
||||||
|
|||||||
Reference in New Issue
Block a user