<s> from pprint import pformat <EOL> import time <EOL> from dulwich . repo import Repo <EOL> from dulwich . index import build_index_from_tree <EOL> from logbook import Logger <EOL> from tempdir import TempDir <EOL> from . import new_local_stack , issues , opts , info , commit <EOL> from . exc import InvocationError , PluginError <EOL> from . git import MalleableCommit , ResolvedRef , get_local_timezone <EOL> from . report import IssueCollector <EOL> from . util import run_user_shell , confirm_prompt <EOL> log = Logger ( '<STR_LIT>' ) <EOL> class Unleash ( object ) : <EOL> def _create_child_commit ( self , parent_ref ) : <EOL> parent = ResolvedRef ( self . repo , parent_ref ) <EOL> if not parent . is_definite : <EOL> raise InvocationError ( '<STR_LIT>' . format ( <EOL> parent . ref , parent . full_name <EOL> ) ) <EOL> if not parent . found : <EOL> raise InvocationError ( '<STR_LIT>' . format ( parent . ref ) ) <EOL> commit = MalleableCommit . from_existing ( <EOL> self . repo , parent . id <EOL> ) <EOL> if opts [ '<STR_LIT>' ] is None : <EOL> commit . author = '<STR_LIT>' . format ( <EOL> self . gitconfig . get ( '<STR_LIT:user>' , '<STR_LIT:name>' ) , <EOL> self . gitconfig . get ( '<STR_LIT:user>' , '<STR_LIT:email>' ) , <EOL> ) <EOL> commit . commiter = commit . author <EOL> else : <EOL> commit . author = opts [ '<STR_LIT>' ] <EOL> commit . committer = opts [ '<STR_LIT>' ] <EOL> now = int ( time . time ( ) ) <EOL> ltz = get_local_timezone ( now ) <EOL> commit . author_time = now <EOL> commit . author_timezone = ltz <EOL> commit . commit_time = now <EOL> commit . commit_timezone = ltz <EOL> commit . parent_ids = [ parent . id ] <EOL> return commit <EOL> def __init__ ( self , plugins = [ ] ) : <EOL> self . plugins = plugins <EOL> def _init_repo ( self ) : <EOL> self . repo = Repo ( opts [ '<STR_LIT:root>' ] ) <EOL> self . gitconfig = self . repo . get_config_stack ( ) <EOL> def _perform_step ( self , signal_name ) : <EOL> log . debug ( '<STR_LIT>' . format ( signal_name ) ) <EOL> begin = time . time ( ) <EOL> with new_local_stack ( ) as nc : <EOL> nc [ '<STR_LIT>' ] = issues . channel ( signal_name ) <EOL> self . plugins . notify ( signal_name ) <EOL> duration = time . time ( ) - begin <EOL> log . debug ( '<STR_LIT>' . format ( signal_name , duration ) ) <EOL> def create_release ( self , ref ) : <EOL> with new_local_stack ( ) as nc : <EOL> base_ref = ResolvedRef ( self . repo , ref ) <EOL> log . debug ( <EOL> '<STR_LIT>' . format ( base_ref . full_name , base_ref . id ) <EOL> ) <EOL> orig_tree = base_ref . get_object ( ) . tree <EOL> nc [ '<STR_LIT>' ] = self . _create_child_commit ( ref ) <EOL> nc [ '<STR_LIT>' ] = IssueCollector ( log = log ) <EOL> nc [ '<STR_LIT:info>' ] = { '<STR_LIT>' : base_ref } <EOL> nc [ '<STR_LIT>' ] = log <EOL> try : <EOL> self . _perform_step ( '<STR_LIT>' ) <EOL> log . debug ( '<STR_LIT>' . format ( pformat ( info ) ) ) <EOL> self . _perform_step ( '<STR_LIT>' ) <EOL> self . _perform_step ( '<STR_LIT>' ) <EOL> if opts [ '<STR_LIT>' ] : <EOL> log . info ( unicode ( commit ) ) <EOL> with TempDir ( ) as inspect_dir : <EOL> commit . export_to ( inspect_dir ) <EOL> log . info ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> ) <EOL> status = run_user_shell ( cwd = inspect_dir ) <EOL> if status != <NUM_LIT:2> : <EOL> raise InvocationError ( <EOL> '<STR_LIT>' . <EOL> format ( status ) ) <EOL> release_commit = nc [ '<STR_LIT>' ] <EOL> nc [ '<STR_LIT>' ] = self . _create_child_commit ( ref ) <EOL> nc [ '<STR_LIT>' ] = IssueCollector ( log = log ) <EOL> self . _perform_step ( '<STR_LIT>' ) <EOL> if opts [ '<STR_LIT>' ] : <EOL> log . info ( '<STR_LIT>' ) <EOL> return <EOL> confirm_prompt ( <EOL> '<STR_LIT>' <EOL> . format ( info [ '<STR_LIT>' ] , info [ '<STR_LIT>' ] ) <EOL> ) <EOL> release_tag = '<STR_LIT>' . format ( info [ '<STR_LIT>' ] ) <EOL> if release_tag in self . repo . refs : <EOL> confirm_prompt ( <EOL> '<STR_LIT>' <EOL> . format ( release_tag ) , <EOL> ) <EOL> release_hash = release_commit . save ( ) <EOL> log . info ( '<STR_LIT>' . format ( release_tag , release_hash ) ) <EOL> self . repo . refs [ release_tag ] = release_hash <EOL> dev_hash = nc [ '<STR_LIT>' ] . save ( ) <EOL> assert base_ref . is_definite and base_ref . found <EOL> if not base_ref . is_ref or not base_ref . full_name . startswith ( '<STR_LIT>' ) : <EOL> log . warning ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> log . info ( '<STR_LIT>' . format ( dev_hash ) ) <EOL> else : <EOL> self . repo . refs [ base_ref . full_name ] = dev_hash <EOL> log . info ( '<STR_LIT>' . format ( <EOL> base_ref . full_name , dev_hash <EOL> ) ) <EOL> self . _update_working_copy ( base_ref , orig_tree ) <EOL> except PluginError : <EOL> log . debug ( '<STR_LIT>' ) <EOL> return <EOL> def _update_working_copy ( self , base_ref , orig_tree ) : <EOL> head_ref = ResolvedRef ( self . repo , '<STR_LIT>' ) <EOL> if not head_ref . is_definite or not head_ref . is_symbolic or not head_ref . target == base_ref . full_name : <EOL> log . info ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> return <EOL> if not self . repo . has_index ( ) : <EOL> log . info ( '<STR_LIT>' ) <EOL> return <EOL> index = self . repo . open_index ( ) <EOL> changes = list ( index . changes_from_tree ( <EOL> self . repo . object_store , <EOL> orig_tree , <EOL> ) ) <EOL> if changes : <EOL> log . warning ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' . format ( base_ref . id ) ) <EOL> return <EOL> confirm_prompt ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> ) <EOL> log . info ( '<STR_LIT>' ) <EOL> build_index_from_tree ( <EOL> self . repo . path , <EOL> self . repo . index_path ( ) , <EOL> self . repo . object_store , <EOL> base_ref . get_object ( ) . tree , <EOL> ) <EOL> def publish ( self , ref ) : <EOL> if ref is None : <EOL> tags = sorted ( <EOL> ( t for t in self . repo . refs . as_dict ( ) . iteritems ( ) if <EOL> t [ <NUM_LIT:0> ] . startswith ( '<STR_LIT>' ) ) , <EOL> key = lambda ( _ , sha ) : self . repo [ sha ] . commit_time , <EOL> reverse = True , <EOL> ) <EOL> if not tags : <EOL> log . error ( '<STR_LIT>' ) <EOL> return <EOL> ref = tags [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] <EOL> pref = ResolvedRef ( self . repo , ref ) <EOL> with new_local_stack ( ) as nc : <EOL> nc [ '<STR_LIT>' ] = MalleableCommit . from_existing ( self . repo , pref . id ) <EOL> log . debug ( '<STR_LIT>' . format ( commit ) ) <EOL> nc [ '<STR_LIT>' ] = IssueCollector ( log = log ) <EOL> nc [ '<STR_LIT:info>' ] = { '<STR_LIT>' : pref } <EOL> nc [ '<STR_LIT>' ] = log <EOL> try : <EOL> self . _perform_step ( '<STR_LIT>' ) <EOL> log . debug ( '<STR_LIT>' . format ( pformat ( info ) ) ) <EOL> self . _perform_step ( '<STR_LIT>' ) <EOL> except PluginError : <EOL> log . debug ( '<STR_LIT>' ) <EOL> return </s>
