#!/usr/bin/env python
#-*- coding: UTF-8 -*-
 
import sys
import wx
import os
import os.path
from   time import strftime

LINUX = sys.platform.startswith('linux')
if LINUX:
    import pwd
    USER = pwd.getpwuid(os.getuid())[0]
else:
    import getpass
    USER = getpass.getuser()    
TITLE = 'StoreMan'
VERNUM = '1.34'
RELEASEDATE = '2011-02-18'
IMAGEDIR = TITLE.lower() + 'images'
APPICON = TITLE.lower() + '.ico'
HOMEDIR = os.path.expanduser("~")
APPPATH = os.path.dirname(sys.argv[0])
ICONPATH = os.path.join(APPPATH, IMAGEDIR)
VERSION = '%s - Version %s (%s)' % (TITLE, VERNUM, USER)
URL_DOWNLOAD_LIST = 'http://code.google.com/p/wx-storeman/downloads/list'
URL_DOWNLOAD_FILES = 'http://wx-storeman.googlecode.com/files'
URL_WEBSITE = 'http://www.ewetel.net/~frank.mersmann/'

RED = wx.Colour(255, 0, 0)                       # Error, no db connection
GREEN = wx.Colour(0, 255, 0)                     # ready
BLUE = wx.Colour(0, 0, 255)                      # scan dir to db
YELLOW = wx.Colour(255, 180, 0)                  # query is executing
LBLUE = wx.Colour(66, 199, 243)                  # task is running
LRED = wx.Colour(246, 144, 162)                  # displimit reached
GREY = wx.Colour(127, 127, 127)
BLACK = (0, 0, 0)
READONLY_COLOR = wx.SYS_COLOUR_INACTIVECAPTION

if "wxMSW" in wx.PlatformInfo:
    SCALE = 16
    PSTRING = 'wxMSW'
elif "wxGTK" in wx.PlatformInfo:
    SCALE = 22
    PSTRING = 'wxGTK'
else:
    SCALE = 48
    PSTRING = ''
    
PYVERSION = 'running on Python - Version ' + sys.version.split()[0]
WXVERSION = 'using wxPython - Version ' + wx.VERSION_STRING
PLATFORMINFO = 'wx Platform Info - %s' % PSTRING

BORDER = 10
GAP = 5
LRT = wx.LEFT | wx.RIGHT | wx.TOP

JOB_TIME_SLICE = 30000
ACTION_LOG_SIZE =  64 * 1024
BACKUP_LOG_SIZE = 512 * 1024


def searchFile(filename, search_path):
    """Given a search path, find file
    """
    file_found = False
    paths = search_path.split(os.pathsep)
    for path in paths:
        if os.path.exists(os.path.join(path, filename)):
            file_found = True
            break
    return file_found
#-------------------------------------------------------------------------------------------

def loadIcon(iconname):
    """ small helper function to load icons """
    try:
        bitmap = wx.Bitmap('%s%s%s' % (ICONPATH, os.sep, iconname))
    except:
        bitmap = wx.NullBitmap
    return bitmap
#-------------------------------------------------------------------------------------------

def format3P(vs):                       # Werte wie '12765' in '12.765' formatieren
    vs = str(vs)
    dotpos = len(vs)

    while dotpos > 3:                   # alle 3 Stellen ein '.'
        dotpos -= 3
        vs = '%s.%s' % (vs[0:dotpos], vs[dotpos:])
    return vs
#-------------------------------------------------------------------------------------------

def initJobExample():
    return {'Example': {'immediate':  'False',
                        'background': 'False',
                        'running':    'False',
                        'lastrun':    '2000-01-01 00:00',
                        'nextrun':    strftime('%Y-%m-%d %H:%M'),
                        'delayed':    'False',
                        'interval':   '0',
                        'taskcount':  '0',
                        'tasklist':   [],
                        }
           }
#-------------------------------------------------------------------------------------------
            
def initTaskExample():
    return {'Example': {'sourcepath': os.path.normpath(HOMEDIR),
                        'targetpath': os.path.normpath(HOMEDIR),
                        'subinclude': 'True',
                        'override':   'False',
                        'comprmeth':  'tar.gz',
                        'timestamp':  'True',
                        'tsappend':   'True',
                        'exclude':    ['(.*)~$'],
                        'lastrun':    '2000-01-01 00:00'
                        }
           }
#-------------------------------------------------------------------------------------------

        
        