<s> import xmlrpclib <EOL> from django . template . defaultfilters import slugify <EOL> from cheeserater . packages . models import Package , Topic , Category <EOL> CHEESESHOP = "<STR_LIT>" <EOL> def main ( skip_until = None ) : <EOL> s = xmlrpclib . Server ( CHEESESHOP ) <EOL> names = sorted ( s . list_packages ( ) , key = lambda s : s . lower ( ) ) <EOL> for name in names : <EOL> if skip_until and name < skip_until : <EOL> print "<STR_LIT>" % name <EOL> continue <EOL> print "<STR_LIT>" % name <EOL> versions = s . package_releases ( name ) <EOL> try : <EOL> info = s . release_data ( name , versions [ - <NUM_LIT:1> ] ) <EOL> except IndexError : <EOL> print "<STR_LIT>" % name <EOL> continue <EOL> package , created = Package . objects . get_or_create ( name = name ) <EOL> if created : <EOL> print "<STR_LIT>" % name <EOL> package . version = versions [ - <NUM_LIT:1> ] <EOL> for f in [ '<STR_LIT>' , '<STR_LIT:description>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] : <EOL> value = info . get ( f , "<STR_LIT>" ) <EOL> if value is None or value . strip ( ) == "<STR_LIT>" : <EOL> value = "<STR_LIT>" <EOL> value = value . strip ( ) <EOL> setattr ( package , f , value ) <EOL> package . save ( ) <EOL> categories = [ ] <EOL> for classifier in info [ "<STR_LIT>" ] : <EOL> topic , value = map ( str . strip , classifier . split ( "<STR_LIT>" , <NUM_LIT:1> ) ) <EOL> topic , created = Topic . objects . get_or_create ( <EOL> name = topic , <EOL> defaults = { "<STR_LIT>" : slugify ( topic ) [ : <NUM_LIT:50> ] } <EOL> ) <EOL> if created : print "<STR_LIT>" % topic . name <EOL> cat , created = Category . objects . get_or_create ( <EOL> topic = topic , <EOL> value = value , <EOL> defaults = { "<STR_LIT>" : slugify ( value ) [ : <NUM_LIT:50> ] } <EOL> ) <EOL> if created : print "<STR_LIT>" % cat <EOL> categories . append ( cat ) <EOL> package . categories = categories <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> import optparse <EOL> parser = optparse . OptionParser ( ) <EOL> parser . add_option ( "<STR_LIT>" , dest = "<STR_LIT>" , default = None ) <EOL> options , args = parser . parse_args ( ) <EOL> main ( options . skip_until ) </s>
