Exemplo n.º 1
0
 def repo_remote_add(self, repo_type, mlgit_remote, global_conf=False):
     try:
         remote_add(repo_type, mlgit_remote, global_conf)
         self.__config = config_load()
         metadata_path = get_metadata_path(self.__config)
         m = Metadata('', metadata_path, self.__config, self.__repo_type)
         m.remote_set_url(mlgit_remote)
     except Exception as e:
         log.error(e, class_name=REPOSITORY_CLASS_NAME)
         return
Exemplo n.º 2
0
 def test_remote_del(self):
     remote_default = 'git_local_server.git'
     init_mlgit()
     config = yaml_load('.ml-git/config.yaml')
     self.assertEqual(config[DATASETS]['git'], '')
     remote_add(DATASETS, remote_default)
     config = yaml_load('.ml-git/config.yaml')
     self.assertEqual(config[DATASETS]['git'], remote_default)
     remote_del(DATASETS)
     config_ = yaml_load('.ml-git/config.yaml')
     self.assertEqual(config_[DATASETS]['git'], '')
Exemplo n.º 3
0
 def test_remote_del(self):
     remote_default = 'git_local_server.git'
     dataset = 'dataset'
     init_mlgit()
     config = yaml_load('.ml-git/config.yaml')
     self.assertEqual(config['dataset']['git'], '')
     remote_add(dataset, remote_default)
     config = yaml_load('.ml-git/config.yaml')
     self.assertEqual(config['dataset']['git'], remote_default)
     remote_del(dataset)
     config_ = yaml_load('.ml-git/config.yaml')
     self.assertEqual(config_['dataset']['git'], '')
Exemplo n.º 4
0
def _configure_metadata_remote(repo_type):
    config = mlgit_config_load()
    try:
        if not config[repo_type]['git']:
            raise Exception('Need configure a remote repository.')
    except Exception:
        git_repo = input(
            USER_INPUT_MESSAGE.format(
                'git repository for ml-git {} metadata'.format(
                    repo_type))).lower()
        from ml_git.admin import remote_add
        remote_add(repo_type, git_repo)
Exemplo n.º 5
0
 def create(self, kwargs):
     artifact_name = kwargs['artifact_name']
     categories = list(kwargs['category'])
     version = int(kwargs['version_number'])
     imported_dir = kwargs['import']
     store_type = kwargs['store_type']
     bucket_name = kwargs['bucket_name']
     start_wizard = kwargs['wizard_config']
     import_url = kwargs['import_url']
     unzip_file = kwargs['unzip']
     credentials_path = kwargs['credentials_path']
     repo_type = self.__repo_type
     try:
         create_workspace_tree_structure(repo_type, artifact_name,
                                         categories, store_type,
                                         bucket_name, version, imported_dir,
                                         kwargs['mutability'])
         if start_wizard:
             has_new_store, store_type, bucket, profile, endpoint_url, git_repo = start_wizard_questions(
                 repo_type)
             if has_new_store:
                 store_add(store_type, bucket, profile, endpoint_url)
             update_store_spec(repo_type, artifact_name, store_type, bucket)
             remote_add(repo_type, git_repo)
         if import_url:
             self.create_config_store('gdrive', credentials_path)
             local = LocalRepository(
                 self.__config, get_objects_path(self.__config, repo_type))
             destine_path = os.path.join(repo_type, artifact_name, 'data')
             local.import_file_from_url(destine_path, import_url,
                                        StoreType.GDRIVE.value)
         if unzip_file:
             log.info('Unzipping files', CLASS_NAME=REPOSITORY_CLASS_NAME)
             data_path = os.path.join(get_root_path(), repo_type,
                                      artifact_name, 'data')
             unzip_files_in_directory(data_path)
         log.info("Project Created.", CLASS_NAME=REPOSITORY_CLASS_NAME)
     except Exception as e:
         if not isinstance(e, PermissionError):
             clear(os.path.join(repo_type, artifact_name))
         if isinstance(e, KeyboardInterrupt):
             log.info("Create command aborted!",
                      class_name=REPOSITORY_CLASS_NAME)
         else:
             log.error(e, CLASS_NAME=REPOSITORY_CLASS_NAME)
Exemplo n.º 6
0
    def test_remote_add_global_config(self):
        remote_default = 'git_local_server.git'
        new_remote = 'git_local_server2.git'
        dataset = 'dataset'
        init_mlgit()
        with mock.patch('pathlib.Path.home', return_value=self.tmp_dir):
            remote_add(dataset, new_remote, global_conf=True)

        self.assertTrue(os.path.exists('.mlgitconfig'))
        config = yaml_load('.ml-git/config.yaml')
        config_global = yaml_load('.mlgitconfig')
        self.assertEqual(config_global['dataset']['git'], new_remote)
        self.assertNotEqual(config['dataset']['git'], remote_default)

        with mock.patch('pathlib.Path.home', return_value=self.tmp_dir):
            remote_add(dataset, '', global_conf=True)

        config_ = yaml_load('.mlgitconfig')
        self.assertEqual(config_['dataset']['git'], '')

        with mock.patch('pathlib.Path.home', return_value=self.tmp_dir):
            remote_add(dataset, new_remote, global_conf=True)

        config__ = yaml_load('.mlgitconfig')
        self.assertEqual(config__['dataset']['git'], new_remote)
Exemplo n.º 7
0
 def test_remote_add(self):
     remote_default = 'git_local_server.git'
     new_remote = 'git_local_server2.git'
     init_mlgit()
     remote_add(DATASETS, new_remote)
     self.assertTrue(os.path.isdir('.ml-git'))
     config = yaml_load('.ml-git/config.yaml')
     self.assertEqual(config[DATASETS]['git'], new_remote)
     self.assertNotEqual(remote_default, new_remote)
     remote_add(DATASETS, '')
     config_ = yaml_load('.ml-git/config.yaml')
     self.assertEqual(config_[DATASETS]['git'], '')
     remote_add(DATASETS, new_remote)
     self.assertTrue(os.path.isdir('.ml-git'))
     config__ = yaml_load('.ml-git/config.yaml')
     self.assertEqual(config__[DATASETS]['git'], new_remote)