Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_show():
tmp_dir, git_dir = create_git_repo()
from bloom.git import show
assert show('master', 'something.txt') == None
with open(os.path.join(git_dir, 'something.txt'), 'w+') as f:
f.write('v1\n')
assert show('master', 'something.txt') == None
check_call('git add something.txt', shell=True, cwd=git_dir,
stdout=PIPE)
check_call('git commit -am "added something.txt"', shell=True, cwd=git_dir,
stdout=PIPE)
assert show('master', 'something.txt', git_dir) == 'v1\n', \
str(show('master', 'something.txt', git_dir)) + ' == v1'
os.makedirs(os.path.join(git_dir, 'adir'))
copy(os.path.join(git_dir, 'something.txt'), os.path.join(git_dir, 'adir'))
with open(os.path.join(git_dir, 'adir', 'something.txt'), 'a') as f:
f.write('v2\n')
check_call('git add adir', shell=True, cwd=git_dir,
stdout=PIPE)
check_call('git commit -am "made a subfolder"', shell=True, cwd=git_dir,
if len(index_yaml['distributions'][args.source]['distribution']) != 1 or \
len(index_yaml['distributions'][args.dest]['distribution']) != 1:
raise RuntimeError('Both source and destination distributions must have a single distribution file.')
# There is a possibility that the source_ref has a different distribution file
# layout. Check that they match.
source_ref_index_yaml = yaml.safe_load(show(args.source_ref, 'index-v4.yaml'))
if source_ref_index_yaml['distributions'][args.source]['distribution'] != \
index_yaml['distributions'][args.source]['distribution']:
raise RuntimeError('The distribution file layout has changed between the source ref and now.')
source_distribution_filename = index_yaml['distributions'][args.source]['distribution'][0]
dest_distribution_filename = index_yaml['distributions'][args.dest]['distribution'][0]
# Fetch the source distribution file from the exact point in the repository history requested.
source_distfile_data = yaml.safe_load(show(args.source_ref, source_distribution_filename))
source_distribution = DistributionFile(args.source, source_distfile_data)
# Prepare the destination distribution for new bloom releases from the source distribution.
dest_distribution = get_distribution_file(index, args.dest)
new_repositories = []
repositories_to_retry = []
for repo_name, repo_data in sorted(source_distribution.repositories.items()):
if repo_name not in dest_distribution.repositories:
dest_repo_data = copy.deepcopy(repo_data)
if dest_repo_data.release_repository:
new_repositories.append(repo_name)
release_tag = dest_repo_data.release_repository.tags['release']
release_tag = release_tag.replace(args.source,args.dest)
dest_repo_data.release_repository.tags['release'] = release_tag
dest_distribution.repositories[repo_name] = dest_repo_data
elif dest_distribution.repositories[repo_name].release_repository is not None and \
error("In patches path '{0}' is a file, ".format(rel_path) +
"but it exists in the upstream branch as a directory.",
exit=True)
# If the file already exists, warn
if os.path.isfile(rel_path):
warning(" File '{0}' already exists, overwriting..."
.format(rel_path))
execute_command('git rm {0}'.format(rel_path), shell=True)
# If package.xml tempalte in version, else grab data
if path in ['stack.xml']:
warning(" Skipping '{0}' templating, fuerte not supported"
.format(rel_path))
if path in ['package.xml']:
info(" Templating '{0}' into upstream branch..."
.format(rel_path))
file_data = show(BLOOM_CONFIG_BRANCH, os.path.join(root_path, rel_path))
file_data = file_data.replace(':{version}', version)
else:
info(" Overlaying '{0}' into upstream branch..."
.format(rel_path))
file_data = show(BLOOM_CONFIG_BRANCH, os.path.join(root_path, rel_path))
# Write file
with open(rel_path, 'wb') as f:
# Python 2 will treat this as an ascii string but
# Python 3 will not re-decode a utf-8 string.
if sys.version_info.major == 2:
file_data = file_data.decode('utf-8').encode('utf-8')
else:
file_data = file_data.encode('utf-8')
f.write(file_data)
# Add it with git
execute_command('git add {0}'.format(rel_path), shell=True)
def get_releaser_history(self):
# Assumes that this is called in the target branch
patches_branch = 'patches/' + get_current_branch()
raw = show(patches_branch, 'releaser_history.json')
return None if raw is None else json.loads(raw)
warning(" File '{0}' already exists, overwriting..."
.format(rel_path))
execute_command('git rm {0}'.format(rel_path), shell=True)
# If package.xml tempalte in version, else grab data
if path in ['stack.xml']:
warning(" Skipping '{0}' templating, fuerte not supported"
.format(rel_path))
if path in ['package.xml']:
info(" Templating '{0}' into upstream branch..."
.format(rel_path))
file_data = show(BLOOM_CONFIG_BRANCH, os.path.join(root_path, rel_path))
file_data = file_data.replace(':{version}', version)
else:
info(" Overlaying '{0}' into upstream branch..."
.format(rel_path))
file_data = show(BLOOM_CONFIG_BRANCH, os.path.join(root_path, rel_path))
# Write file
with open(rel_path, 'wb') as f:
# Python 2 will treat this as an ascii string but
# Python 3 will not re-decode a utf-8 string.
if sys.version_info.major == 2:
file_data = file_data.decode('utf-8').encode('utf-8')
else:
file_data = file_data.encode('utf-8')
f.write(file_data)
# Add it with git
execute_command('git add {0}'.format(rel_path), shell=True)
def read_tracks_file():
return yaml.safe_load(show('master', 'tracks.yaml'))
def load_original_config(self, patches_branch):
config_store = show(patches_branch, 'debian.store')
if config_store is None:
return config_store
return json.loads(config_store)
def upconvert_bloom_to_config_branch():
global _has_checked_bloom_branch
if _has_checked_bloom_branch:
return
# Assert that this repository does not have multiple remotes
check_for_multiple_remotes()
if get_root() is None:
# Not a git repository
return
track_branches(['bloom', BLOOM_CONFIG_BRANCH])
if show('bloom', PLACEHOLDER_FILE) is not None:
return
if show('bloom', 'bloom.conf') is not None:
# Wait for the bloom.conf upconvert...
return
if not branch_exists('bloom'):
return
_has_checked_bloom_branch = True
info("Moving configurations from deprecated 'bloom' branch "
"to the '{0}' branch.".format(BLOOM_CONFIG_BRANCH))
tmp_dir = mkdtemp()
git_root = get_root()
try:
# Copy the new upstream source into the temporary directory
with inbranch('bloom'):
ignores = ('.git', '.gitignore', '.svn', '.hgignore', '.hg', 'CVS')
configs = os.path.join(tmp_dir, 'configs')
my_copytree(git_root, configs, ignores)
if [x for x in os.listdir(os.getcwd()) if x not in ignores]: