#!/usr/bin/env python
'''Install P4V addins'''
# Copyright (c) 2006 Qualcomm
# Miki Tebeka <mtebeka@qualcomm.com>
from re import match
from user import home
from os.path import join, isfile, dirname, isdir
from sys import stdout, path, platform
from urllib import quote, unquote
from shutil import copy2
from os import mkdir, popen
from glob import glob
# Configuration file specifying the addins
CONFIG_FILE = "install.cfg"
# Application directory
APPDIR = path[0]
if isfile(APPDIR): # py2exe
APPDIR = dirname(APPDIR)
if platform == "win32":
from win32pdh import EnumObjectItems, PERF_DETAIL_WIZARD
def is_process_running(process_name):
'''Check if process is running'''
junk, names = EnumObjectItems(None, None, "Process", PERF_DETAIL_WIZARD)
return process_name.lower() in [name.lower() for name in names]
elif platform == "cygwin":
def is_process_running(process_name):
for line in popen("ps -W"):
if process_name.lower() in line.lower():
return 1
return 0
else:
raise SystemExit("error: unsupported platform - %s" % platform)
# General install error
class InstallError(Exception):
pass
def config_file():
'''Name of configuration file'''
return join(APPDIR, CONFIG_FILE)
_DEFAULTS = {
"name" : "",
"command" : "",
"arguments" : "",
"directory" : "",
"prompttext" : "",
"console" : "no",
"prompt" : "no",
"closeOnExit" : "no",
"subMenu" : "no",
"showBrowse" : "no",
"addToContext" : "yes",
"refresh" : "no"
}
_BOOL_OPTS = set([
"console"
"prompt"
"closeOnExit"
"subMenu"
"showBrowse",
"addToContext"
"refresh"
])
def is_boolean(optname):
return optname in _BOOL_OPTS
def load_config():
'''Load addins config file'''
addin_list = []
def CustomTool(**kw):
addin = _DEFAULTS.copy()
addin.update(kw)
if not addin["name"]:
raise InstallError("Custom tool without a name")
if not addin["command"]:
raise InstallError("Custom tool %s don't have a command" % \
addin["name"])
for opt in addin.keys():
if not is_boolean(opt):
continue
if addin[opt] not in ("yes", "no"):
raise InstallError(
"Bad value for %s in %s (can be \"yes\" or \"no\"" % \
(opt, addin["name"]))
addin_list.append(addin)
env = {"CustomTool" : CustomTool}
try:
execfile(config_file(), env, env)
except Exception, e:
raise InstallError(e)
return addin_list