<s> import os <EOL> import sys <EOL> import argparse <EOL> import MySQLdb <EOL> sys . path += [ os . path . abspath ( '<STR_LIT>' ) ] <EOL> import OCP . settings <EOL> os . environ [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> from django . conf import settings <EOL> import ocpcaproj <EOL> import ocpcaprivate <EOL> class Dataset ( ) : <EOL> def __init__ ( self , inputData ) : <EOL> """<STR_LIT>""" <EOL> ( self . ximagesize , self . yimagesize , self . startslice , self . endslice , self . zoomlevels , self . zscale , self . startwindow , self . endwindow , self . starttime , self . endtime ) = inputData <EOL> class Project ( ) : <EOL> def __init__ ( self , inputData ) : <EOL> """<STR_LIT>""" <EOL> ( self . token , self . openid , self . dbhost , self . project , self . dbtype , self . dataset , self . dataurl , self . readonly , self . exceptions , self . resolution , self . public , self . kvengine , self . kvserver , self . propagate ) = inputData <EOL> class OCPAdmin ( ) : <EOL> def __init__ ( self , host , remotehost , token , dataset ) : <EOL> """<STR_LIT>""" <EOL> self . token = token <EOL> self . dataset = dataset <EOL> self . conn = MySQLdb . connect ( host = host , user = ocpcaprivate . dbuser , passwd = ocpcaprivate . dbpasswd , db = ocpcaprivate . db ) <EOL> self . remoteconn = MySQLdb . connect ( host = remotehost , user = ocpcaprivate . dbuser , passwd = ocpcaprivate . dbpasswd , db = ocpcaprivate . db ) <EOL> def loadProject ( self ) : <EOL> """<STR_LIT>""" <EOL> sql = "<STR_LIT>" % ( ocpcaprivate . projects , self . token ) <EOL> try : <EOL> cursor = self . conn . cursor ( ) <EOL> cursor . execute ( sql ) <EOL> except MySQLdb . Error , e : <EOL> print e <EOL> row = cursor . fetchone ( ) <EOL> if ( row == None ) : <EOL> raise Exception ( "<STR_LIT>" . format ( self . token ) ) <EOL> return row <EOL> def insertProject ( self ) : <EOL> """<STR_LIT>""" <EOL> proj = Project ( self . loadProject ( ) ) <EOL> sql = "<STR_LIT>" . format ( ocpcaprivate . projects , self . token , proj . openid , proj . dbhost , proj . project , proj . dbtype , proj . dataset , proj . dataurl , proj . readonly , proj . exceptions , proj . resolution , proj . public , proj . kvengine , proj . kvserver , proj . propagate ) <EOL> try : <EOL> cursor = self . remoteconn . cursor ( ) <EOL> cursor . execute ( sql ) <EOL> self . remoteconn . commit ( ) <EOL> except MySQLdb . Error , e : <EOL> print e <EOL> def loadDataset ( self ) : <EOL> """<STR_LIT>""" <EOL> sql = "<STR_LIT>" % ( ocpcaprivate . datasets , self . dataset ) <EOL> try : <EOL> cursor = self . conn . cursor ( ) <EOL> cursor . execute ( sql ) <EOL> except MySQLdb . Error , e : <EOL> print e <EOL> row = cursor . fetchone ( ) <EOL> if ( row == None ) : <EOL> raise Exception ( "<STR_LIT>" . format ( self . dataset ) ) <EOL> return row <EOL> def insertDataset ( self ) : <EOL> """<STR_LIT>""" <EOL> dat = Dataset ( self . loadDataset ( ) ) <EOL> sql = "<STR_LIT>" . format ( ocpcaprivate . datasets , self . dataset , dat . ximagesize , dat . yimagesize , dat . startslice , dat . endslice , dat . zoomlevels , dat . zscale , dat . startwindow , dat . endwindow , dat . starttime , dat . endtime ) <EOL> try : <EOL> cursor = self . remoteconn . cursor ( ) <EOL> cursor . execute ( sql ) <EOL> self . remoteconn . commit ( ) <EOL> except MySQLdb . Error , e : <EOL> print e <EOL> def main ( ) : <EOL> parser = argparse . ArgumentParser ( description = "<STR_LIT>" ) <EOL> parser . add_argument ( '<STR_LIT:host>' , action = "<STR_LIT:store>" , help = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , action = "<STR_LIT:store>" , help = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , action = "<STR_LIT:store>" , help = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , action = "<STR_LIT:store>" , help = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , dest = "<STR_LIT>" , action = "<STR_LIT:store_true>" , help = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , dest = "<STR_LIT>" , action = "<STR_LIT:store_true>" , help = '<STR_LIT>' ) <EOL> result = parser . parse_args ( ) <EOL> ocpadmin = OCPAdmin ( result . host , result . remotehost , result . token , result . dataset ) <EOL> if ( result . proj ) : <EOL> ocpadmin . insertProject ( ) <EOL> elif ( result . dst ) : <EOL> ocpadmin . insertDataset ( ) <EOL> else : <EOL> ocpadmin . insertDataset ( ) <EOL> ocpadmin . insertProject ( ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> main ( ) </s>
