<s> import urllib , json , os <EOL> from default_files import gitignore , wingproj , license , readme , setupfile , testfile <EOL> def get_default_files ( name , desc ) : <EOL> """<STR_LIT>""" <EOL> defaultfiles = [ [ '<STR_LIT>' , gitignore ( ) ] , <EOL> [ '<STR_LIT>' , readme ( name , desc ) ] , <EOL> [ '<STR_LIT>' , license ( ) ] ] <EOL> return defaultfiles <EOL> def get_default_py_files ( name , desc , url ) : <EOL> """<STR_LIT>""" <EOL> defaultfiles = [ [ '<STR_LIT>' , setupfile ( name , url , desc ) ] ] <EOL> return defaultfiles <EOL> make_src_dir = True <EOL> def prep_directory ( basedir ) : <EOL> if not os . path . exists ( basedir ) : <EOL> os . mkdir ( basedir ) <EOL> def writefile ( fpath , data ) : <EOL> f = open ( fpath , '<STR_LIT:wb>' ) <EOL> f . write ( data ) <EOL> f . close ( ) <EOL> def write_default_files ( dpath , name , desc , url ) : <EOL> if os . path . exists ( dpath ) : <EOL> onlyfiles = [ f for f in os . listdir ( dpath ) <EOL> if os . path . isfile ( os . path . join ( dpath , f ) ) ] <EOL> if len ( onlyfiles ) > <NUM_LIT:0> : <EOL> return <EOL> print "<STR_LIT>" <EOL> files = get_default_files ( name , desc ) <EOL> if "<STR_LIT>" in desc . lower ( ) : <EOL> files = files + get_default_py_files ( name , desc , url ) <EOL> if make_src_dir : <EOL> srcdir = dpath + '<STR_LIT>' <EOL> os . mkdir ( srcdir ) <EOL> writefile ( srcdir + '<STR_LIT>' , '<STR_LIT>' ) <EOL> testdir = dpath + '<STR_LIT>' <EOL> os . mkdir ( testdir ) <EOL> writefile ( testdir + '<STR_LIT>' , '<STR_LIT>' ) <EOL> writefile ( testdir + '<STR_LIT>' , testfile ( name ) ) <EOL> for fname , data in files : <EOL> fn = '<STR_LIT:/>' . join ( [ dpath , fname ] ) <EOL> writefile ( fn , data ) <EOL> def process ( cmd , name , fpath , ask , desc , url , typ = "<STR_LIT>" ) : <EOL> if ask : <EOL> print "<STR_LIT>" % name <EOL> resp = raw_input ( "<STR_LIT>" ) <EOL> if resp == "<STR_LIT>" or resp == "<STR_LIT:U+0020>" : <EOL> return <EOL> os . system ( cmd ) <EOL> if typ == "<STR_LIT>" : <EOL> write_default_files ( fpath , name , desc , url ) <EOL> def get_gists ( uname , ask = False , basedir = '<STR_LIT>' ) : <EOL> print <EOL> print "<STR_LIT>" % uname <EOL> print <EOL> gists = urllib . urlopen ( "<STR_LIT>" % uname ) <EOL> wingfn = '<STR_LIT>' <EOL> if basedir : <EOL> prep_directory ( basedir ) <EOL> for item in json . loads ( gists . readlines ( ) [ <NUM_LIT:0> ] ) : <EOL> name = '<STR_LIT:->' . join ( item [ '<STR_LIT>' ] . keys ( ) [ - <NUM_LIT:1> ] . split ( '<STR_LIT:.>' ) ) <EOL> if basedir : <EOL> fpath = '<STR_LIT:/>' . join ( [ basedir , name ] ) <EOL> else : <EOL> fpath = name <EOL> if os . path . exists ( fpath ) : <EOL> continue <EOL> desc = item [ '<STR_LIT:description>' ] <EOL> idn = item [ '<STR_LIT:id>' ] <EOL> url = item [ '<STR_LIT>' ] <EOL> cmd = "<STR_LIT>" % ( idn , fpath ) <EOL> process ( cmd , name , fpath , ask , desc , url , typ = "<STR_LIT>" ) <EOL> print <EOL> def get_repos ( uname , ask = False , basedir = '<STR_LIT>' ) : <EOL> print <EOL> print "<STR_LIT>" % uname <EOL> print <EOL> gists = urllib . urlopen ( "<STR_LIT>" % uname ) <EOL> if basedir : <EOL> prep_directory ( basedir ) <EOL> for item in json . loads ( gists . readlines ( ) [ <NUM_LIT:0> ] ) : <EOL> name = item [ '<STR_LIT>' ] <EOL> if basedir : <EOL> fpath = '<STR_LIT:/>' . join ( [ basedir , item [ '<STR_LIT:name>' ] ] ) <EOL> else : <EOL> fpath = item [ '<STR_LIT:name>' ] <EOL> if os . path . exists ( fpath ) : <EOL> continue <EOL> cmd = "<STR_LIT>" % ( name , fpath ) <EOL> desc = item [ '<STR_LIT:description>' ] <EOL> url = item [ '<STR_LIT>' ] <EOL> process ( cmd , item [ '<STR_LIT:name>' ] , fpath , ask , desc , url , typ = "<STR_LIT>" ) <EOL> print </s>
