本文整理汇总了Python中exe.engine.uniqueidgenerator.UniqueIdGenerator.generate方法的典型用法代码示例。如果您正苦于以下问题:Python UniqueIdGenerator.generate方法的具体用法?Python UniqueIdGenerator.generate怎么用?Python UniqueIdGenerator.generate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类exe.engine.uniqueidgenerator.UniqueIdGenerator
的用法示例。
在下文中一共展示了UniqueIdGenerator.generate方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestUniqueId
# 需要导入模块: from exe.engine.uniqueidgenerator import UniqueIdGenerator [as 别名]
# 或者: from exe.engine.uniqueidgenerator.UniqueIdGenerator import generate [as 别名]
class TestUniqueId(unittest.TestCase):
def setUp(self):
self.generator = UniqueIdGenerator("David's Gen", sys.argv[0])
def testGenerate(self):
howMany = 10000
values = {}
for x in range(howMany):
id = self.generator.generate()
self.assert_(id.isalnum())
values[id] = 1
self.assertEqual(howMany, len(values))
示例2: Manifest
# 需要导入模块: from exe.engine.uniqueidgenerator import UniqueIdGenerator [as 别名]
# 或者: from exe.engine.uniqueidgenerator.UniqueIdGenerator import generate [as 别名]
class Manifest(object):
"""
Represents an imsmanifest xml file
"""
def __init__(self, config, outputDir, package, pages, scormType):
"""
Initialize
'outputDir' is the directory that we read the html from and also output
the mainfest.xml
"""
self.config = config
self.outputDir = outputDir
self.package = package
self.idGenerator = UniqueIdGenerator(package.name, config.exePath)
self.pages = pages
self.itemStr = ""
self.resStr = ""
self.scormType = scormType
self.dependencies = {}
def createMetaData(self, template):
"""
if user did not supply metadata title, description or creator
then use package title, description, or creator in imslrm
if they did not supply a package title, use the package name
if they did not supply a date, use today
"""
lrm = self.package.dublinCore.__dict__.copy()
if lrm.get('title', '') == '':
lrm['title'] = self.package.title
if lrm['title'] == '':
lrm['title'] = self.package.name
if lrm.get('description', '') == '':
lrm['description'] = self.package.description
if lrm['description'] == '':
lrm['description'] = self.package.name
if lrm.get('creator', '') == '':
lrm['creator'] = self.package.author
if lrm['date'] == '':
lrm['date'] = time.strftime('%Y-%m-%d')
# if they don't look like VCARD entries, coerce to fn:
for f in ('creator', 'publisher', 'contributors'):
if re.match('.*[:;]', lrm[f]) == None:
lrm[f] = u'FN:' + lrm[f]
xml = template % lrm
return xml
def save(self, filename):
"""
Save a imsmanifest file to self.outputDir
"""
out = open(self.outputDir/filename, "w")
if filename == "imsmanifest.xml":
out.write(self.createXML().encode('utf8'))
out.close()
if self.scormType == "scorm1.2":
templateFilename = self.config.xulDir/'templates'/'imslrm.xml'
template = open(templateFilename, 'rb').read()
xml = self.createMetaData(template)
out = open(self.outputDir/'imslrm.xml', 'wb')
out.write(xml.encode('utf8'))
out.close()
def createXML(self):
"""
returning XLM string for manifest file
"""
manifestId = unicode(self.idGenerator.generate())
orgId = unicode(self.idGenerator.generate())
# Add the namespaces
if self.scormType == "scorm1.2":
xmlStr = u'<?xml version="1.0" encoding="UTF-8"?>\n'
xmlStr += u'<!-- generated by eXe - http://exelearning.org -->\n'
xmlStr += u'<manifest identifier="'+manifestId+'" '
xmlStr += u'xmlns="http://www.imsproject.org/xsd/imscp_rootv1p1p2" '
xmlStr += u'xmlns:adlcp="http://www.adlnet.org/xsd/adlcp_rootv1p2" '
xmlStr += u'xmlns:imsmd="http://www.imsglobal.org/xsd/imsmd_v1p2" '
xmlStr += u'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" '
xmlStr += u"xsi:schemaLocation=\"http://www.imsproject.org/xsd/"
xmlStr += u"imscp_rootv1p1p2 imscp_rootv1p1p2.xsd "
xmlStr += u"http://www.imsglobal.org/xsd/imsmd_rootv1p2p1 "
xmlStr += u"imsmd_rootv1p2p1.xsd "
xmlStr += u"http://www.adlnet.org/xsd/adlcp_rootv1p2 "
xmlStr += u"adlcp_rootv1p2.xsd\" "
xmlStr += u"> \n"
xmlStr += u"<metadata> \n"
xmlStr += u" <schema>ADL SCORM</schema> \n"
xmlStr += u" <schemaversion>1.2</schemaversion> \n"
xmlStr += u" <adlcp:location>imslrm.xml"
xmlStr += u"</adlcp:location> \n"
xmlStr += u"</metadata> \n"
elif self.scormType == "scorm2004":
xmlStr = u'<?xml version="1.0" encoding="UTF-8"?>\n'
xmlStr += u'<!-- generated by eXe - http://exelearning.org -->\n'
xmlStr += u'<manifest identifier="'+manifestId+'" '
xmlStr += u'xmlns="http://www.imsproject.org/xsd/imscp_rootv1p1p2" '
xmlStr += u'xmlns:adlcp="http://www.adlnet.org/xsd/adlcp_rootv1p2" '
#.........这里部分代码省略.........
示例3: Manifest
# 需要导入模块: from exe.engine.uniqueidgenerator import UniqueIdGenerator [as 别名]
# 或者: from exe.engine.uniqueidgenerator.UniqueIdGenerator import generate [as 别名]
#.........这里部分代码省略.........
return xml
def save(self, filename):
"""
Save a imsmanifest file to self.outputDir
Two works: createXML and createMetaData
"""
out = open(self.outputDir / filename, "w")
if filename == "imsmanifest.xml":
out.write(self.createXML().encode("utf8"))
out.close()
# now depending on metadataType, <metadata> content is diferent:
if self.scormType == "scorm1.2" or self.scormType == "scorm2004":
if self.metadataType == "DC":
# if old template is desired, select imslrm.xml file:\r
# anything else, yoy should select:
templateFilename = self.config.webDir / "templates" / "imslrm.xml"
template = open(templateFilename, "rb").read()
elif self.metadataType == "LOMES":
template = None
elif self.metadataType == "LOM":
template = None
# Now the file with metadatas.
# Notice that its name is independent of metadataType:
xml = self.createMetaData(template)
out = open(self.outputDir / "imslrm.xml", "wb")
out.write(xml.encode("utf8"))
out.close()
def createXML(self):
"""
returning XLM string for manifest file
"""
manifestId = unicode(self.idGenerator.generate())
orgId = unicode(self.idGenerator.generate())
# Add the namespaces
if self.scormType == "scorm1.2":
xmlStr = u'<?xml version="1.0" encoding="UTF-8"?>\n'
xmlStr += u"<!-- Generated by eXe - http://exelearning.net -->\n"
xmlStr += u'<manifest identifier="' + manifestId + '" '
xmlStr += u'xmlns="http://www.imsproject.org/xsd/imscp_rootv1p1p2" '
xmlStr += u'xmlns:adlcp="http://www.adlnet.org/xsd/adlcp_rootv1p2" '
xmlStr += u'xmlns:imsmd="http://www.imsglobal.org/xsd/imsmd_v1p2" '
xmlStr += u'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" '
xmlStr += u'xsi:schemaLocation="http://www.imsproject.org/xsd/'
xmlStr += u"imscp_rootv1p1p2 imscp_rootv1p1p2.xsd "
xmlStr += u"http://www.imsglobal.org/xsd/imsmd_rootv1p2p1 "
xmlStr += u"imsmd_rootv1p2p1.xsd "
xmlStr += u"http://www.adlnet.org/xsd/adlcp_rootv1p2 "
xmlStr += u'adlcp_rootv1p2.xsd" '
xmlStr += u"> \n"
xmlStr += u"<metadata> \n"
xmlStr += u" <schema>ADL SCORM</schema> \n"
xmlStr += u" <schemaversion>1.2</schemaversion> \n"
xmlStr += u" <adlcp:location>imslrm.xml"
xmlStr += u"</adlcp:location> \n"
xmlStr += u"</metadata> \n"
elif self.scormType == "scorm2004":
xmlStr = u'<?xml version="1.0" encoding="UTF-8"?>\n'
xmlStr += u"<!-- Generated by eXe - http://exelearning.net -->\n"
xmlStr += u'<manifest identifier="' + manifestId + '" \n'
xmlStr += u'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" \n'
xmlStr += u'xmlns:adlcp="http://www.adlnet.org/xsd/adlcp_v1p3" \n'
xmlStr += u'xmlns:adlseq="http://www.adlnet.org/xsd/adlseq_v1p3" \n'
示例4: Manifest
# 需要导入模块: from exe.engine.uniqueidgenerator import UniqueIdGenerator [as 别名]
# 或者: from exe.engine.uniqueidgenerator.UniqueIdGenerator import generate [as 别名]
class Manifest(object):
"""
Represents an imsmanifest xml file
"""
def __init__(self, config, outputDir, package, pages, metadataType):
"""
Initialize
'outputDir' is the directory that we read the html from and also output
the mainfest.xml
"""
self.config = config
self.outputDir = outputDir
self.package = package
self.idGenerator = UniqueIdGenerator(package.name, config.exePath)
self.pages = pages
self.metadataType = metadataType
self.itemStr = ""
self.resStr = ""
def createMetaData(self):
"""
if user did not supply metadata title, description or creator
then use package title, description, or creator in imslrm
if they did not supply a package title, use the package name
if they did not supply a date, use today
"""
xml = ""
namespace = "lom:"
# depending on (user desired) the metadata type:
if self.metadataType == "LOMES":
output = StringIO.StringIO()
metadata = copy.deepcopy(self.package.lomEs)
title = metadata.get_general().get_title() or lomsubs.titleSub([])
if not title.get_string():
title.add_string(lomsubs.LangStringSub(self.package.lang.encode("utf-8"), self.package.name))
metadata.get_general().set_title(title)
metadata.export(output, 0, namespace_=namespace, pretty_print=False)
xml = output.getvalue()
if self.metadataType == "LOM":
output = StringIO.StringIO()
metadata = copy.deepcopy(self.package.lom)
title = metadata.get_general().get_title() or lomsubs.titleSub([])
if not title.get_string():
title.add_string(lomsubs.LangStringSub(self.package.lang.encode("utf-8"), self.package.name))
metadata.get_general().set_title(title)
metadata.export(output, 0, namespace_=namespace, pretty_print=False)
xml = output.getvalue()
if self.metadataType == "DC":
lrm = self.package.dublinCore.__dict__.copy()
# use package values in absentia:
if lrm.get("title", "") == "":
lrm["title"] = self.package.title
if lrm["title"] == "":
lrm["title"] = self.package.name
if lrm.get("description", "") == "":
lrm["description"] = self.package.description
if lrm["description"] == "":
lrm["description"] = self.package.name
if lrm.get("creator", "") == "":
lrm["creator"] = self.package.author
if lrm["date"] == "":
lrm["date"] = time.strftime("%Y-%m-%d")
# if they don't look like VCARD entries, coerce to fn:
for f in ("creator", "publisher", "contributors"):
if re.match(".*[:;]", lrm[f]) == None:
lrm[f] = u"FN:" + lrm[f]
templateFilename = self.config.webDir / "templates" / "imslrm.xml"
template = open(templateFilename, "rb").read()
xml = template % lrm
out = open(self.outputDir / "imslrm.xml", "wb")
out.write(xml.encode("utf8"))
out.close()
xml = "<adlcp:location>imslrm.xml</adlcp:location>"
return xml
def save(self, filename):
"""
Save a imsmanifest file to self.outputDir
"""
out = open(self.outputDir / filename, "w")
if filename == "imsmanifest.xml":
out.write(self.createXML().encode("utf8"))
out.close()
def createXML(self):
"""
returning XLM string for manifest file
"""
manifestId = self.idGenerator.generate()
orgId = self.idGenerator.generate()
xmlStr = (
u"""<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated by eXe - http://exelearning.net -->
<manifest identifier="%s"
xmlns="http://www.imsglobal.org/xsd/imscp_v1p1"
xmlns:imsmd="http://www.imsglobal.org/xsd/imsmd_v1p2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:lom="http://ltsc.ieee.org/xsd/LOM"
#.........这里部分代码省略.........
示例5: Manifest
# 需要导入模块: from exe.engine.uniqueidgenerator import UniqueIdGenerator [as 别名]
# 或者: from exe.engine.uniqueidgenerator.UniqueIdGenerator import generate [as 别名]
#.........这里部分代码省略.........
"""
modifiedMetaData = False
out = open(self.outputDir/filename, "w")
if filename == "imsmanifest.xml":
out.write(self.createXML().encode('utf8'))
out.close()
# now depending on metadataType, <metadata> content is diferent:
if self.scormType == "scorm1.2" or self.scormType == "scorm2004":
if self.metadataType == 'DC':
# if old template is desired, select imslrm.xml file:\r
# anything else, yoy should select:
templateFilename = self.config.webDir/'templates'/'imslrm.xml'
template = open(templateFilename, 'rb').read()
elif self.metadataType == 'LOMES':
template = None
elif self.metadataType == 'LOM':
template = None
# Now the file with metadatas.
# Notice that its name is independent of metadataType:
metaData = self.createMetaData(template)
xml = metaData['xml']
modifiedMetaData = metaData['modifiedMetaData']
out = open(self.outputDir/'imslrm.xml', 'wb')
out.write(xml.encode('utf8'))
out.close()
return modifiedMetaData
def createXML(self):
"""
returning XLM string for manifest file
"""
manifestId = unicode(self.idGenerator.generate())
orgId = unicode(self.idGenerator.generate())
# Add the namespaces
if self.scormType == "scorm1.2":
xmlStr = u'<?xml version="1.0" encoding="UTF-8"?>\n'
xmlStr += u'<!-- Generated by eXe - http://exelearning.net -->\n'
xmlStr += u'<manifest identifier="'+manifestId+'" '
xmlStr += u'xmlns="http://www.imsproject.org/xsd/imscp_rootv1p1p2" '
xmlStr += u'xmlns:adlcp="http://www.adlnet.org/xsd/adlcp_rootv1p2" '
xmlStr += u'xmlns:imsmd="http://www.imsglobal.org/xsd/imsmd_v1p2" '
xmlStr += u'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" '
xmlStr += u"xsi:schemaLocation=\"http://www.imsproject.org/xsd/"
xmlStr += u"imscp_rootv1p1p2 imscp_rootv1p1p2.xsd "
xmlStr += u"http://www.imsglobal.org/xsd/imsmd_rootv1p2p1 "
xmlStr += u"imsmd_rootv1p2p1.xsd "
xmlStr += u"http://www.adlnet.org/xsd/adlcp_rootv1p2 "
xmlStr += u"adlcp_rootv1p2.xsd\" "
xmlStr += u"> \n"
xmlStr += u"<metadata> \n"
xmlStr += u" <schema>ADL SCORM</schema> \n"
xmlStr += u" <schemaversion>1.2</schemaversion> \n"
xmlStr += u" <adlcp:location>imslrm.xml"
xmlStr += u"</adlcp:location> \n"
xmlStr += u"</metadata> \n"
elif self.scormType == "scorm2004":
xmlStr = u'<?xml version="1.0" encoding="UTF-8"?>\n'
xmlStr += u'<!-- Generated by eXe - http://exelearning.net -->\n'
xmlStr += u'<manifest identifier="'+manifestId+'" \n'
xmlStr += u'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" \n'
xmlStr += u'xmlns:adlcp="http://www.adlnet.org/xsd/adlcp_v1p3" \n'
xmlStr += u'xmlns:adlseq="http://www.adlnet.org/xsd/adlseq_v1p3" \n'