diff -ur v6/fsyn.py v7/fsyn.py --- v6/fsyn.py 2020-05-01 00:00:02.000000000 +0900 +++ v7/fsyn.py 2020-05-03 01:43:08.000000000 +0900 @@ -25,6 +25,15 @@ s = sys.stdin.readline().strip() return s == 'y' +def rm_confirm(path): + if path_exists( path ): + if not confirm( 'exists {}, remove ok?'.format( path ) ): + dbg.err_exit( 'cancel' ) + cmd = 'rm -rf ' + path + cmd_call( cmd ) + +cut_tail_sla = lambda path: path[ : -1 ] if path[-1] == '/' else path + def fsyn_new(dir_path): @@ -199,21 +208,28 @@ id_lst = ids_from( id ) return sorted_ids( filter( lambda id: not get_link( id ).to, id_lst ) ) - def tails(id='org'): - ids = get_tails( id ) + def get_ctails(): + return get_tails( get_curr() ) + + def tails(): + ids = get_tails() show_ids( ids, 'tail' ) def ctails(): - tails( get_curr() ) + ids = get_ctails() + show_ids( ids, 'ctail' ) def get_latest(id='org'): return max( get_tails(), key=tm_ut.str_to_sec ) - def latest(id='org'): - dbg.out( get_latest( id ) ) + def get_clatest(): + return get_latest( get_curr() ) + + def latest(): + dbg.out( get_latest() ) def clatest(): - latest( get_curr() ) + dbg.out( get_clatest() ) def get_prev(id): link = get_link( id ) @@ -254,7 +270,7 @@ cmp = get_cmp( id, targ_id ) if cmp.rm: - cmd = 'rm -f ' + to_str( cmp.rm, delim=' ' ) + cmd = '( cd {} ; rm -f {} )'.format( dir_path, to_str( cmp.rm, delim=' ' ) ) cmd_call( cmd ) set_curr( targ_id ) @@ -315,7 +331,8 @@ def fix_link(id): link = get_link( id ) - chg = False + e = empty.new() + e.chg = False def fix_from(): id_from = link.from_ @@ -327,7 +344,7 @@ dbg.out( msg ) link.from_ = '' - chg = True + e.chg = True msg_done( 'remove', id_from ) return @@ -346,7 +363,7 @@ dbg.out( msg ) link.to.remove( id_to ) - chg = True + e.chg = True msg_done( 'remove', id_to ) return @@ -362,7 +379,7 @@ for id_to in link.to: fix_to( id_to ) fix_from() - if chg: + if e.chg: put_link( id, link ) def fixlink(): @@ -402,6 +419,8 @@ def push(to_path): + to_path = cut_tail_sla( to_path ) + from_path = to_path if to_path == 'site_ut': from_path = 'site_ut' @@ -449,13 +468,15 @@ push_to( get_curr() ) if from_path == 'site_ut': - cmd = get_site_ut_cmd( 'put', fsyn_BASE, cd_dir=to_path ) + cmd = get_site_ut_cmd( 'put -verb', fsyn_BASE, cd_dir=to_path ) dbg.out( 'upload cmd={} ... '.format( cmd ), '' ) - cmd_call( cmd ) + cmd_ut.call_show( cmd ) # for -verb showing cmd_ut.rm_rf( to_path ) dbg.out( 'ok' ) - def pull(from_path): + def pull(from_path, do_checkout_clatest=True): + from_path = cut_tail_sla( from_path ) + def copy(id, name, force=False): fn = path_join( fsyn_BASE, id, name ) if not com_exists( from_path, fn ): @@ -488,9 +509,42 @@ if com_exists( from_path, path_join( fsyn_BASE, id, 'snap' ) ): # ! link pull_from( id ) + if do_checkout_clatest: + checkout( get_clatest() ) + return empty.new( locals() ) +def clone(cmd, dir_path): + path = cut_tail_sla( cmd.args[ 0 ] ) + + if not path.endswith( '.fsyn' ): + dbg.help_exit( cmd.help ) + + path = path[ : -len( '.fsyn' ) ] + + (DIR, BASE) = os.path.split( path ) + dot_fsyn = BASE + '.fsyn' + + rm_confirm( BASE ) + rm_confirm( dot_fsyn ) + + cmd = 'mkdir -p {} {}'.format( BASE, dot_fsyn ) + cmd_call( cmd ) + + cmd = 'echo org > {}/curr'.format( dot_fsyn ) + cmd_call( cmd ) + + dir_path = path_join( dir_path, BASE ) + fsyn = fsyn_new( dir_path ) + + fsyn.pull( DIR, do_checkout_clatest=False ) + fsyn.ckout_org() + + id = fsyn.get_clatest() + fsyn.checkout( id ) + + if __name__ == "__main__": cmds = [ arg.cmd_new( 'create' ), @@ -509,12 +563,17 @@ arg.cmd_new( 'fixlink', comment='fix link info' ), arg.cmd_new( 'push', [ 'to_path' ] ), arg.cmd_new( 'pull', [ 'from_path' ] ), + arg.cmd_new( 'clone', [ 'dot_fsyn_path' ], comment='ex. site/foo.fsyn' ), ] cmd = arg.get_name_args( cmds ) dir_path = os.getcwd() - fsyn = fsyn_new( dir_path ) - func = getattr( fsyn, cmd.name ) - func( *cmd.args ) + if cmd.name == 'clone': + clone( cmd, dir_path ) + else: + fsyn = fsyn_new( dir_path ) + + func = getattr( fsyn, cmd.name ) + func( *cmd.args ) # EOF