SHARE
TWEET

Untitled

a guest Oct 16th, 2019 87 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/env python
  2. # -*- mode: utf-8; coding: utf-8; -*-
  3. import argparse
  4. import pathlib
  5. import urllib.parse
  6. import subprocess
  7.  
  8.  
  9. def parse_arguments():
  10.     parser = argparse.ArgumentParser()
  11.  
  12.     parser.add_argument( 'url', metavar='URL', type=str, help='Git のリポジトリ URL' )
  13.  
  14.     return parser.parse_args()
  15.  
  16.  
  17. def main():
  18.     args        = parse_arguments()
  19.  
  20.     url         = urllib.parse.urlparse( args.url )
  21.  
  22.     base_dir    =  pathlib.Path.home() / 'opt' / 'src'
  23.     host_dir    =  base_dir / url.hostname
  24.     path_parts  =  pathlib.Path( url.path ).parts
  25.  
  26.     parent_dir  = host_dir.joinpath( *path_parts[1:-1] )
  27.  
  28.     if not parent_dir.exists():
  29.         print( "mkdir -p {}".format( parent_dir ) )
  30.         parent_dir.mkdir( parents=True )
  31.  
  32.     origin      = url.hostname
  33.  
  34.     subprocess.run( [ 'git', '-C', str( parent_dir ), 'clone', '--origin', origin, url.geturl() ] )
  35.  
  36.  
  37. if __name__ == '__main__':
  38.     main()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top