# -*- coding: utf-8 -*-
import os

basedir = u"C:/My documents/Максим/Gis-Lab/articles-projects/geosample/"
os.chdir(basedir)

layersv = ["admin","ecoregions","hydro-a","hydro-l","oopt","poi-osm","railroad-l","road-l-osm","settlements","soils","veg"]
layersr = ["relief","modis"]

#compress vector layers
for layer in layersv:
    afile = "upload/" + layer + ".7z"
    if os.path.exists(afile) == True:
        print "removing ......" + layer
        os.remove(afile)
    print "compressing ......" + layer
    os.system("C:/tools/7-Zip/7z.exe a -t7z -m0=lzma -mx=9 -mfb=64 -md=32m -ms=on upload/" + layer + ".7z shape/" + layer + "*.*")
    os.system("C:/tools/7-Zip/7z.exe u -t7z -m0=lzma -mx=9 -mfb=64 -md=32m -ms=on upload/" + layer + ".7z tab/" + layer + "*.*")
    
#compress raster layers
for layer in layersr:
    afile = "upload/" + layer + ".7z"
    if os.path.exists(afile) == True:
        print "removing ......" + layer
        os.remove(afile)
    print "compressing ......" + layer
    os.system("C:/tools/7-Zip/7z.exe a -t7z -m0=lzma -mx=9 -mfb=64 -md=32m -ms=on upload/" + layer + ".7z raster/" + layer + "*.*")
    if layer == "relief":
        command = "C:/tools/7-Zip/7z.exe u -t7z -m0=lzma -mx=9 -mfb=64 -md=32m -ms=on " + afile + " " +"raster/info"
        os.system(command)
        command = "C:/tools/7-Zip/7z.exe u -t7z -m0=lzma -mx=9 -mfb=64 -md=32m -ms=on " + afile + " " +"raster/reliefg"
        os.system(command)
        command = "C:/tools/7-Zip/7z.exe u -t7z -m0=lzma -mx=9 -mfb=64 -md=32m -ms=on " + afile + " " +"raster/reliefg-hill"
        os.system(command)
    
#make total geosample.7z
afile = "upload/geosample.7z"
if os.path.exists(afile) == True:
        print "removing ......" + layer
        os.remove(afile)
exts = "*.shp *.shx *.dbf *.tif *.wld *.jpg *.qgs *.mxd *.lyr *.prj *.sbn *.sbx *.qml *.jgw *.sqlite *.gvl *.gvp *.umap *.uprj *.avl *.apr *.wor *.tab *.img *.dat *.id *.map *.ind *.rrd *.jmp *.jml *.hgrd *.sdat *.sgrd *.sprj *.lbl *.mwsr *mwprj *.mwleg *.mwsr *.qix *.qprj *.sql *.grc *.gxw"
command = "C:/tools/7-Zip/7z.exe a -t7z -m0=lzma -mx=9 -mfb=64 -md=32m -ms=on " + afile +" grass"
os.system(command)
command = "C:/tools/7-Zip/7z.exe u -t7z -m0=lzma -mx=9 -mfb=64 -md=32m -ms=on -r " + afile + " " + exts
os.system(command)
command = "C:/tools/7-Zip/7z.exe u -t7z -m0=lzma -mx=9 -mfb=64 -md=32m -ms=on " + afile + " " +"raster/info"
os.system(command)
command = "C:/tools/7-Zip/7z.exe u -t7z -m0=lzma -mx=9 -mfb=64 -md=32m -ms=on " + afile + " " +"raster/reliefg"
os.system(command)
command = "C:/tools/7-Zip/7z.exe u -t7z -m0=lzma -mx=9 -mfb=64 -md=32m -ms=on " + afile + " " +"raster/reliefg-hill"
os.system(command)
command = "C:/tools/7-Zip/7z.exe u -t7z -m0=lzma -mx=9 -mfb=64 -md=32m -ms=on -r " + afile + " " +"geoserver/*"
os.system(command)
command = "C:/tools/7-Zip/7z.exe u -t7z -m0=lzma -mx=9 -mfb=64 -md=32m -ms=on -r " + afile + " " +"openlayers/*"
os.system(command)
command = "C:/tools/7-Zip/7z.exe u -t7z -m0=lzma -mx=9 -mfb=64 -md=32m -ms=on " + afile + " " +"screenshots"
os.system(command)
command = "C:/tools/7-Zip/7z.exe u -t7z -m0=lzma -mx=9 -mfb=64 -md=32m -ms=on " + afile +" readme"
os.system(command)

#make geosample for QGIS
afile = "upload/geosample-qgis.7z"
if os.path.exists(afile) == True:
        print "removing ......" + layer
        os.remove(afile)
exts = "*.shp *.shx shape/*.dbf *.tif *.wld *.jpg *.qgs *.prj *.qml *.jgw *.qix *.qprj"
command = "C:/tools/7-Zip/7z.exe a -t7z -m0=lzma -mx=9 -mfb=64 -md=32m -ms=on -r " + afile + " " + exts
os.system(command)
command = "C:/tools/7-Zip/7z.exe d " + afile + " geoserver"
os.system(command)
command = "C:/tools/7-Zip/7z.exe d " + afile + " geosample-grass-qgis.qgs"
os.system(command)
command = "C:/tools/7-Zip/7z.exe d " + afile + " geosample-sqlite-qgis.qgs"
os.system(command)
command = "C:/tools/7-Zip/7z.exe u -t7z -m0=lzma -mx=9 -mfb=64 -md=32m -ms=on " + afile + " " +"screenshots/geosample-qgis.png"
os.system(command)
command = "C:/tools/7-Zip/7z.exe u -t7z -m0=lzma -mx=9 -mfb=64 -md=32m -ms=on " + afile +" readme"
os.system(command)

#make geosample for Mapwindow
afile = "upload/geosample-mapwindow.7z"
if os.path.exists(afile) == True:
        print "removing ......" + layer
        os.remove(afile)
exts = "*.shp *.shx shape/*.dbf *.tif *.wld *.jpg *.prj *.qml *.jgw *.lbl *.mwsr *mwprj *.mwleg *.mwsr"
command = "C:/tools/7-Zip/7z.exe a -t7z -m0=lzma -mx=9 -mfb=64 -md=32m -ms=on -r " + afile + " " + exts
os.system(command)
command = "C:/tools/7-Zip/7z.exe d " + afile + " geoserver"
os.system(command)
command = "C:/tools/7-Zip/7z.exe u -t7z -m0=lzma -mx=9 -mfb=64 -md=32m -ms=on " + afile + " " +"screenshots/geosample-mapwindow.png"
os.system(command)
command = "C:/tools/7-Zip/7z.exe u -t7z -m0=lzma -mx=9 -mfb=64 -md=32m -ms=on " + afile +" readme"
os.system(command)

#make geosample for gvSIG
afile = "upload/geosample-gvsig.7z"
if os.path.exists(afile) == True:
        print "removing ......" + layer
        os.remove(afile)
exts = "*.shp *.shx shape/*.dbf *.tif *.wld *.jpg *.gvp *.gvl *.prj *.jgw"
command = "C:/tools/7-Zip/7z.exe a -t7z -m0=lzma -mx=9 -mfb=64 -md=32m -ms=on -r " + afile + " " + exts
os.system(command)
command = "C:/tools/7-Zip/7z.exe d " + afile + " geoserver"
os.system(command)
command = "C:/tools/7-Zip/7z.exe u -t7z -m0=lzma -mx=9 -mfb=64 -md=32m -ms=on " + afile + " " +"screenshots/geosample-gvsig.png"
os.system(command)
command = "C:/tools/7-Zip/7z.exe u -t7z -m0=lzma -mx=9 -mfb=64 -md=32m -ms=on " + afile +" readme"
os.system(command)

#make geosample for SAGA
afile = "upload/geosample-saga.7z"
if os.path.exists(afile) == True:
        print "removing ......" + layer
        os.remove(afile)
exts = "*.shp *.shx shape/*.dbf *.sprj *.hgrd *.sdat *.sgrd"
command = "C:/tools/7-Zip/7z.exe a -t7z -m0=lzma -mx=9 -mfb=64 -md=32m -ms=on -r " + afile + " " + exts
os.system(command)
command = "C:/tools/7-Zip/7z.exe d " + afile + " geoserver"
os.system(command)
command = "C:/tools/7-Zip/7z.exe u -t7z -m0=lzma -mx=9 -mfb=64 -md=32m -ms=on " + afile + " " +"screenshots/geosample-saga.png"
os.system(command)
command = "C:/tools/7-Zip/7z.exe u -t7z -m0=lzma -mx=9 -mfb=64 -md=32m -ms=on " + afile +" readme"
os.system(command)

#make geosample for openJUMP
afile = "upload/geosample-openjump.7z"
if os.path.exists(afile) == True:
        print "removing ......" + layer
        os.remove(afile)
exts = "*.shp *.shx shape/*.dbf *.tif *.wld *.jpg *.jmp *.jml *.prj *.jgw"
command = "C:/tools/7-Zip/7z.exe a -t7z -m0=lzma -mx=9 -mfb=64 -md=32m -ms=on -r " + afile + " " + exts
os.system(command)
command = "C:/tools/7-Zip/7z.exe d " + afile + " geoserver"
os.system(command)
command = "C:/tools/7-Zip/7z.exe u -t7z -m0=lzma -mx=9 -mfb=64 -md=32m -ms=on " + afile + " " +"screenshots/geosample-openjump.png"
os.system(command)
command = "C:/tools/7-Zip/7z.exe u -t7z -m0=lzma -mx=9 -mfb=64 -md=32m -ms=on " + afile +" readme"
os.system(command)

#make geosample for uDig
afile = "upload/geosample-udig.7z"
if os.path.exists(afile) == True:
        print "removing ......" + layer
        os.remove(afile)
exts = "*.shp *.shx shape/*.dbf *.tif *.wld *.jpg *.prj *.jgw *.umap *.uprj"
command = "C:/tools/7-Zip/7z.exe a -t7z -m0=lzma -mx=9 -mfb=64 -md=32m -ms=on -r " + afile + " " + exts
os.system(command)
command = "C:/tools/7-Zip/7z.exe d " + afile + " geoserver"
os.system(command)
command = "C:/tools/7-Zip/7z.exe u -t7z -m0=lzma -mx=9 -mfb=64 -md=32m -ms=on " + afile + " " +"screenshots/geosample-udig.png"
os.system(command)
command = "C:/tools/7-Zip/7z.exe u -t7z -m0=lzma -mx=9 -mfb=64 -md=32m -ms=on " + afile +" readme"
os.system(command)

#make geosample for ArcGIS
afile = "upload/geosample-arcgis.7z"
if os.path.exists(afile) == True:
        print "removing ......" + layer
        os.remove(afile)
exts = "*.shp *.shx shape/*.dbf *.tif *.wld *.jpg *.mxd *.prj *.lyr *.sbn *.sbx *.jgw"
command = "C:/tools/7-Zip/7z.exe u -t7z -m0=lzma -mx=9 -mfb=64 -md=32m -r " + afile + " " + exts
os.system(command)
command = "C:/tools/7-Zip/7z.exe d " + afile + " geoserver"
os.system(command)
command = "C:/tools/7-Zip/7z.exe u -t7z -m0=lzma -mx=9 -mfb=64 -md=32m -ms=on " + afile + " " +"screenshots/geosample-arcgis.png"
os.system(command)
command = "C:/tools/7-Zip/7z.exe u -t7z -m0=lzma -mx=9 -mfb=64 -md=32m -ms=on " + afile +" readme"
os.system(command)

#make geosample for ArcView
afile = "upload/geosample-arcview.7z"
if os.path.exists(afile) == True:
        print "removing ......" + layer
        os.remove(afile)
exts = "*.shp *.shx shape/*.dbf *.jpg *.prj *.sbn *.sbx *.avl *.apr *.abs *.jgw"
command = "C:/tools/7-Zip/7z.exe u -t7z -m0=lzma -mx=9 -mfb=64 -md=32m -ms=on -r " + afile + " " + exts
os.system(command)
command = "C:/tools/7-Zip/7z.exe u -t7z -m0=lzma -mx=9 -mfb=64 -md=32m -ms=on -r " + afile + " " +"raster/info"
os.system(command)
command = "C:/tools/7-Zip/7z.exe u -t7z -m0=lzma -mx=9 -mfb=64 -md=32m -ms=on -r " + afile + " " +"raster/reliefg"
os.system(command)
command = "C:/tools/7-Zip/7z.exe u -t7z -m0=lzma -mx=9 -mfb=64 -md=32m -ms=on -r " + afile + " " +"raster/reliefg-hill"
os.system(command)
command = "C:/tools/7-Zip/7z.exe d " + afile + " geoserver"
os.system(command)
command = "C:/tools/7-Zip/7z.exe u -t7z -m0=lzma -mx=9 -mfb=64 -md=32m -ms=on " + afile + " " +"screenshots/geosample-arcview.png"
os.system(command)
command = "C:/tools/7-Zip/7z.exe u -t7z -m0=lzma -mx=9 -mfb=64 -md=32m -ms=on " + afile +" readme"
os.system(command)

#make geosample for SQLite
afile = "upload/geosample-sqlite.7z"
if os.path.exists(afile) == True:
        print "removing ......" + layer
        os.remove(afile)
exts = "geosample.sqlite *sqlite*.qgs *.tif *.wld *.jpg *.prj *.jgw"
command = "C:/tools/7-Zip/7z.exe a -t7z -m0=lzma -mx=9 -mfb=64 -md=32m -ms=on -r " + afile + " " + exts
os.system(command)
command = "C:/tools/7-Zip/7z.exe d " + afile + " geoserver"
os.system(command)
command = "C:/tools/7-Zip/7z.exe d " + afile + " shape"
os.system(command)
command = "C:/tools/7-Zip/7z.exe u -t7z -m0=lzma -mx=9 -mfb=64 -md=32m -ms=on " + afile +" readme"
os.system(command)

#make geosample for PostGIS
afile = "upload/geosample-postgis.7z"
if os.path.exists(afile) == True:
        print "removing ......" + layer
        os.remove(afile)
exts = "*.sql"
command = "C:/tools/7-Zip/7z.exe a -t7z -m0=lzma -mx=9 -mfb=64 -md=32m -ms=on -r " + afile + " " + exts
os.system(command)
command = "C:/tools/7-Zip/7z.exe d " + afile + " geoserver"
os.system(command)
command = "C:/tools/7-Zip/7z.exe d " + afile + " shape"
os.system(command)
command = "C:/tools/7-Zip/7z.exe u -t7z -m0=lzma -mx=9 -mfb=64 -md=32m -ms=on " + afile +" readme"
os.system(command)

#make geosample for SpatiaLite GIS
afile = "upload/geosample-spatialite-gis.7z"
if os.path.exists(afile) == True:
        print "removing ......" + layer
        os.remove(afile)
exts = "geosample-spatialite-gis.sqlite"
command = "C:/tools/7-Zip/7z.exe a -t7z -m0=lzma -mx=9 -mfb=64 -md=32m -ms=on -r " + afile + " " + exts
os.system(command)
command = "C:/tools/7-Zip/7z.exe u -t7z -m0=lzma -mx=9 -mfb=64 -md=32m -ms=on " + afile + " " +"screenshots/geosample-spatialite-gis.png"
os.system(command)
command = "C:/tools/7-Zip/7z.exe u -t7z -m0=lzma -mx=9 -mfb=64 -md=32m -ms=on " + afile +" readme"
os.system(command)

#make geosample for GRASS
afile = "upload/geosample-grass.7z"
if os.path.exists(afile) == True:
        print "removing ......" + layer
        os.remove(afile)
command = "C:/tools/7-Zip/7z.exe a -t7z -m0=lzma -mx=9 -mfb=64 -md=32m -ms=on -r " + afile + " grass/*"
os.system(command)
command = "C:/tools/7-Zip/7z.exe u -t7z -m0=lzma -mx=9 -mfb=64 -md=32m -ms=on " + afile + " " +"geosample-grass-qgis.qgs"
os.system(command)
command = "C:/tools/7-Zip/7z.exe u -t7z -m0=lzma -mx=9 -mfb=64 -md=32m -ms=on " + afile + " " +"geosample-grass-tcltk.grc"
os.system(command)
command = "C:/tools/7-Zip/7z.exe u -t7z -m0=lzma -mx=9 -mfb=64 -md=32m -ms=on " + afile + " " +"geosample-grass-wxpython.gxw"
os.system(command)
command = "C:/tools/7-Zip/7z.exe u -t7z -m0=lzma -mx=9 -mfb=64 -md=32m -ms=on " + afile + " " +"screenshots/geosample-grass*"
os.system(command)
command = "C:/tools/7-Zip/7z.exe u -t7z -m0=lzma -mx=9 -mfb=64 -md=32m -ms=on " + afile +" readme"
os.system(command)

#make geosample for OpenLayers
afile = "upload/geosample-openlayers.7z"
if os.path.exists(afile) == True:
        print "removing ......" + layer
        os.remove(afile)
command = "C:/tools/7-Zip/7z.exe a -t7z -m0=lzma -mx=9 -mfb=64 -md=32m -ms=on -r " + afile + " openlayers/*"
os.system(command)
command = "C:/tools/7-Zip/7z.exe u -t7z -m0=lzma -mx=9 -mfb=64 -md=32m -ms=on " + afile + " " +"screenshots/geosample-ol.png"
os.system(command)
command = "C:/tools/7-Zip/7z.exe u -t7z -m0=lzma -mx=9 -mfb=64 -md=32m -ms=on " + afile +" readme"
os.system(command)

#make geosample for Mapinfo
afile = "upload/geosample-mapinfo.7z"
if os.path.exists(afile) == True:
        print "removing ......" + layer
        os.remove(afile)
command = "C:/tools/7-Zip/7z.exe a -t7z -m0=lzma -mx=9 -mfb=64 -md=32m -ms=on -r " + afile + " tab"
os.system(command)
exts = "raster/*.tif raster/*.wld raster/*.jpg raster/*.jgw raster/*.prj raster/*.tab raster/*.img"
command = "C:/tools/7-Zip/7z.exe u -t7z -m0=lzma -mx=9 -mfb=64 -md=32m -ms=on " + afile + " " + exts
os.system(command)
command = "C:/tools/7-Zip/7z.exe u -t7z -m0=lzma -mx=9 -mfb=64 -md=32m -ms=on " + afile + " " +"geosample-mapinfo.wor"
os.system(command)
command = "C:/tools/7-Zip/7z.exe u -t7z -m0=lzma -mx=9 -mfb=64 -md=32m -ms=on " + afile + " " +"screenshots/geosample-mapinfo.png"
os.system(command)
command = "C:/tools/7-Zip/7z.exe u -t7z -m0=lzma -mx=9 -mfb=64 -md=32m -ms=on " + afile +" readme"
os.system(command)

#make geosample for Geoserver
afile = "upload/geosample-geoserver.7z"
if os.path.exists(afile) == True:
        print "removing ......" + layer
        os.remove(afile)
command = "C:/tools/7-Zip/7z.exe a -t7z -m0=lzma -mx=9 -mfb=64 -md=32m -ms=on -r " + afile + " geoserver"
os.system(command)
command = "C:/tools/7-Zip/7z.exe u -t7z -m0=lzma -mx=9 -mfb=64 -md=32m -ms=on " + afile +" readme"
os.system(command)