<s> import logging <EOL> import os <EOL> import sys <EOL> sys . path . extend ( [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ] ) <EOL> os . environ . setdefault ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> from django . db . models . loading import cache <EOL> cache . get_apps ( ) <EOL> from freenasUI . common . ssl import ( <EOL> load_certificate , <EOL> export_privatekey , <EOL> ) <EOL> from freenasUI . system . models import ( <EOL> Settings , <EOL> Certificate , <EOL> CERT_TYPE_EXISTING , <EOL> ) <EOL> log = logging . getLogger ( '<STR_LIT>' ) <EOL> def main ( certfile , keyfile ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> with open ( certfile , "<STR_LIT:r>" ) as f : <EOL> crt = f . read ( ) <EOL> except IOError : <EOL> print "<STR_LIT>" % certfile <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> try : <EOL> with open ( keyfile , "<STR_LIT:r>" ) as f : <EOL> key = f . read ( ) <EOL> except IOError : <EOL> print "<STR_LIT>" % keyfile <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> cert_info = load_certificate ( crt ) <EOL> created_cert = Certificate . objects . create ( <EOL> cert_name = "<STR_LIT>" , <EOL> cert_type = CERT_TYPE_EXISTING , <EOL> cert_certificate = crt , <EOL> cert_privatekey = export_privatekey ( key ) , <EOL> cert_country = cert_info [ '<STR_LIT>' ] , <EOL> cert_state = cert_info [ '<STR_LIT:state>' ] , <EOL> cert_city = cert_info [ '<STR_LIT>' ] , <EOL> cert_organization = cert_info [ '<STR_LIT>' ] , <EOL> cert_common = cert_info [ '<STR_LIT>' ] , <EOL> cert_email = cert_info [ '<STR_LIT:email>' ] , <EOL> cert_digest_algorithm = cert_info [ '<STR_LIT>' ] <EOL> ) <EOL> fnassettings = Settings . objects . all ( ) [ <NUM_LIT:0> ] <EOL> fnassettings . stg_guicertificate = created_cert <EOL> fnassettings . save ( ) <EOL> def usage ( ) : <EOL> usage_str = """<STR_LIT>""" % ( os . path . basename ( sys . argv [ <NUM_LIT:0> ] ) , ) <EOL> sys . exit ( usage_str ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> if len ( sys . argv ) < <NUM_LIT:3> : <EOL> usage ( ) <EOL> else : <EOL> main ( sys . argv [ <NUM_LIT:1> ] , sys . argv [ <NUM_LIT:2> ] ) </s>
