<s> import logging <EOL> import os <EOL> import subprocess <EOL> from googkit . compat . urllib import request <EOL> from googkit . lib . error import GoogkitError <EOL> from googkit . lib . i18n import _ <EOL> def run ( repos , target_path ) : <EOL> """<STR_LIT>""" <EOL> if os . path . exists ( target_path ) : <EOL> _pull ( repos , target_path ) <EOL> else : <EOL> _clone ( repos , target_path ) <EOL> def _git_cmd ( ) : <EOL> if os . name == '<STR_LIT>' : <EOL> return '<STR_LIT>' <EOL> else : <EOL> return '<STR_LIT>' <EOL> def _pull ( repos , target_path ) : <EOL> args = [ _git_cmd ( ) , '<STR_LIT>' ] <EOL> popen_args = { <EOL> '<STR_LIT>' : target_path , <EOL> '<STR_LIT>' : subprocess . PIPE , <EOL> '<STR_LIT>' : subprocess . PIPE , <EOL> } <EOL> proc = subprocess . Popen ( args , ** popen_args ) <EOL> result = proc . communicate ( ) <EOL> if proc . returncode != <NUM_LIT:0> : <EOL> raise GoogkitError ( _ ( '<STR_LIT>' ) . format ( <EOL> message = result [ <NUM_LIT:1> ] . decode ( ) ) ) <EOL> logging . debug ( result [ <NUM_LIT:0> ] . decode ( ) ) <EOL> def _clone ( repos , target_path ) : <EOL> args = [ _git_cmd ( ) , '<STR_LIT>' , repos , request . pathname2url ( target_path ) ] <EOL> popen_args = { <EOL> '<STR_LIT>' : subprocess . PIPE , <EOL> '<STR_LIT>' : subprocess . PIPE , <EOL> } <EOL> proc = subprocess . Popen ( args , ** popen_args ) <EOL> result = proc . communicate ( ) <EOL> if proc . returncode != <NUM_LIT:0> : <EOL> raise GoogkitError ( _ ( '<STR_LIT>' ) . format ( <EOL> message = result [ <NUM_LIT:1> ] . decode ( ) ) ) <EOL> logging . debug ( result [ <NUM_LIT:0> ] . decode ( ) ) </s>
