<s> '''<STR_LIT>''' <EOL> from django . core . management . base import BaseCommand , CommandError <EOL> from hwdoc . models import EquipmentModel , Equipment , ServerManagement , Rack <EOL> from django . utils . translation import ugettext as _ <EOL> from django . utils . translation import ugettext_lazy as _l <EOL> import csv <EOL> import re <EOL> class Command ( BaseCommand ) : <EOL> '''<STR_LIT>''' <EOL> help = _l ( '<STR_LIT>' ) <EOL> args = '<STR_LIT>' <EOL> label = _l ( '<STR_LIT>' ) <EOL> def handle ( self , * args , ** options ) : <EOL> '''<STR_LIT>''' <EOL> if args is None or len ( args ) != <NUM_LIT:1> : <EOL> raise CommandError ( _ ( '<STR_LIT>' ) ) <EOL> csvname = args [ <NUM_LIT:0> ] <EOL> count = <NUM_LIT:0> <EOL> try : <EOL> with open ( csvname , '<STR_LIT:rb>' ) as f : <EOL> reader = csv . reader ( f ) <EOL> for row in reader : <EOL> ( aa , eq , sn , dns , passwd , rack , unit , pdua , pdub , mac ) = row [ : <NUM_LIT:10> ] <EOL> if eq . startswith ( '<STR_LIT>' ) : <EOL> eq = '<STR_LIT>' <EOL> elif re . match ( '<STR_LIT>' , eq ) : <EOL> eq = '<STR_LIT>' <EOL> elif eq . startswith ( '<STR_LIT>' ) : <EOL> eq = '<STR_LIT>' <EOL> elif eq . startswith ( '<STR_LIT>' ) : <EOL> eq = '<STR_LIT>' <EOL> else : <EOL> continue <EOL> try : <EOL> rack = Rack . objects . get ( name = rack ) <EOL> except Rack . DoesNotExist : <EOL> raise RuntimeError ( _ ( '<STR_LIT>' % { '<STR_LIT>' : rack } ) ) <EOL> unit = unit . split ( '<STR_LIT:->' ) [ <NUM_LIT:0> ] [ <NUM_LIT:1> : ] <EOL> e = Equipment ( ) <EOL> if eq == '<STR_LIT>' : <EOL> e . model = EquipmentModel . objects . get ( name = '<STR_LIT>' ) <EOL> e . purpose = eq <EOL> elif eq == '<STR_LIT>' : <EOL> e . model = EquipmentModel . objects . get ( name = '<STR_LIT>' ) <EOL> e . purpose = eq <EOL> elif eq == '<STR_LIT>' : <EOL> e . model = EquipmentModel . objects . get ( name = '<STR_LIT>' ) <EOL> e . purpose = eq <EOL> elif eq == '<STR_LIT>' : <EOL> e . model = EquipmentModel . objects . get ( name = '<STR_LIT>' ) <EOL> e . purpose = eq <EOL> e . serial = sn <EOL> e . rack = rack <EOL> e . unit = unit <EOL> e . save ( ) <EOL> if eq == '<STR_LIT>' or eq == '<STR_LIT>' or eq == '<STR_LIT>' : <EOL> s = ServerManagement ( ) <EOL> s . equipment = e <EOL> if eq == '<STR_LIT>' : <EOL> s . method = '<STR_LIT>' <EOL> s . username = '<STR_LIT>' <EOL> elif eq == '<STR_LIT>' or eq == '<STR_LIT>' : <EOL> s . method = '<STR_LIT>' <EOL> s . username = '<STR_LIT>' <EOL> s . hostname = dns <EOL> s . password = passwd <EOL> s . mac = mac <EOL> s . save ( ) <EOL> print _ ( '<STR_LIT>' ) % { '<STR_LIT>' : eq , '<STR_LIT>' : sn } <EOL> count += <NUM_LIT:1> <EOL> print _ ( '<STR_LIT>' ) + str ( count ) <EOL> except IOError : <EOL> raise CommandError ( _ ( '<STR_LIT>' ) ) </s>
