def update_hostery_file(commits, sync=True): data = {} def write_txn(branch): if sync: git.pull(branch) hostery_file = open(HOSTERY_FILE, 'r') all_data = json.loads(hostery_file.read()) all_data.update(data) hostery_file.close() hostery_file = open(HOSTERY_FILE, 'w') hostery_file.write(json.dumps(all_data, indent=2)) hostery_file.close() git.add(HOSTERY_FILE) # command('git status', verbose=True) git.commit('hostery mark') if sync: git.push(branch) return all_data for commit in commits: data[commit] = get_commit_data(commit) # get info from each commit, add it to data return git.safe_checkout(HOSTERY_BRANCH, write_txn)
def init(args): if not git.is_controlled(): print_color('fatal: Not a git repository', colors.FAIL) quit() if os.path.isfile(HOSTERY_CONFIG): print_color('fatal: Hostery already configured. Edit or delete %s'% HOSTERY_CONFIG, colors.FAIL) quit() # instantiate hostery config hostery_config = open(HOSTERY_CONFIG, 'w') data = Connection.ByType[args.type].GetConfig() hostery_config.write(json.dumps(data, indent=2)) hostery_config.close() git.ignore(HOSTERY_CONFIG) # make empty hostery file on empty hostery branch def txn(branch): # git ignore everything except hostery file and gitignore. command('git rm --cached . -r', verbose=True) git_ignore = open('.gitignore', 'w') git_ignore.write('*\n!.gitignore\n!%s'%HOSTERY_FILE) git_ignore.close() git.add('.gitignore') # make hostery file hostery_file = open(HOSTERY_FILE, 'w') hostery_file.write(json.dumps({})) hostery_file.close() # add, commit, push. git.add(HOSTERY_FILE) command('git status', multiline=True, verbose=True) git.commit('hostery init') git.push(branch) git.safe_checkout(HOSTERY_BRANCH, txn, empty_branch=True) print 'Hostery configured! Use "hostery mark" to upload a commit.'
def mark(args): if not os.path.isfile(HOSTERY_CONFIG): print_color('fatal: Not a configured for hostery. Use "hostery init".', colors.FAIL) quit() #read hostery file hostery_config = open(HOSTERY_CONFIG, 'rb') config = json.loads(hostery_config.read()) hostery_config.close() # check if has single revision commit_number = git.commit_number() if not commit_number: quit() # do git sync if args.skip_git: print_color('Skipping git sync.', colors.WARNING) else: git_sync() commits_to_copy = [i[:7] for i in (args.commits or [commit_number])] # get/update commit data print_color('Updating hostery data ...', colors.HEADER) # todo commit_data = update_hostery_file(commits_to_copy, sync=not args.skip_git) #read hostery config, instantiate connection hostery_config = open(HOSTERY_CONFIG, 'rb') config = json.loads(hostery_config.read()) hostery_config.close() # start connection connection = Connection.FromConfig(config) connection.connect() # update index.html temp_index_file = update_index_file(commit_data) if not connection.supports_partial_upload(): # see what's not in the staging dir that *is* in the hostery file # add those to the list. for (_, dirs, _) in os.walk(connection.get_staging_directory()): commits_to_copy += filter(lambda c: c not in dirs, commit_data.keys()) commits_to_copy = list(set(commits_to_copy)) break def copy_commit(commit): upload_list = get_upload_list(commit, commit_data, not args.skip_symlinks) print_color('Staging files for %s ...'%commit, colors.HEADER) print_upload_list(upload_list, config['root']) connection.stage(*upload_list) print "WTF" # add latest symlink to upload list at root latest = UploadItem(commits_to_copy[-1], rename='latest') latest.set_symlink(commits_to_copy[-1], path=commits_to_copy[-1]) connection.stage(latest) # stage commits print_color('Staging files for %s ...'%', '.join(commits_to_copy), colors.HEADER) for commit in commits_to_copy: git.safe_checkout(commit, copy_commit) # add index.html to upload list at root connection.stage(UploadItem(temp_index_file.name, rename='index.html')) # upload files if not args.skip_upload: print_color('Uploading files ...', colors.HEADER) connection.upload() # end connection connection.disconnect() # clean up temp_index_file.close() print_color('Done.', colors.HEADER)