class SwitchDriver: """ Main class for running the switch driver process. """ def fetch_metadata(self): """ @brief collect metadata from the user """ self.driver_make = prompt.text("Driver Make") self.driver_model = prompt.text("Driver Model") self.driver_name = prompt.text("Driver Name") self.metadata = Metadata(self.driver_make, self.driver_model, self.driver_name) def fetch_comm_config(self): """ @brief collect connection information for the logger from the user """ config_path = "%s/%s" % (self.metadata.driver_dir(), CommConfig.config_filename()) self.comm_config = CommConfig.get_config_from_console(config_path) self.comm_config.get_from_console() def run(self): """ @brief Run it. """ print("*** Starting Switch Driver Process***") self.fetch_metadata() self.fetch_comm_config() self.metadata.link_current_metadata()
class SwitchDriver(): """ Main class for running the switch driver process. """ def fetch_metadata(self): """ @brief collect metadata from the user """ self.driver_make = prompt.text('Driver Make') self.driver_model = prompt.text('Driver Model') self.driver_name = prompt.text('Driver Name') self.metadata = Metadata(self.driver_make, self.driver_model, self.driver_name) def fetch_comm_config(self): """ @brief collect connection information for the logger from the user """ config_path = "%s/%s" % (self.metadata.driver_dir(), CommConfig.config_filename()) self.comm_config = CommConfig.get_config_from_console(config_path) self.comm_config.get_from_console() def run(self): """ @brief Run it. """ print("*** Starting Switch Driver Process***") self.fetch_metadata() self.fetch_comm_config() self.metadata.link_current_metadata()
def fetch_metadata(self): """ @brief collect metadata from the user """ self.driver_make = prompt.text('Driver Make') self.driver_model = prompt.text('Driver Model') self.driver_name = prompt.text('Driver Name') self.metadata = Metadata(self.driver_make, self.driver_model, self.driver_name)
def test_constructor(self): """ Test object creation """ default_metadata = Metadata() self.assertTrue(default_metadata) specific_metadata = Metadata('seabird', 'sbe37smb', 'ooicore') self.assertTrue(specific_metadata) failure_metadata = None try: failure_metadata = Metadata('seabird') except InvalidParameters, e: self.assertTrue(e)
def overwrite(self): """ @brief Overwrite the current files with what is stored in the current metadata file. """ self.metadata = Metadata() self.comm_config = CommConfig.get_config_from_file(self.metadata) self.generate_code(force = True)
def test_list(self): """ Test the full file manifest """ filelist = DriverFileList(Metadata(), ROOTDIR, self.implfile(), self.nosefile()) self.assertTrue(filelist) known_files = [ 'mi/__init__.py', 'mi/base.py', 'mi/base2.py', 'mi/base3.py', 'mi/base4.py', 'mi/foo/__init__.py', 'mi/foo/impl.py', 'mi/foo/res/test_file', 'mi/foo/test/__init__.py', 'mi/foo/test/test_process.py', ] files = filelist.files() log.debug("F: %s" % files) self.assertEqual(sorted(files), sorted(known_files)) pass
def fetch_metadata(self): """ @brief collect metadata from the user """ self.driver_make = prompt.text("Driver Make") self.driver_model = prompt.text("Driver Model") self.driver_name = prompt.text("Driver Name") self.metadata = Metadata(self.driver_make, self.driver_model, self.driver_name)
class StartDriver(): """ Main class for running the start driver process. """ def fetch_metadata(self): """ @brief collect metadata from the user """ self.metadata = Metadata() self.metadata.get_from_console() def fetch_comm_config(self): """ @brief collect connection information for the logger from the user """ config_path = "%s/%s" % (self.metadata.driver_dir(), CommConfig.config_filename()) self.comm_config = CommConfig.get_config_from_console(config_path) self.comm_config.get_from_console() def generate_code(self, force = False): """ @brief generate the directory structure, code and tests for the new driver. """ driver = DriverGenerator( self.metadata, force = force ) driver.generate() def overwrite(self): """ @brief Overwrite the current files with what is stored in the current metadata file. """ self.metadata = Metadata() self.comm_config = CommConfig.get_config_from_file(self.metadata) self.generate_code(force = True) def run(self): """ @brief Run it. """ print( "*** Starting Driver Creation Process***" ) self.fetch_metadata() self.fetch_comm_config() self.generate_code()
def __init__(self): """ @brief ctor """ self.metadata = Metadata() self._zipfile = None self._manifest = None self._compression = None self.generator = DriverGenerator(self.metadata) # Set compression level self.zipfile_compression()
def test_extra_list(self): """ Find all the files in the driver directory """ rootdir = dirname(TESTDIR) filelist = DriverFileList(Metadata(), ROOTDIR, self.implfile(), self.nosefile()) self.assertTrue(filelist) known_files = ['%s/res/test_file' % TESTDIR] files = filelist._extra_files() log.debug(sorted(files)) log.debug(sorted(known_files)) self.assertEqual(sorted(files), sorted(known_files))
def fetch_metadata(self): """ @brief collect metadata from the user """ self.metadata = Metadata() self.metadata.get_from_console()
class PackageDriver(): """ Main class for running the package driver process. """ ### # Configuration ### def log_file(self): return "qualification.log" def log_path(self): return "%s/%s" % (self.metadata.idk_dir(), self.log_file()) def archive_path(self): return "%s/%s_%02d_driver.zip" % (os.environ['HOME'], self.metadata.name.lower(), self.metadata.version) ### # Public Methods ### def __init__(self): """ @brief ctor """ self.metadata = Metadata() self._zipfile = None self._manifest = None self._compression = None self.generator = DriverGenerator(self.metadata) # Set compression level self.zipfile_compression() def run_qualification_tests(self): """ @brief Run all qualification tests for the driver and store the results for packaging """ log.info("-- Running qualification tests") test = NoseTest(self.metadata, log_file=self.log_path()) test.report_header() result = test.run_qualification() if(test.run_qualification()): log.info(" ++ Qualification tests passed") return True else: log.error("Qualification tests have fail! No package created.") return False def package_driver(self): """ @brief Store driver files in a zip package """ log.info("-- Building driver package") 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 """ # Add python source files self._add_file(self.generator.driver_full_name(), 'src', 'driver source code') self._add_file(self.generator.driver_test_full_name(), 'src/test', 'driver test code') # 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())
def fetch_metadata(self): """ @brief collect metadata from the user """ self.metadata = Metadata()