import sys
import socket
import os
IPAddr=socket.gethostbyname(socket.gethostname())
if IPAddr[0:11] == "100.100.100": #4269
    host = "100.100.100.11"
    port = "5432"
    dbname = "sig4269"
    sigdb="sig4269"
    refdb="ref_geo4269"
    password = "XXXXXX"
if IPAddr[0:9] == "192.168.0": #01
    host = "192.168.0.201"
    port = "5432"
    dbname = "sig01"
    sigdb="sig01"
    refdb="ref_geo01"
    password = "XXXXXX"
if IPAddr[0:9] == "192.168.1": #0726
    host = "192.168.1.201"
    port = "5432"
    dbname = "sig0726"
    sigdb="sig0726"
    refdb="ref_geo0726"
    password = "XXXXXX"
if sys.platform == 'linux':
    os_user = os.environ['USER']
else:
    os_user = os.environ['USERNAME']
if os_user == 'STAGE':
    os_user='stage'

geom = "geom"
champ_travaux_prevus_multipolygon="""(gid serial NOT NULL, groupe_gestion text, gestion_lib text, id_gestion text, datedebut date, datefin date, commentaire text, surface_m2 double precision, surface_ha double precision,  date_creation date, date_maj date, geom geometry(MultiPolygon,2154))"""
champ_travaux_prevus_multilinestring="""(gid serial NOT NULL, groupe_gestion text, gestion_lib text, id_gestion text, datedebut date, datefin date, commentaire text, longueur_m double precision, longueur_km double precision,  date_creation date, date_maj date, geom geometry(MultiLineString,2154))"""
champ_travaux_prevus_point = """(gid serial NOT NULL, groupe_gestion text, gestion_lib text, id_gestion text, datedebut date, datefin date, commentaire text, x_wgs84 double precision, y_wgs84 double precision,  date_creation date, date_maj date, geom geometry(Point,2154))"""

champ_viergePolygone = """(gid serial NOT NULL, commentaire text, surface_m2 double precision, surface_ha double precision, geom geometry(MultiPolygon,2154))"""
champ_viergeLigne = """(gid serial NOT NULL, commentaire text, longueur_m double precision, longueur_km double precision, geom geometry(MultiLineString,2154))"""
champ_viergePoint = """(gid serial NOT NULL, commentaire text, x_wgs84 double precision, y_wgs84 double precision, geom geometry(Point,2154))"""

champ_habitat = """(gid serial NOT NULL, cd_cb_01 text, lb_cb97_fr_01 text, occupation_01 integer, cd_cb_02 text, lb_cb97_fr_02 text, occupation_02 integer, cd_cb_03 text, lb_cb97_fr_03 text, occupation_03 integer, milieu_code text, milieu_libelle text, surface_m2 double precision, surface_ha double precision, commentaire text, date_creation date, date_maj date, geom geometry(MultiPolygon,2154))"""

champ_contour="""(gid serial NOT NULL, date_creation date, date_maj date, utilisateur character varying, dept character(2), nom character varying, surface_m2 double precision, surface_ha double precision, type_site character varying, type_milieu character varying, date_premier_pg integer, date_debut_pg integer, date_fin_pg integer, referent character varying, gestion_deleguee character varying, terrain_militaire character(3), ens character(3), zh character(3), adapt_pmr character(3), inform character(3), guide character(3), ouverture_public character(3), obs character(3), anim character(3), n2000_anim character(3), contrat_n2000_conseil character(3), n2000_op character(3), contrat_n2000_benef character(3), contrat_agri character(3), bc_habitat integer, bc_amphibien integer, bc_coleoptere integer, bc_crustace integer, bc_mammifere integer, bc_chiroptere integer, bc_mollusque integer, bc_odonate integer, bc_oiseau integer, bc_orthoptere integer, bc_poisson integer, bc_reptile integer, bc_rhopalocere integer, bc_heterocere integer, bc_autre_invertebre integer, bc_flore integer, bc_bryophyte integer, bc_champignon integer, suiv_analyse_sol character(3), suiv_piezo character(3), suiv_climat character(3), suiv_topo character(3), suiv_habitat character(3), suiv_amphibien character(3), suiv_coleoptere character(3), suiv_crustace character(3), suiv_mammifere character(3), suiv_chiroptere character(3), suiv_mollusque character(3), suiv_odonate character(3), suiv_oiseau character(3), suiv_orthoptere character(3), suiv_poisson character(3), suiv_reptile character(3), suiv_rhopalocere character(3), suiv_heterocere character(3), suiv_autre_invertebre character(3), suiv_flore character(3), suiv_bryophyte character(3), suiv_champignon character(3), suiv_analyse_eau character(3), suiv_phenologie character(3), suiv_frequentation character(3), suiv_paysager character(3), suiv_autre character(3), commentaire text, geom geometry(MultiPolygon,2154))
"""

champ_vegethab_point = """(
    gid serial NOT NULL ,
    cd_eu_01 character varying(254) COLLATE pg_catalog."default",
    lb_eu_01 character varying(254) COLLATE pg_catalog."default",
    occupati_1 bigint,
    cd_eu_02 character varying(254) COLLATE pg_catalog."default",
    lb_eu_02 character varying(254) COLLATE pg_catalog."default",
    occupati_2 bigint,
    cd_eu_03 character varying(254) COLLATE pg_catalog."default",
    lb_eu_03 character varying(254) COLLATE pg_catalog."default",
    occupati_3 bigint,
    milieu_cod character varying(254) COLLATE pg_catalog."default",
    milieu_lib character varying(254) COLLATE pg_catalog."default",
    surface_m2 numeric,
    surface_ha numeric,
    commentair character varying(254) COLLATE pg_catalog."default",
    date_creat date,
    date_maj date,
    num_phyto character varying(254) COLLATE pg_catalog."default",
    type_unite character varying(254) COLLATE pg_catalog."default",
    dynamique character varying(254) COLLATE pg_catalog."default",
    gestio_obs character varying(254) COLLATE pg_catalog."default",
    degrad_obs character varying(254) COLLATE pg_catalog."default",
    eta_conser character varying(254) COLLATE pg_catalog."default",
    clas_phyto character varying(254) COLLATE pg_catalog."default",
    alli_phyto character varying(254) COLLATE pg_catalog."default",
    syntaxon character varying(254) COLLATE pg_catalog."default",
    n2000 character varying(254) COLLATE pg_catalog."default",
    lrr_aura character varying(254) COLLATE pg_catalog."default",
    lrr_cbna character varying(254) COLLATE pg_catalog."default",
    lrr_cbnmc character varying(254) COLLATE pg_catalog."default",
    vege_enjeu character varying(254) COLLATE pg_catalog."default",
    num_photo character varying(254) COLLATE pg_catalog."default",
    nature_obs character varying(254) COLLATE pg_catalog."default",
    date_sais date,
    s_al_phyto character varying(254) COLLATE pg_catalog."default",
    alli_name character varying(254) COLLATE pg_catalog."default",
    salli_name character varying(254) COLLATE pg_catalog."default",
    class_name character varying(254) COLLATE pg_catalog."default",
    geom geometry(Point,2154)
)
"""
champ_vegethab_multilinestring = """(
    gid serial NOT NULL ,
    cd_eu_01 character varying(254) COLLATE pg_catalog."default",
    lb_eu_01 character varying(254) COLLATE pg_catalog."default",
    occupati_1 bigint,
    cd_eu_02 character varying(254) COLLATE pg_catalog."default",
    lb_eu_02 character varying(254) COLLATE pg_catalog."default",
    occupati_2 bigint,
    cd_eu_03 character varying(254) COLLATE pg_catalog."default",
    lb_eu_03 character varying(254) COLLATE pg_catalog."default",
    occupati_3 bigint,
    milieu_cod character varying(254) COLLATE pg_catalog."default",
    milieu_lib character varying(254) COLLATE pg_catalog."default",
    surface_m2 numeric,
    surface_ha numeric,
    commentair character varying(254) COLLATE pg_catalog."default",
    date_creat date,
    date_maj date,
    num_phyto character varying(254) COLLATE pg_catalog."default",
    type_unite character varying(254) COLLATE pg_catalog."default",
    dynamique character varying(254) COLLATE pg_catalog."default",
    gestio_obs character varying(254) COLLATE pg_catalog."default",
    degrad_obs character varying(254) COLLATE pg_catalog."default",
    eta_conser character varying(254) COLLATE pg_catalog."default",
    clas_phyto character varying(254) COLLATE pg_catalog."default",
    alli_phyto character varying(254) COLLATE pg_catalog."default",
    syntaxon character varying(254) COLLATE pg_catalog."default",
    n2000 character varying(254) COLLATE pg_catalog."default",
    lrr_aura character varying(254) COLLATE pg_catalog."default",
    lrr_cbna character varying(254) COLLATE pg_catalog."default",
    lrr_cbnmc character varying(254) COLLATE pg_catalog."default",
    vege_enjeu character varying(254) COLLATE pg_catalog."default",
    num_photo character varying(254) COLLATE pg_catalog."default",
    nature_obs character varying(254) COLLATE pg_catalog."default",
    date_sais date,
    s_al_phyto character varying(254) COLLATE pg_catalog."default",
    alli_name character varying(254) COLLATE pg_catalog."default",
    salli_name character varying(254) COLLATE pg_catalog."default",
    class_name character varying(254) COLLATE pg_catalog."default",
    geom geometry(MultiLineString,2154)
)
"""
champ_vegethab_multipolygon = """(
    gid serial NOT NULL ,
    cd_eu_01 character varying(254) COLLATE pg_catalog."default",
    lb_eu_01 character varying(254) COLLATE pg_catalog."default",
    occupati_1 bigint,
    cd_eu_02 character varying(254) COLLATE pg_catalog."default",
    lb_eu_02 character varying(254) COLLATE pg_catalog."default",
    occupati_2 bigint,
    cd_eu_03 character varying(254) COLLATE pg_catalog."default",
    lb_eu_03 character varying(254) COLLATE pg_catalog."default",
    occupati_3 bigint,
    milieu_cod character varying(254) COLLATE pg_catalog."default",
    milieu_lib character varying(254) COLLATE pg_catalog."default",
    surface_m2 numeric,
    surface_ha numeric,
    commentair character varying(254) COLLATE pg_catalog."default",
    date_creat date,
    date_maj date,
    num_phyto character varying(254) COLLATE pg_catalog."default",
    type_unite character varying(254) COLLATE pg_catalog."default",
    dynamique character varying(254) COLLATE pg_catalog."default",
    gestio_obs character varying(254) COLLATE pg_catalog."default",
    degrad_obs character varying(254) COLLATE pg_catalog."default",
    eta_conser character varying(254) COLLATE pg_catalog."default",
    clas_phyto character varying(254) COLLATE pg_catalog."default",
    alli_phyto character varying(254) COLLATE pg_catalog."default",
    syntaxon character varying(254) COLLATE pg_catalog."default",
    n2000 character varying(254) COLLATE pg_catalog."default",
    lrr_aura character varying(254) COLLATE pg_catalog."default",
    lrr_cbna character varying(254) COLLATE pg_catalog."default",
    lrr_cbnmc character varying(254) COLLATE pg_catalog."default",
    vege_enjeu character varying(254) COLLATE pg_catalog."default",
    num_photo character varying(254) COLLATE pg_catalog."default",
    nature_obs character varying(254) COLLATE pg_catalog."default",
    date_sais date,
    s_al_phyto character varying(254) COLLATE pg_catalog."default",
    alli_name character varying(254) COLLATE pg_catalog."default",
    salli_name character varying(254) COLLATE pg_catalog."default",
    class_name character varying(254) COLLATE pg_catalog."default",
    geom geometry(MultiPolygon,2154)
)
"""