def _store_package_files(self): """ @brief Store all files in zip archive and add them to the manifest file """ self.metadata = Metadata(self.metadata.driver_path, 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 if it exists, it is not required string_file_path = os.path.join(self.generator.resource_dir(), self.string_file()) if os.path.exists(string_file_path): self._add_file(string_file_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 _get_source_data_file(self, filename): """ Search for a sample data file, first check the driver resource directory then just use the filename as a path. If the file doesn't exists raise an exception @param filename name or path of the file to search for @return full path to the found data file @raise IDKException if the file isn't found """ resource_dir = Metadata().resource_dir() source_path = os.path.join(resource_dir, filename) log.debug("Search for resource file (%s) in %s", filename, resource_dir) if os.path.isfile(source_path): log.debug("Found %s in resource directory", filename) return source_path log.debug("Search for resource file (%s) in current directory", filename) if os.path.isfile(filename): log.debug("Found %s in the current directory", filename) return filename raise IDKException("Data file %s does not exist", filename)
def test_constructor(self): """ Test object creation """ default_metadata = Metadata() self.assertTrue(default_metadata) specific_metadata = Metadata(DRIVER_PATH, BASE_DIR) self.assertTrue(specific_metadata) self.assertTrue(os.path.isfile(specific_metadata.metadata_path()), msg="file doesn't exist: %s" % specific_metadata.metadata_path()) self.assertEqual(specific_metadata.driver_path, "test_driver/foo") self.assertEqual(specific_metadata.driver_name, "test_driver_foo") self.assertEqual(specific_metadata.author, "Bill French") self.assertEqual(specific_metadata.email, "*****@*****.**") self.assertEqual(specific_metadata.notes, "some note") self.assertEqual(specific_metadata.version, "0.2.2")
def get_metadata(opts): """ return a list of metadata objects that we would like to run test for. If buildall option is set then we search the working directory tree for drivers, otherwise we return the current IDK driver metadata @param opts: command line options dictionary. @return: list of all metadata data objects we would like to run tests for. """ result = [] if (opts.buildall): paths = get_driver_paths() for path in paths: result.append(Metadata(path)) pass else: result.append(Metadata()) return result
def get_metadata(opts): """ return a list of metadata objects that we would like to run test for. If buildall option is set then we search the working directory tree for drivers, otherwise we return the current IDK driver metadata @param opts: command line options dictionary. @return: list of all metadata data objects we would like to run tests for. """ result = [] if (opts.buildall): paths = get_driver_paths() for path in paths: # Some drivers can't be run in batch tests if path not in EXCLUDED_DRIVERS: log.debug("Adding driver path: %s", path) result.append(Metadata(path)) else: result.append(Metadata()) return result
def run(self): print "*** Starting Driver Packaging Process ***" # store the original directory since we will be navigating away from it original_dir = os.getcwd() # first create a temporary clone of ooici to work with self.clone_repo() # get which dataset agent is selected from the current metadata, use # this to get metadata from the cloned repo tmp_metadata = Metadata() # read metadata from the cloned repo self.metadata = Metadata(tmp_metadata.driver_path, REPODIR + '/marine-integrations') # for now leave out the test option until test are more stable, # just build the package driver if "--repackage" in sys.argv: self.get_repackage_version('dsd_' + self.metadata.driver_name) self.package_driver() else: new_version = self.update_version() self.make_branch('dsd_' + self.metadata.driver_name + '_' + new_version.replace('.', '_')) self.package_driver() if not "--no-push" in sys.argv: cmd = 'git push --tags' output = subprocess.check_output(cmd, shell=True) if len(output) > 0: log.debug('git push returned: %s', output) # go back to the original directory os.chdir(original_dir) print "Package Created: " + self.archive_path()
def test_package_driver_real(self): """ Test with real hypm ctd driver code """ # link current metadata dsa file to a real driver, the ctd current_dsa_path = Config().idk_config_dir() + "/current_dsa.yml" ctd_md_path = "%s/%s/hypm/ctd/metadata.yml" % (Config().base_dir(), MI_BASE_DIR) log.info("linking %s to %s", ctd_md_path, current_dsa_path) # exists doesn't catch when this link is broken but still there, # need to figure out how to find and delete if exists(current_dsa_path): os.remove(current_dsa_path) log.error(current_dsa_path) os.symlink(ctd_md_path, current_dsa_path) # create the metadata so we can use it for opening the egg metadata = Metadata() # create the egg with the package driver package_driver = PackageDriver() package_driver.run() startup_config = { 'harvester': { 'directory': '/tmp/dsatest', 'pattern': '*.txt', 'frequency': 1, }, 'parser': {} } # load the driver cotr = self.load_egg(metadata) # need to load with the right number of arguments egg_driver = cotr(startup_config, None, None, None, None) log.info("driver loaded")
def fetch_metadata(self): """ @brief collect metadata from the user """ self.metadata = Metadata()
ofile = open(self.parser_path(), 'w') code = template.substitute(self._parser_template_data()) ofile.write(code) ofile.close() def generate_parser_test_code(self): """ @brief Generate stub parser test code """ if (os.path.exists(self.parser_test_path()) and not self.force): msg = "Warning: driver exists (" + self.parser_test_path( ) + ") not overwriting" sys.stderr.write(msg) log.warn(msg) else: log.info("Generate parser code from template %s to file %s" % (self.parser_test_template(), self.parser_test_path())) template = self._get_template(self.parser_test_template()) ofile = open(self.parser_test_path(), 'w') code = template.substitute(self._parser_test_template_data()) ofile.write(code) ofile.close() if __name__ == '__main__': metadata = Metadata() driver = DriverGenerator(metadata) driver.generate()
def overwrite(self): """ @brief Overwrite the current files with what is stored in the current metadata file. """ self.metadata = Metadata() self.generate_code(force=True)
def fetch_metadata(self): """ @brief collect metadata from the user """ self.metadata = Metadata() self.metadata.get_from_console()