Beispiel #1
0
    def test_project_name_with_environment_file(self):
        base_dir = tempfile.mkdtemp()
        try:
            name = 'namefromenvfile'
            with open(os.path.join(base_dir, '.env'), 'w') as f:
                f.write('COMPOSE_PROJECT_NAME={}'.format(name))
            project_name = get_project_name(base_dir)
            assert project_name == name

            # Environment has priority over .env file
            os.environ['COMPOSE_PROJECT_NAME'] = 'namefromenv'
            assert get_project_name(base_dir) == os.environ['COMPOSE_PROJECT_NAME']
        finally:
            shutil.rmtree(base_dir)
Beispiel #2
0
    def test_project_name_with_environment_file(self):
        base_dir = tempfile.mkdtemp()
        try:
            name = 'namefromenvfile'
            with open(os.path.join(base_dir, '.env'), 'w') as f:
                f.write('COMPOSE_PROJECT_NAME={}'.format(name))
            project_name = get_project_name(base_dir)
            assert project_name == name

            # Environment has priority over .env file
            os.environ['COMPOSE_PROJECT_NAME'] = 'namefromenv'
            assert get_project_name(base_dir) == os.environ['COMPOSE_PROJECT_NAME']
        finally:
            shutil.rmtree(base_dir)
Beispiel #3
0
    def __init__(self, kard):
        self.kard = kard
        self.env = kard.env
        self.path = Path(kard.path) / self.DOCKER_CONTEXT

        if self.kard.meta.get('project_name') is None:
            self.kard.meta['project_name'] = get_project_name(
                str(get_pkr_path()))

        self.tpl_context = None
        self.tpl_env = None
Beispiel #4
0
def init_project(orgId):

    print("[init_project]: Compose project init started...")
    namespace, api_data, repl = create_customer(orgId)

    environment = Environment.from_env_file(FOLDER_PATH)
    config_path = get_config_path_from_options(FOLDER_PATH, dict(),
                                               environment)
    project = get_project(FOLDER_PATH, config_path, namespace)
    project_name = get_project_name(FOLDER_PATH, namespace)
    print("[init_project]: Compose project init finished...")
    return (project, namespace, api_data, repl)
Beispiel #5
0
    def __init__(self, files):
        super(Compose, self).__init__()

        self.files = files
        # options.update({'--file': self.files})
        self.options = {'--file': self.files}
        # if net is not None:
        #     self.options['--net'] = net

        self.project_dir = os.curdir
        self.project_name = get_project_name(self.project_dir)
        log.verbose("Client compose {}: {}", self.project_name, files)
Beispiel #6
0
 def test_project_name_priority(self):
     base_dir = 'tests/fixtures/testdir'
     os.environ['COMPOSE_PROJECT_NAME'] = 'env_name'
     project_name = get_project_name(
         base_dir,
         project_name='project_name',
         config_project_name='config_project_name')
     self.assertEqual('projectname', project_name)
     project_name = get_project_name(
         base_dir,
         project_name=None,
         config_project_name='config_project_name')
     self.assertEqual('envname', project_name)
     del os.environ['COMPOSE_PROJECT_NAME']
     project_name = get_project_name(
         base_dir,
         project_name=None,
         config_project_name='config_project_name')
     self.assertEqual('configprojectname', project_name)
     project_name = get_project_name(base_dir,
                                     project_name=None,
                                     config_project_name=None)
     self.assertEqual('testdir', project_name)
Beispiel #7
0
    def get_meta(extras, kard):
        """Ensure that the required meta are present.

        Args:
          * extras(dict): extra values
          * kard: the current kard
        """
        metas = ['tag', 'project_name']

        default = kard.env.get('default_meta', {}).copy()
        default.setdefault('project_name', get_project_name(str(kard.path)))
        merge(extras, default)

        return ensure_definition_matches(definition=metas,
                                         defaults=default,
                                         data=kard.meta)
Beispiel #8
0
    def get_meta(extras, kard):
        """Ensure that the required meta are present.

        Args:
          * extras(dict): extra values
          * kard: the current kard
        """
        metas = ('tag', 'project_name')
        ret = {}
        defaults = {'project_name': get_project_name(str(kard.path))}
        for meta in metas:
            if meta in extras:
                ret[meta] = extras.pop(meta)
            elif meta not in kard.meta:
                if meta in defaults:
                    ret[meta] = defaults[meta]
                else:
                    ret[meta] = ask_input(meta)
        return ret
Beispiel #9
0
 def test_project_name_with_empty_environment_var(self):
     base_dir = 'tests/fixtures/simple-composefile'
     with mock.patch.dict(os.environ):
         os.environ['COMPOSE_PROJECT_NAME'] = ''
         project_name = get_project_name(base_dir)
     self.assertEquals('simplecomposefile', project_name)
Beispiel #10
0
 def test_project_name_from_environment_new_var(self):
     name = 'namefromenv'
     os.environ['COMPOSE_PROJECT_NAME'] = name
     project_name = get_project_name(None)
     self.assertEquals(project_name, name)
Beispiel #11
0
 def test_project_name_with_explicit_project_name(self):
     name = 'explicit-project-name'
     project_name = get_project_name(None, project_name=name)
     self.assertEquals('explicitprojectname', project_name)
Beispiel #12
0
 def test_project_name_with_explicit_uppercase_base_dir(self):
     base_dir = 'tests/fixtures/UpperCaseDir'
     project_name = get_project_name(base_dir)
     self.assertEquals('uppercasedir', project_name)
Beispiel #13
0
 def test_project_name_with_explicit_base_dir(self):
     base_dir = 'tests/fixtures/simple-composefile'
     project_name = get_project_name(base_dir)
     self.assertEquals('simplecomposefile', project_name)
Beispiel #14
0
 def test_default_project_name(self):
     test_dir = py._path.local.LocalPath('tests/fixtures/simple-composefile')
     with test_dir.as_cwd():
         project_name = get_project_name('.')
         self.assertEquals('simplecomposefile', project_name)
Beispiel #15
0
 def test_project_name_from_environment_new_var(self):
     name = 'namefromenv'
     os.environ['COMPOSE_PROJECT_NAME'] = name
     project_name = get_project_name(None)
     assert project_name == name
Beispiel #16
0
 def test_default_project_name(self):
     test_dir = py._path.local.LocalPath(
         'tests/fixtures/simple-composefile')
     with test_dir.as_cwd():
         project_name = get_project_name('.')
         assert 'simple-composefile' == project_name
Beispiel #17
0
 def test_project_name_with_explicit_uppercase_base_dir(self):
     base_dir = 'tests/fixtures/UpperCaseDir'
     project_name = get_project_name(base_dir)
     assert 'uppercasedir' == project_name
Beispiel #18
0
 def test_project_name_with_explicit_project_name(self):
     name = 'explicit-project-name'
     project_name = get_project_name(None, project_name=name)
     assert 'explicit-project-name' == project_name
Beispiel #19
0
 def test_project_name_from_environment_new_var(self):
     name = "namefromenv"
     with mock.patch.dict(os.environ):
         os.environ["COMPOSE_PROJECT_NAME"] = name
         project_name = get_project_name(None)
     self.assertEquals(project_name, name)
Beispiel #20
0
 def test_leading_dash_project_name(self):
             test_dir = py._path.local.LocalPath('tests/fixtures/_leading-dash')
             with test_dir.as_cwd():
                 project_name = get_project_name('.')
                 assert 'leading-dash' == project_name
Beispiel #21
0
 def test_project_name_with_explicit_base_dir(self):
     base_dir = 'tests/fixtures/simple-composefile'
     project_name = get_project_name(base_dir)
     assert 'simple-composefile' == project_name
Beispiel #22
0
 def test_project_name_with_explicit_uppercase_base_dir(self):
     base_dir = 'tests/fixtures/UpperCaseDir'
     project_name = get_project_name(base_dir)
     assert 'uppercasedir' == project_name
Beispiel #23
0
 def test_project_name_with_explicit_base_dir(self):
     base_dir = 'tests/fixtures/simple-composefile'
     project_name = get_project_name(base_dir)
     self.assertEquals('simplecomposefile', project_name)
Beispiel #24
0
 def test_project_name_from_environment_old_var(self):
     name = 'namefromenv'
     with mock.patch.dict(os.environ):
         os.environ['FIG_PROJECT_NAME'] = name
         project_name = get_project_name(None)
     self.assertEquals(project_name, name)
Beispiel #25
0
 def test_project_name_with_explicit_base_dir(self):
     base_dir = 'tests/fixtures/simple-composefile'
     project_name = get_project_name(base_dir)
     assert 'simple-composefile' == project_name
Beispiel #26
0
 def test_project_name_with_explicit_uppercase_base_dir(self):
     base_dir = 'tests/fixtures/UpperCaseDir'
     project_name = get_project_name(base_dir)
     self.assertEquals('uppercasedir', project_name)
Beispiel #27
0
 def test_project_name_with_explicit_project_name(self):
     name = 'explicit-project-name'
     project_name = get_project_name(None, project_name=name)
     assert 'explicit-project-name' == project_name
Beispiel #28
0
 def test_project_name_with_explicit_project_name(self):
     name = 'explicit-project-name'
     project_name = get_project_name(None, project_name=name)
     self.assertEquals('explicitprojectname', project_name)
Beispiel #29
0
 def test_project_name_with_empty_environment_var(self):
     base_dir = 'tests/fixtures/simple-composefile'
     with mock.patch.dict(os.environ):
         os.environ['COMPOSE_PROJECT_NAME'] = ''
         project_name = get_project_name(base_dir)
     assert 'simple-composefile' == project_name
Beispiel #30
0
 def test_project_name_from_environment_new_var(self):
     name = 'namefromenv'
     with mock.patch.dict(os.environ):
         os.environ['COMPOSE_PROJECT_NAME'] = name
         project_name = get_project_name(None)
     self.assertEquals(project_name, name)