本文整理汇总了Python中mi.idk.driver_generator.DriverGenerator.resource_dir方法的典型用法代码示例。如果您正苦于以下问题:Python DriverGenerator.resource_dir方法的具体用法?Python DriverGenerator.resource_dir怎么用?Python DriverGenerator.resource_dir使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mi.idk.driver_generator.DriverGenerator
的用法示例。
在下文中一共展示了DriverGenerator.resource_dir方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: PackageDriver
# 需要导入模块: from mi.idk.driver_generator import DriverGenerator [as 别名]
# 或者: from mi.idk.driver_generator.DriverGenerator import resource_dir [as 别名]
#.........这里部分代码省略.........
self._store_package_files()
def run(self):
print "*** Starting Driver Packaging Process***"
if( self.run_qualification_tests() ):
self.package_driver()
print "Package Created: " + self.archive_path()
else:
sys.exit()
def zipfile(self):
"""
@brief Return the ZipFile object. Create the file if it isn't already open
@retval ZipFile object
"""
if(not self._zipfile):
self._zipfile = zipfile.ZipFile(self.archive_path(), mode="w")
return self._zipfile
def zipfile_compression(self):
"""
@brief What type of compression should we use for the package file. If we have access to zlib, we will compress
@retval Compression type
"""
if(self._compression): return self._compression
try:
import zlib
self._compression = zipfile.ZIP_DEFLATED
log.info("Setting compression level to deflated")
except:
log.info("Setting compression level to store only")
self._compression = zipfile.ZIP_STORED
def manifest(self):
"""
@brief Return the PackageManifest object. Create it if it doesn't already exist
@retval PackageManifest object
"""
if(not self._manifest):
self._manifest = PackageManifest(self.metadata)
return self._manifest
###
# Private Methods
###
def _store_package_files(self):
"""
@brief Store all files in zip archive and add them to the manifest file
"""
egg_generator = EggGenerator(self.metadata)
egg_file = egg_generator.save()
# Add egg
self._add_file(egg_file, 'egg', 'python driver egg package')
# Add the package metadata file
self._add_file(self.metadata.metadata_path(), description = 'package metadata')
# Add the qualification test log
self._add_file(self.log_path(), description = 'qualification tests results')
# Store additional resource files
self._store_resource_files()
# Finally save the manifest file. This must be last of course
self._add_file(self.manifest().manifest_path(), description = 'package manifest file')
def _store_resource_files(self):
"""
@brief Store additional files added by the driver developer. These files life in the driver resource dir.
"""
log.debug( " -- Searching for developer added resource files." )
for file in os.listdir(self.generator.resource_dir()):
log.debug(" ++ found: " + file)
desc = prompt.text( 'Describe ' + file )
self._add_file(self.generator.resource_dir() + "/" + file, 'resource', desc)
def _add_file(self, source, destdir=None, description=None):
"""
@brief Add a file to the zip package and store the file in the manifest.
"""
filename = os.path.basename(source)
dest = filename
if(destdir):
dest = "%s/%s" % (destdir, filename)
log.debug( "archive %s to %s" % (filename, dest) )
self.manifest().add_file(dest, description);
self.zipfile().write(source, dest, self.zipfile_compression())
示例2: PackageDriver
# 需要导入模块: from mi.idk.driver_generator import DriverGenerator [as 别名]
# 或者: from mi.idk.driver_generator.DriverGenerator import resource_dir [as 别名]
#.........这里部分代码省略.........
import zlib
self._compression = zipfile.ZIP_DEFLATED
log.info("Setting compression level to deflated")
except:
log.info("Setting compression level to store only")
self._compression = zipfile.ZIP_STORED
def manifest(self):
"""
@brief Return the PackageManifest object. Create it if it doesn't already exist
@retval PackageManifest object
"""
if(not self._manifest):
self._manifest = PackageManifest(self.metadata)
return self._manifest
###
# Private Methods
###
def _store_package_files(self):
"""
@brief Store all files in zip archive and add them to the manifest file
"""
# make sure metadata is up to date
self.metadata = Metadata(self.metadata.driver_make,
self.metadata.driver_model,
self.metadata.driver_name,
REPODIR + '/marine-integrations')
self.generator = DriverGenerator(self.metadata)
egg_generator = EggGenerator(self.metadata)
egg_file = egg_generator.save()
# Add egg
self._add_file(egg_file, 'egg', 'python driver egg package')
# Add the package metadata file
self._add_file(self.metadata.metadata_path(), description = 'package metadata')
# Add the qualification test log
self._add_file(self.log_path(), description = 'qualification tests results')
# Store parameter/command string description file
str_path = "%s/%s" % (self.generator.resource_dir(), self.string_file())
if os.path.exists(str_path):
self._add_file(str_path, 'resource', 'driver string file')
# Store additional resource files
self._store_resource_files()
# Finally save the manifest file. This must be last of course
self._add_file(self.manifest().manifest_path(), description = 'package manifest file')
def _store_resource_files(self):
"""
@brief Store additional files added by the driver developer. These
files live in the driver resource dir.
"""
resource_dir = os.path.join(self.metadata.relative_driver_path(), "resource")
log.debug(" -- Searching for developer added resource files in dir: %s",
resource_dir)
stringfile = self.string_file()
if os.path.exists(resource_dir):
for file in os.listdir(resource_dir):
if file != stringfile:
log.debug(" ++ found: " + file)
desc = prompt.text('Describe ' + file)
self._add_file(resource_dir + "/" + file, 'resource', desc)
else:
log.debug(" --- No resource directory found, skipping...")
def _add_file(self, source, destdir=None, description=None):
"""
@brief Add a file to the zip package and store the file in the manifest.
"""
filename = os.path.basename(source)
dest = filename
if(destdir):
dest = "%s/%s" % (destdir, filename)
log.debug("archive %s to %s" % (filename, dest))
self.manifest().add_file(dest, description);
self.zipfile().write(source, dest, self.zipfile_compression())
def _verify_version(self, version = None):
"""
Ensure we have a good version number and that it has not already been packaged and published
"""
if version == None:
version = self.metadata.version
if not version:
raise ValidationFailure("Driver version required in metadata")
p = re.compile("^\d+\.\d+\.\d+$")
if not p.findall("%s" % version):
raise ValidationFailure("Version format incorrect '%s', should be x.x.x" % version)