Skip to content

Commit

Permalink
improve: 本地中转目录生成方式抽离到公共部分 TencentBlueKing#275
Browse files Browse the repository at this point in the history
  • Loading branch information
pagezz-canway committed May 10, 2019
1 parent 4a612ea commit 0601a5d
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions gcloud/external_plugins/models/original_source.py
Expand Up @@ -95,6 +95,13 @@ def reader(self):
def details(self):
raise NotImplementedError()

def prepare_cache_path(self):
cache_path = os.path.join(CACHE_TEMP_PATH, self.name)
if os.path.exists(cache_path):
shutil.rmtree(cache_path)
os.makedirs(cache_path)
return cache_path

def update_base_source(self, source_type, packages, **kwargs):
if source_type != self.type:
raise exceptions.OriginalSourceTypeError('Original source type cannot be updated')
Expand All @@ -120,10 +127,7 @@ def details(self):
}

def reader(self):
cache_path = os.path.join(CACHE_TEMP_PATH, self.name)
if os.path.exists(cache_path):
shutil.rmtree(cache_path)
os.makedirs(cache_path)
cache_path = super(GitRepoOriginalSource, self).prepare_cache_path()
Repo.clone_from(self.repo_address, cache_path, branch=self.branch)


Expand Down Expand Up @@ -172,9 +176,7 @@ def details(self):
}

def reader(self):
cache_path = os.path.join(CACHE_TEMP_PATH, self.name)
if not os.path.exists(cache_path):
os.makedirs(cache_path)
cache_path = super(S3OriginalSource, self).prepare_cache_path()
client = boto3.client('s3',
endpoint_url=self.service_address,
aws_access_key_id=self.access_key,
Expand Down

0 comments on commit 0601a5d

Please sign in to comment.