<s> import json <EOL> import os <EOL> import shutil <EOL> import subprocess <EOL> from six . moves . urllib import parse <EOL> from . import utils <EOL> from . exceptions import GitCommandError <EOL> def set_repo_version ( repo , version ) : <EOL> with open ( repo . get_metadata_path ( '<STR_LIT:version>' ) , '<STR_LIT:w>' ) as out : <EOL> out . write ( str ( version ) ) <EOL> repo . run_git_command ( <EOL> '<STR_LIT>' , '<STR_LIT>' , repo . get_metadata_path ( '<STR_LIT:version>' ) , failure_ok = True , <EOL> ) <EOL> repo . run_git_command ( <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' % version , failure_ok = True <EOL> ) <EOL> def migration_0002 ( repo , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> os . mkdir ( <EOL> repo . get_metadata_path ( '<STR_LIT>' ) <EOL> ) <EOL> subprocess . check_call ( <EOL> ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT:.>' <EOL> ) , <EOL> cwd = repo . get_metadata_path ( '<STR_LIT>' ) , <EOL> stdout = subprocess . PIPE , <EOL> ) <EOL> try : <EOL> repo . run_git_command ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , shadow = True ) <EOL> except GitCommandError : <EOL> repo . run_git_command ( '<STR_LIT>' , '<STR_LIT>' , shadow = True ) <EOL> repo . run_git_command ( <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , shadow = True <EOL> ) <EOL> repo . run_git_command ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , shadow = True ) <EOL> set_repo_version ( repo , <NUM_LIT:2> ) <EOL> def migration_0003 ( repo , init = False , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> os . mkdir ( repo . get_shadow_path ( '<STR_LIT>' ) ) <EOL> except OSError : <EOL> pass <EOL> storable = { <EOL> '<STR_LIT>' : repo . issue . _options , <EOL> '<STR_LIT>' : repo . issue . raw <EOL> } <EOL> with open ( repo . get_shadow_path ( '<STR_LIT>' ) , '<STR_LIT:w>' ) as out : <EOL> out . write ( json . dumps ( storable ) ) <EOL> issue_pickle_path = repo . get_shadow_path ( '<STR_LIT>' ) <EOL> repo . run_git_command ( '<STR_LIT>' , '<STR_LIT>' , issue_pickle_path , shadow = True ) <EOL> repo . run_git_command ( <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , shadow = True <EOL> ) <EOL> repo . run_git_command ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , shadow = True ) <EOL> repo . run_git_command ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> set_repo_version ( repo , <NUM_LIT:3> ) <EOL> def migration_0004 ( repo , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> local_remote_files_path = repo . get_metadata_path ( '<STR_LIT>' ) <EOL> jira_remote_files_path = repo . get_shadow_path ( '<STR_LIT>' ) <EOL> try : <EOL> os . rename ( local_remote_files_path , jira_remote_files_path ) <EOL> except ( IOError , OSError ) : <EOL> with open ( jira_remote_files_path , '<STR_LIT:w>' ) as out : <EOL> out . write ( '<STR_LIT:{}>' ) <EOL> repo . run_git_command ( '<STR_LIT>' , '<STR_LIT>' , jira_remote_files_path , shadow = True ) <EOL> repo . run_git_command ( <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , shadow = True <EOL> ) <EOL> repo . run_git_command ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , shadow = True ) <EOL> repo . run_git_command ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> set_repo_version ( repo , <NUM_LIT:4> ) <EOL> def migration_0005 ( repo , init = False , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> if init : <EOL> set_repo_version ( repo , <NUM_LIT:5> ) <EOL> return <EOL> repo_path = repo . path <EOL> temp_path = os . path . normpath ( <EOL> os . path . join ( <EOL> repo_path , <EOL> '<STR_LIT>' , <EOL> repo . path . split ( '<STR_LIT:/>' ) [ - <NUM_LIT:1> ] + '<STR_LIT>' <EOL> ) <EOL> ) <EOL> repo . clone ( <EOL> repo . issue_url , <EOL> repo . get_jira , <EOL> temp_path , <EOL> ) <EOL> temp_dir = os . listdir ( temp_path ) <EOL> for filename in os . listdir ( repo_path ) : <EOL> if filename not in temp_dir and not filename . endswith ( '<STR_LIT>' ) : <EOL> shutil . copyfile ( <EOL> os . path . join ( repo_path , filename ) , <EOL> os . path . join ( temp_path , filename ) , <EOL> ) <EOL> shutil . rmtree ( repo_path ) <EOL> os . rename ( temp_path , repo_path ) <EOL> set_repo_version ( repo , <NUM_LIT:5> ) <EOL> def migration_0006 ( repo , init = False , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> if init : <EOL> set_repo_version ( repo , <NUM_LIT:6> ) <EOL> return <EOL> repo . run_git_command ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' % repo . get_metadata_path ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ) , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ) <EOL> set_repo_version ( repo , <NUM_LIT:6> ) <EOL> def migration_0007 ( repo , init = False , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> os . mkdir ( <EOL> repo . get_metadata_path ( <EOL> '<STR_LIT>' , <EOL> ) <EOL> ) <EOL> except OSError : <EOL> pass <EOL> with open ( repo . get_metadata_path ( '<STR_LIT>' , '<STR_LIT>' ) , '<STR_LIT:w>' ) as out : <EOL> out . write ( '<STR_LIT>' ) <EOL> repo . run_git_command ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> repo . get_metadata_path ( '<STR_LIT>' , '<STR_LIT>' , ) <EOL> ) <EOL> repo . run_git_command ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> failure_ok = True <EOL> ) <EOL> set_repo_version ( repo , <NUM_LIT:7> ) <EOL> def migration_0008 ( repo , init = False , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> if init : <EOL> set_repo_version ( repo , <NUM_LIT:8> ) <EOL> return <EOL> with open ( repo . get_metadata_path ( '<STR_LIT>' ) , '<STR_LIT:w>' ) as out : <EOL> out . write ( <EOL> '<STR_LIT:\n>' . join ( <EOL> [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ] <EOL> ) <EOL> ) <EOL> repo . run_git_command ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ) <EOL> repo . run_git_command ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> failure_ok = True <EOL> ) <EOL> files_to_add = [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT:version>' , <EOL> ] <EOL> for filename in files_to_add : <EOL> repo . run_git_command ( <EOL> '<STR_LIT>' , <EOL> repo . get_metadata_path ( filename ) , <EOL> failure_ok = True <EOL> ) <EOL> set_repo_version ( repo , <NUM_LIT:8> ) <EOL> def migration_0009 ( repo , init = False , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> if init : <EOL> set_repo_version ( repo , <NUM_LIT:9> ) <EOL> shutil . rmtree ( repo . get_metadata_path ( '<STR_LIT>' ) ) <EOL> os . mkdir ( <EOL> repo . get_metadata_path ( '<STR_LIT>' ) <EOL> ) <EOL> subprocess . check_call ( <EOL> ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT:.>' <EOL> ) , <EOL> cwd = repo . get_metadata_path ( '<STR_LIT>' ) , <EOL> stdout = subprocess . PIPE , <EOL> ) <EOL> try : <EOL> repo . run_git_command ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , shadow = True ) <EOL> except GitCommandError : <EOL> repo . run_git_command ( '<STR_LIT>' , '<STR_LIT>' , shadow = True ) <EOL> repo . run_git_command ( <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , shadow = True <EOL> ) <EOL> repo . run_git_command ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , shadow = True ) <EOL> set_repo_version ( repo , <NUM_LIT:9> ) <EOL> def migration_0010 ( repo , init = False , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> if init : <EOL> set_repo_version ( repo , <NUM_LIT:10> ) <EOL> return <EOL> with open ( repo . get_metadata_path ( '<STR_LIT>' ) , '<STR_LIT:w>' ) as out : <EOL> out . write ( <EOL> '<STR_LIT:\n>' . join ( <EOL> [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ] <EOL> ) <EOL> ) <EOL> repo . run_git_command ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ) <EOL> try : <EOL> os . mkdir ( <EOL> repo . get_metadata_path ( <EOL> '<STR_LIT>' , <EOL> ) <EOL> ) <EOL> except OSError : <EOL> pass <EOL> with open ( repo . get_metadata_path ( '<STR_LIT>' , '<STR_LIT>' ) , '<STR_LIT:w>' ) as out : <EOL> out . write ( '<STR_LIT>' ) <EOL> repo . run_git_command ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> repo . get_metadata_path ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ) <EOL> ) <EOL> repo . run_git_command ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> failure_ok = True , <EOL> ) <EOL> repo . run_git_command ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> failure_ok = True <EOL> ) <EOL> set_repo_version ( repo , <NUM_LIT:10> ) <EOL> def migration_0011 ( repo , init = False , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> if init : <EOL> set_repo_version ( repo , <NUM_LIT:11> ) <EOL> return <EOL> shutil . rmtree ( repo . get_metadata_path ( '<STR_LIT>' ) ) <EOL> os . mkdir ( <EOL> repo . get_metadata_path ( '<STR_LIT>' ) <EOL> ) <EOL> subprocess . check_call ( <EOL> ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT:.>' <EOL> ) , <EOL> cwd = repo . get_metadata_path ( '<STR_LIT>' ) , <EOL> stdout = subprocess . PIPE , <EOL> ) <EOL> try : <EOL> repo . run_git_command ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , shadow = True ) <EOL> except GitCommandError : <EOL> repo . run_git_command ( '<STR_LIT>' , '<STR_LIT>' , shadow = True ) <EOL> repo . run_git_command ( <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , shadow = True <EOL> ) <EOL> repo . run_git_command ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , shadow = True ) <EOL> repo . run_git_command ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> set_repo_version ( repo , <NUM_LIT:11> ) <EOL> def migration_0012 ( repo , init = False , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> subprocess . check_call ( <EOL> ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ) , <EOL> cwd = repo . get_metadata_path ( '<STR_LIT>' ) , <EOL> stdout = subprocess . PIPE , <EOL> stderr = subprocess . PIPE , <EOL> ) <EOL> set_repo_version ( repo , <NUM_LIT:12> ) <EOL> def migration_0013 ( repo , init = False , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> if init : <EOL> set_repo_version ( repo , <NUM_LIT> ) <EOL> return <EOL> result = repo . get_ticket_url ( ) <EOL> if result is not None : <EOL> set_repo_version ( repo , <NUM_LIT> ) <EOL> return <EOL> jira_base = utils . get_default_jira_server ( ) <EOL> ticket_number = repo . path . split ( '<STR_LIT:/>' ) [ - <NUM_LIT:1> : ] [ <NUM_LIT:0> ] . upper ( ) <EOL> issue_url = parse . urljoin ( <EOL> jira_base , <EOL> '<STR_LIT>' + ticket_number + '<STR_LIT:/>' , <EOL> ) <EOL> with open ( repo . get_metadata_path ( '<STR_LIT>' , '<STR_LIT:w>' ) ) as out : <EOL> out . write ( issue_url ) <EOL> set_repo_version ( repo , <NUM_LIT> ) <EOL> def migration_0014 ( repo , init = False , ** kwargs ) : <EOL> if init : <EOL> set_repo_version ( repo , <NUM_LIT> ) <EOL> return <EOL> with open ( repo . get_metadata_path ( '<STR_LIT>' ) , '<STR_LIT:w>' ) as out : <EOL> out . write ( <EOL> '<STR_LIT:\n>' . join ( <EOL> [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ] <EOL> ) <EOL> ) <EOL> if os . path . exists ( repo . get_local_path ( '<STR_LIT>' ) ) : <EOL> shutil . copyfile ( <EOL> repo . get_local_path ( '<STR_LIT>' ) , <EOL> repo . get_local_path ( '<STR_LIT>' ) , <EOL> ) <EOL> repo . run_git_command ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ) <EOL> if os . path . exists ( repo . get_metadata_path ( '<STR_LIT>' ) ) : <EOL> shutil . copyfile ( <EOL> repo . get_metadata_path ( '<STR_LIT>' ) , <EOL> repo . get_local_path ( '<STR_LIT>' ) <EOL> ) <EOL> repo . run_git_command ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ) <EOL> repo . run_git_command ( <EOL> '<STR_LIT>' , <EOL> repo . get_metadata_path ( '<STR_LIT>' ) <EOL> ) <EOL> repo . run_git_command ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' % repo . get_metadata_path ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ) , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ) <EOL> tracked_files = repo . run_git_command ( <EOL> '<STR_LIT>' , '<STR_LIT:-c>' , failure_ok = True <EOL> ) . split ( '<STR_LIT:\n>' ) <EOL> filtered_files = repo . filter_ignored_files ( <EOL> tracked_files , <EOL> '<STR_LIT>' <EOL> ) <EOL> ignored = repo . filter_ignored_files ( <EOL> set ( tracked_files ) - set ( filtered_files ) , <EOL> '<STR_LIT>' <EOL> ) <EOL> for filename in ignored : <EOL> repo . run_git_command ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> filename , <EOL> failure_ok = True , <EOL> shadow = True <EOL> ) <EOL> repo . run_git_command ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> failure_ok = True , <EOL> shadow = True <EOL> ) <EOL> set_repo_version ( repo , <NUM_LIT> ) <EOL> def migration_0015 ( repo , init = False , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> set_repo_version ( repo , <NUM_LIT:15> ) <EOL> def migration_0016 ( repo , init = False , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> macro_path = repo . get_metadata_path ( '<STR_LIT>' ) <EOL> if not os . path . exists ( macro_path ) : <EOL> with open ( macro_path , '<STR_LIT:w>' ) as out : <EOL> out . write ( '<STR_LIT>' ) <EOL> repo . run_git_command ( '<STR_LIT>' , '<STR_LIT>' , macro_path ) <EOL> repo . run_git_command ( <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , failure_ok = True <EOL> ) <EOL> set_repo_version ( repo , <NUM_LIT:16> ) </s>
