Skip to content

Commit

Permalink
add a skeleton for package with some potential hooks
Browse files Browse the repository at this point in the history
load guihelper only if stdin is not the standard one
  • Loading branch information
htouvet committed Dec 22, 2017
1 parent 310f783 commit bc2d4db
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 33 deletions.
49 changes: 32 additions & 17 deletions common.py
Original file line number Diff line number Diff line change
Expand Up @@ -5188,7 +5188,7 @@ def uninstall(self,packagename,params_dict={}):
logger.debug(u' Change current directory to %s' % previous_cwd)
os.chdir(previous_cwd)

def make_package_template(self,installer_path,packagename='',directoryname='',section='',description=None,depends='',version=None,silentflags=None,uninstallkey=None):
def make_package_template(self,installer_path='',packagename='',directoryname='',section='',description=None,depends='',version=None,silentflags=None,uninstallkey=None):
r"""Build a skeleton of WAPT package based on the properties of the supplied installer
Return the path of the skeleton
>>> wapt = Wapt(config_filename='c:/wapt/wapt-get.ini')
Expand All @@ -5211,21 +5211,24 @@ def make_package_template(self,installer_path,packagename='',directoryname='',se
if directoryname:
directoryname = os.path.abspath(directoryname)

installer = os.path.basename(installer_path)
uninstallkey = uninstallkey or ''
if not installer_path and not packagename:
raise EWaptException('You must provide at least installer_path or packagename to be able to prepare a package template')

## TODO : use get_installer_defaults
if installer_path:
installer = os.path.basename(installer_path)
else:
installer = ''

uninstallkey = uninstallkey or ''

if not os.path.exists(installer_path):
raise Exception('The parameter "%s" is neither a file or a directory, it must be the path to a directory, or an .exe or .msi installer' % installer_path)
if os.path.isfile(installer_path):
# case of an installer
props = setuphelpers.getproductprops(installer_path)
silentflags = silentflags or setuphelpers.getsilentflags(installer_path)
# for MSI, uninstallkey is in properties
if not uninstallkey and 'ProductCode' in props:
uninstallkey = '"%s"' % props['ProductCode']
else:
elif os.path.isdir(installer_path):
# case of a directory
props = {
'product':installer,
Expand All @@ -5234,12 +5237,21 @@ def make_package_template(self,installer_path,packagename='',directoryname='',se
'publisher':ensure_unicode(setuphelpers.get_current_user())
}
silentflags = silentflags or ''
else:
# case of a nothing
props = {
'product':packagename,
'description':packagename,
'version': '0',
'publisher':ensure_unicode(setuphelpers.get_current_user())
}
silentflags = ''

if not packagename:
simplename = re.sub(r'[\s\(\)]+','',props['product'].lower())
packagename = '%s-%s' % (self.config.get('global','default_package_prefix'),simplename)

description = description or 'Automatic package for %s ' % props['description']
description = description or 'Package for %s ' % props['description']
version = version or props['version']

if not directoryname:
Expand All @@ -5248,15 +5260,18 @@ def make_package_template(self,installer_path,packagename='',directoryname='',se
if not os.path.isdir(os.path.join(directoryname,'WAPT')):
os.makedirs(os.path.join(directoryname,'WAPT'))

(installer_name,installer_ext) = os.path.splitext(installer)
if installer_ext == '.msi':
setup_template = os.path.join(self.wapt_base_dir,'templates','setup_package_template_msi.py')
elif installer_ext == '.msu':
setup_template = os.path.join(self.wapt_base_dir,'templates','setup_package_template_msu.py')
elif installer_ext == '.exe':
setup_template = os.path.join(self.wapt_base_dir,'templates','setup_package_template_exe.py')
if installer_path:
(installer_name,installer_ext) = os.path.splitext(installer)
if installer_ext == '.msi':
setup_template = os.path.join(self.wapt_base_dir,'templates','setup_package_template_msi.py')
elif installer_ext == '.msu':
setup_template = os.path.join(self.wapt_base_dir,'templates','setup_package_template_msu.py')
elif installer_ext == '.exe':
setup_template = os.path.join(self.wapt_base_dir,'templates','setup_package_template_exe.py')
else:
setup_template = os.path.join(self.wapt_base_dir,'templates','setup_package_template.py')
else:
setup_template = os.path.join(self.wapt_base_dir,'templates','setup_package_template.py')
setup_template = os.path.join(self.wapt_base_dir,'templates','setup_package_skel.py')

template = codecs.open(setup_template,encoding='utf8').read()%dict(
packagename=packagename,
Expand All @@ -5275,7 +5290,7 @@ def make_package_template(self,installer_path,packagename='',directoryname='',se
logger.debug(u'Copy installer %s to target' % installer)
if os.path.isfile(installer_path):
shutil.copyfile(installer_path,os.path.join(directoryname,installer))
else:
elif os.path.isdir(installer_path):
setuphelpers.copytree2(installer_path,os.path.join(directoryname,installer))

control_filename = os.path.join(directoryname,'WAPT','control')
Expand Down
30 changes: 30 additions & 0 deletions templates/setup_package_skel.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# -*- coding: utf-8 -*-
from setuphelpers import *

uninstallkey = []

def install():
print('installing %(packagename)s')
# put here what to do when package is installed on host
# implicit context variables are WAPT, basedir, control, user, params, run

def uninstall():
print('uninstalling %(packagename)s')
# put here what to do when package is removed from host
# implicit context variables are WAPT, control, user, params, run

def session_setup():
print('Session setup for %(packagename)s')
# put here what to do when package is configured inside a user session
# implicit context variables are WAPT, control, user, params

def update_package():
print('Update package content from upstream binary sources')
# put here what to do to update package content with newer installers.
# launched with command wapt-get update-package-sources <path-to-wapt-directory>
# implicit context variables are WAPT, basedir, control, user, params, run
# if attributes in control are changed, they should be explicitly saved to package file with control.save_control_to_wapt()

if __name__ == '__main__':
update_package()

16 changes: 8 additions & 8 deletions templates/wapt.psproj
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ Name=install
ScriptName=%(wapt_base_dir)s\wapt-get.py
EngineType=peRemote
ReinitializeBeforeRun=TRUE
Parameters=-ldebug install "$[ActiveDoc-Dir]"
Parameters=install "$[ActiveDoc-Dir]"
WorkingDir=$[ActiveScript-Dir]
WriteOutputToFile=FALSE
OutputFileName=$[ActiveScript-NoExt].log
Expand All @@ -81,7 +81,7 @@ Name=remove
ScriptName=%(wapt_base_dir)s\wapt-get.py
EngineType=peRemote
ReinitializeBeforeRun=TRUE
Parameters=-ldebug remove "$[ActiveDoc-Dir]"
Parameters=remove "$[ActiveDoc-Dir]"
WorkingDir=$[ActiveScript-Dir]
WriteOutputToFile=FALSE
OutputFileName=$[ActiveScript-NoExt].log
Expand All @@ -104,7 +104,7 @@ Name=session-setup
ScriptName=%(wapt_base_dir)s\wapt-get.py
EngineType=peRemote
ReinitializeBeforeRun=TRUE
Parameters=-ldebug session-setup "$[ActiveDoc-Dir]"
Parameters=session-setup "$[ActiveDoc-Dir]"
WorkingDir=$[ActiveScript-Dir]
WriteOutputToFile=FALSE
OutputFileName=$[ActiveScript-NoExt].log
Expand All @@ -127,7 +127,7 @@ Name=update
ScriptName=%(wapt_base_dir)s\wapt-get.py
EngineType=peRemote
ReinitializeBeforeRun=TRUE
Parameters=-ldebug update
Parameters=update
WorkingDir=$[ActiveScript-Dir]
WriteOutputToFile=FALSE
OutputFileName=$[ActiveScript-NoExt].log
Expand All @@ -150,7 +150,7 @@ Name=upgrade
ScriptName=%(wapt_base_dir)s\wapt-get.py
EngineType=peRemote
ReinitializeBeforeRun=TRUE
Parameters=-f -ldebug upgrade
Parameters=-f upgrade
WorkingDir=$[ActiveScript-Dir]
WriteOutputToFile=FALSE
OutputFileName=$[ActiveScript-NoExt].log
Expand All @@ -173,7 +173,7 @@ Name=-i build-upload
ScriptName=%(wapt_base_dir)s\wapt-get.py
EngineType=peRemote
ReinitializeBeforeRun=TRUE
Parameters=-ldebug -i build-upload "$[ActiveDoc-Dir]"
Parameters=-i build-upload "$[ActiveDoc-Dir]"
WorkingDir=$[ActiveScript-Dir]
WriteOutputToFile=FALSE
OutputFileName=$[ActiveScript-NoExt].log
Expand All @@ -196,7 +196,7 @@ Name=svn update
ScriptName=%(wapt_base_dir)s\wapt-get.py
EngineType=peRemote
ReinitializeBeforeRun=TRUE
Parameters=-ldebug sources "$[ActiveDoc-Dir]"
Parameters=sources "$[ActiveDoc-Dir]"
WorkingDir=$[ActiveScript-Dir]
WriteOutputToFile=FALSE
OutputFileName=$[ActiveScript-NoExt].log
Expand All @@ -219,7 +219,7 @@ Name=uninstall
ScriptName=%(wapt_base_dir)s\wapt-get.py
EngineType=peRemote
ReinitializeBeforeRun=TRUE
Parameters=-ldebug uninstall "$[ActiveDoc-Dir]"
Parameters=uninstall "$[ActiveDoc-Dir]"
WorkingDir=$[ActiveScript-Dir]
WriteOutputToFile=FALSE
OutputFileName=$[ActiveScript-NoExt].log
Expand Down
32 changes: 24 additions & 8 deletions wapt-get.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,10 +277,11 @@ def ask_user_password(title=''):

# import after parsing line command, as import when debugging seems to break command line
# because if rpyc
try:
import waptguihelper
except ImportError:
waptguihelper = None
if sys.stdin is not sys.__stdin__:
try:
import waptguihelper
except ImportError:
waptguihelper = None

def main():
jsonresult = {'output':[]}
Expand Down Expand Up @@ -356,7 +357,7 @@ def get_private_key_passwd(*args):
return open(options.private_key_passwd,'r').read().splitlines()[0].strip()
else:
if private_key_password_cache is None:
if waptguihelper:
if sys.stdin is not sys.__stdin__ and waptguihelper:
res = waptguihelper.key_password_dialog('Password for orivate key',mywapt.personal_certificate_path,private_key_password_cache or '')
if res:
private_key_password_cache = res['keypassword']
Expand Down Expand Up @@ -747,13 +748,28 @@ def get_private_key_passwd(*args):
if len(args) < 2:
print(u"You must provide the package directory")
sys.exit(1)
print mywapt.call_setup_hook(args[1],'update_package')
result= []
for package_dir in args[1:]:
is_updated = mywapt.call_setup_hook(package_dir,'update_package')
if is_updated:
result.append(package_dir)
if options.json_output:
jsonresult['result'] = result
else:
print(u"Packages updated :\n%s" % ' '.join(result))


elif action == 'make-template':
if len(args) < 2:
print(u"You must provide the installer path")
print(u"You must provide the installer path or the package name")
sys.exit(1)
result = mywapt.make_package_template(*args[1:])

if os.path.isfile(args[1]) or os.path.isdir(args[1]):
result = mywapt.make_package_template(*args[1:])
else:
# no installer provided, only package name.
result = mywapt.make_package_template('',*args[1:])

if options.json_output:
jsonresult['result'] = result
else:
Expand Down

0 comments on commit bc2d4db

Please sign in to comment.