Beispiel #1
0
    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')
Beispiel #2
0
    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'
                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 _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
        self._add_file("%s/%s" % (self.generator.resource_dir(), self.string_file()),
                       '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')
Beispiel #4
0
    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 clone_repo(self):
        """
        clone the ooici repository into a temp location and navigate to it
        """
        # make a temp dir to put the clone in
        if not os.path.exists(REPODIR):
            os.mkdir(REPODIR)
        os.chdir(REPODIR)
        # remove an old clone if one exists, start clean
        if os.path.exists(REPODIR + '/marine-integrations'):
            shutil.rmtree(REPODIR + '/marine-integrations')

        # clone the ooici repository into a temporary location
        os.system('git clone [email protected]:ooici/marine-integrations.git')
        log.debug('cloned repository')

        # if the directory doesn't exist, something went wrong with cloning
        if not os.path.exists(REPODIR + '/marine-integrations'):
            raise InvalidParameters('Error creating ooici repository clone')
        # navigate into the cloned repository
        os.chdir(REPODIR + '/marine-integrations')
        log.debug('in cloned repository')

        # 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')
Beispiel #6
0
    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")
Beispiel #7
0
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
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
        """
        pass

    def generate_code(self, force = False):
        """
        @brief generate the directory structure, code and tests for the new driver.
        """
        driver = mi.idk.dataset.driver_generator.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.generate_code(force = True)

    def run(self):
        """
        @brief Run it.
        """
        print( "*** Starting Driver Creation Process***" )

        self.fetch_metadata()
        self.generate_code()
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
        """
        pass

    def generate_code(self, force=False):
        """
        @brief generate the directory structure, code and tests for the new driver.
        """
        driver = mi.idk.dataset.driver_generator.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.generate_code(force=True)

    def run(self):
        """
        @brief Run it.
        """
        print("*** Starting Driver Creation Process***")

        self.fetch_metadata()
        self.generate_code()
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
Beispiel #11
0
    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 update_version(self):
     """
     Update the driver version for this package.  By default increment by one.
     After updating the metadata file, commit the change to git.
     """
     last_dot = self.metadata.version.rfind('.')
     last_version = int(self.metadata.version[last_dot+1:])
     suggest_version = self.metadata.version[:last_dot+1] + str(last_version + 1)
     new_version = prompt.text('Update Driver Version', suggest_version )
     if new_version != self.metadata.version:
         # set the new driver version in the metadata
         self.metadata.set_driver_version(new_version)
         # commit the changed file to git
         cmd = 'git commit ' + str(self.metadata.metadata_path()) + ' -m \'Updated metadata driver version\''
         os.system(cmd)
         # read metadata again to update the version in our metadata
         self.metadata = Metadata(self.metadata.driver_path, REPODIR + '/marine-integrations')
 def get_repackage_version(self):
     """
     Get the driver version the user wants to repackage
     """
     # suggest the current driver version as default
     repkg_version = prompt.text( 'Driver Version to re-package', self.metadata.version )
     # check to make sure this driver version exists
     tag_name = 'driver_' + self.metadata.driver_name + '_' + repkg_version.replace('.','_')
     cmd = 'git tag -l ' + tag_name 
     # find out if this tag name exists
     output = subprocess.check_output(cmd, shell=True)
     if len(output) > 0:
         # this tag exists, check it out
         os.system('git checkout tags/' + tag_name)
         # re-read the metadata since version may have changed in metadata.yml file
         self.metadata = Metadata(self.metadata.driver_path, REPODIR + '/marine-integrations')
     else:
         log.error('No driver version %s found', tag_name)
         raise InvalidParameters('No driver version %s found', tag_name)
    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()
     self.metadata.get_from_console()
class PackageDriver(mi.idk.package_driver.PackageDriver):

    def archive_file(self):
        return "%s-%s-driver.zip" % (self.metadata.driver_name,
                                     self.metadata.version)

    ###
    #   Public Methods
    ###
    def __init__(self, test_mode=False):
        """
        @brief ctor
        """
        self.test_mode = test_mode
        self._zipfile = None
        self._manifest = None
        self._compression = None

        # 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()

        if(test.run_qualification()):
            log.info(" ++ Qualification tests passed")
            return True
        else:
            log.error("Qualification tests have fail!  No package created.")
            return False

    def update_version(self):
        """
        Update the driver version for this package.  By default increment by one.
        After updating the metadata file, commit the change to git.
        """
        last_dot = self.metadata.version.rfind('.')
        last_version = int(self.metadata.version[last_dot+1:])
        suggest_version = self.metadata.version[:last_dot+1] + str(last_version + 1)
        if self.test_mode:
            new_version = suggest_version
        else:
            new_version = prompt.text('Update Driver Version', suggest_version )
        # make sure the entered version has the correct format
        self._verify_version(new_version)
        if new_version != self.metadata.version:
            # search for the tag for this version, find out if it already exists
            cmd = 'git tag -l ' + 'release_dsd_' + self.metadata.driver_name + '_' + new_version.replace('.', '_')
            # find out if this tag name exists
            output = subprocess.check_output(cmd, shell=True)
            if len(output) > 0:
                # this tag already exists and we are not repackaging
                raise InvalidParameters("Version %s already exists.  To repackage, run package driver with the --repackage option", new_version)

            # set the new driver version in the metadata
            self.metadata.set_driver_version(new_version)
            # commit the changed file to git
            cmd = 'git commit ' + str(self.metadata.metadata_path()) + ' -m \'Updated metadata driver version\''
            os.system(cmd)

        return new_version

    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')

        if self.test_mode:
            #sys.argv.append("--repackage")
            sys.argv.append("--no-push")
        log.debug("test mode: %s, argv: %s", self.test_mode, sys.argv)

        # 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 %s' % WRITE_REPO_URL
                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()

    ###
    #   Private Methods
    ###
    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
        self._add_file("%s/%s" % (self.generator.resource_dir(), self.string_file()),
                       '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 fetch_metadata(self):
     """
     @brief collect metadata from the user
     """
     self.metadata = Metadata()
     self.metadata.get_from_console()
 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)
Beispiel #19
0
class PackageDriver(mi.idk.package_driver.PackageDriver):
    def archive_file(self):
        return "%s-%s-driver.zip" % (self.metadata.driver_name,
                                     self.metadata.version)

    ###
    #   Public Methods
    ###
    def __init__(self):
        """
        @brief ctor
        """
        self._zipfile = None
        self._manifest = None
        self._compression = None

        # 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()

        if (test.run_qualification()):
            log.info(" ++ Qualification tests passed")
            return True
        else:
            log.error("Qualification tests have fail!  No package created.")
            return False

    def update_version(self):
        """
        Update the driver version for this package.  By default increment by one.
        After updating the metadata file, commit the change to git.
        """
        last_dot = self.metadata.version.rfind('.')
        last_version = int(self.metadata.version[last_dot + 1:])
        suggest_version = self.metadata.version[:last_dot +
                                                1] + str(last_version + 1)
        new_version = prompt.text('Update Driver Version', suggest_version)
        # make sure the entered version has the correct format
        self._verify_version(new_version)
        if new_version != self.metadata.version:
            # search for the tag for this version, find out if it already exists
            cmd = 'git tag -l ' + 'release_dsd_' + self.metadata.driver_name + '_' + new_version.replace(
                '.', '_')
            # find out if this tag name exists
            output = subprocess.check_output(cmd, shell=True)
            if len(output) > 0:
                # this tag already exists and we are not repackaging
                raise InvalidParameters(
                    "Version %s already exists.  To repackage, run package driver with the --repackage option",
                    new_version)

            # set the new driver version in the metadata
            self.metadata.set_driver_version(new_version)
            # commit the changed file to git
            cmd = 'git commit ' + str(self.metadata.metadata_path(
            )) + ' -m \'Updated metadata driver version\''
            os.system(cmd)

        return new_version

    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()

    ###
    #   Private Methods
    ###
    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 _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)
                    self._add_file(resource_dir + "/" + file, 'resource',
                                   'test file')
        else:
            log.debug(" --- No resource directory found, skipping...")
 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)
class PackageDriver(mi.idk.package_driver.PackageDriver):

    def archive_file(self):
        return "%s-%s-driver.zip" % (self.metadata.driver_name,
                                     self.metadata.version)
    
    ###
    #   Public Methods
    ###
    def __init__(self):
        """
        @brief ctor
        """
        self._zipfile = None
        self._manifest = None
        self._compression = None

        # 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()

        if(test.run_qualification()):
            log.info(" ++ Qualification tests passed")
            return True
        else:
            log.error("Qualification tests have fail!  No package created.")
            return False
        
    def clone_repo(self):
        """
        clone the ooici repository into a temp location and navigate to it
        """
        # make a temp dir to put the clone in
        if not os.path.exists(REPODIR):
            os.mkdir(REPODIR)
        os.chdir(REPODIR)
        # remove an old clone if one exists, start clean
        if os.path.exists(REPODIR + '/marine-integrations'):
            shutil.rmtree(REPODIR + '/marine-integrations')

        # clone the ooici repository into a temporary location
        os.system('git clone [email protected]:ooici/marine-integrations.git')
        log.debug('cloned repository')

        # if the directory doesn't exist, something went wrong with cloning
        if not os.path.exists(REPODIR + '/marine-integrations'):
            raise InvalidParameters('Error creating ooici repository clone')
        # navigate into the cloned repository
        os.chdir(REPODIR + '/marine-integrations')
        log.debug('in cloned repository')

        # 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')

    def get_repackage_version(self):
        """
        Get the driver version the user wants to repackage
        """
        # suggest the current driver version as default
        repkg_version = prompt.text( 'Driver Version to re-package', self.metadata.version )
        # check to make sure this driver version exists
        tag_name = 'driver_' + self.metadata.driver_name + '_' + repkg_version.replace('.','_')
        cmd = 'git tag -l ' + tag_name 
        # find out if this tag name exists
        output = subprocess.check_output(cmd, shell=True)
        if len(output) > 0:
            # this tag exists, check it out
            os.system('git checkout tags/' + tag_name)
            # re-read the metadata since version may have changed in metadata.yml file
            self.metadata = Metadata(self.metadata.driver_path, REPODIR + '/marine-integrations')
        else:
            log.error('No driver version %s found', tag_name)
            raise InvalidParameters('No driver version %s found', tag_name)

    def make_branch(self):
        """
        Make a new branch for this release and tag it with the same name so we
        can get back to it
        """
        name = self.metadata.driver_name_versioned
        # create a new branch name and check it out
        cmd = 'git checkout -b ' + name
        output = subprocess.check_output(cmd, shell=True)
        log.debug('created new branch %s: %s', name, output)
        # tag the initial branch so that we can get back to it later
        cmd = 'git tag ' + name
        output = subprocess.check_output(cmd, shell=True)
        log.debug('created new tag %s: %s', name, output)

    def update_version(self):
        """
        Update the driver version for this package.  By default increment by one.
        After updating the metadata file, commit the change to git.
        """
        last_dot = self.metadata.version.rfind('.')
        last_version = int(self.metadata.version[last_dot+1:])
        suggest_version = self.metadata.version[:last_dot+1] + str(last_version + 1)
        new_version = prompt.text('Update Driver Version', suggest_version )
        if new_version != self.metadata.version:
            # set the new driver version in the metadata
            self.metadata.set_driver_version(new_version)
            # commit the changed file to git
            cmd = 'git commit ' + str(self.metadata.metadata_path()) + ' -m \'Updated metadata driver version\''
            os.system(cmd)
            # read metadata again to update the version in our metadata
            self.metadata = Metadata(self.metadata.driver_path, REPODIR + '/marine-integrations')

    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()

        # for now comment out the test option until test are more stable,
        # just build the package driver
        if len(sys.argv) == 2 and (sys.argv[1] == "--repackage"):
            self.get_repackage_version()
            self.package_driver()
        else:
            self.update_version()
            self.make_branch()
            self.package_driver()

            if prompt.yes_no('Do you want to push the new release branch to ooici?'):
                cmd = 'git push'
                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()

    ###
    #   Private Methods
    ###
    def _store_package_files(self):
        """
        @brief Store all files in zip archive and add them to the manifest file
        """
        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
        self._add_file("%s/%s" % (self.generator.resource_dir(), self.string_file()),
                       '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 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()