def log_external(message, errcode=1001, module='', autostart=True): ''' Writes a custom message to the Scala log and Content Manager Player Health Screen. Tries Player interface, then InfoNetwork. Arguments: message The message to log. Options: errcode Error code, see notes below. module The name of the source of the message. autostart If using InfoNetwork, whether to start service. Notes: https://license.scala.com/readme/ScriptingAutomation.html#toc_CustomProblems ''' import pythoncom global _player if not _player: _player = COMObject(_player_name) try: _player.LogExternalError(errcode, module, message) except UnicodeError: _player.LogExternalError(errcode, module, message.encode('UTF-8')) except pythoncom.com_error, err: # do not log this; creates a loop. print 'COM Error: %s' % err global _netic if autostart: from scalatools import start_svc start_svc(_netic_svc) # don't cache netic, it doesn't work more than once :/ _netic = COMObject(_netic_name) try: _netic.LogExternalError(errcode, module, message) except pythoncom.com_error: pass except UnicodeError: _netic.LogExternalError(errcode, module, message.encode('UTF-8'))
def install_content(abspath, subfolder='', autostart=True): r''' Copies a file to the local Scala Content: folder. Argument: abspath - A file (specified by its absolute path) to copy. Options: subfolder - Place it into a subfolder to group related files. autostart - Start the Transmission Client service if necessary. Notes: Installed files may be found later using a Scala-style virtual path string, passed to lock_content, e.g.: lock_content(r'Content:\filename.ext') ''' import pythoncom global _netic if not os.path.exists(abspath): raise IOError, 'File "%s" does not exist.' % abspath if autostart: from scalatools import start_svc start_svc(_netic_svc) try: # don't cache netic, it doesn't work more than once # if not _netic: _netic = COMObject(_netic_name) _netic.IntegrateContentLocally(abspath, subfolder) _log.info(abspath) except pythoncom.com_error, err: errstr = '%s\n\nPlayer Transmission Client (%s) not available.' % ( str(err), _netic_name) _log.error(errstr.replace('\n', ' ')) raise _ObjectNotAvailable, errstr
def install_content(abspath, subfolder='', autostart=True): r''' Copies a file to the local Scala Content: folder. Argument: abspath - A file (specified by its absolute path) to copy. Options: subfolder - Place it into a subfolder to group related files. autostart - Start the Transmission Client service if necessary. Notes: Installed files may be found later using a Scala-style virtual path string, passed to lock_content, e.g.: lock_content(r'Content:\filename.ext') ''' import pythoncom global _netic if not os.path.exists(abspath): raise IOError, 'File "%s" does not exist.' % abspath if autostart: from scalatools import start_svc start_svc(_netic_svc) try: # don't cache netic, it doesn't work more than once # if not _netic: _netic = COMObject(_netic_name) _netic.IntegrateContentLocally(abspath, subfolder) _log.info(abspath) except pythoncom.com_error, err: errstr = '%s\n\nPlayer Transmission Client (%s) not available.' % ( str(err), _netic_name) _log.error( errstr.replace('\n', ' ') ) raise _ObjectNotAvailable, errstr
def check_plan(autostart=True): ''' Ask the Transmission Client to check for a new plan.xml file. Options: autostart - Start the Transmission Client service if needed. ''' import pythoncom global _netic if autostart: from scalatools import start_svc start_svc(_netic_svc) try: # don't cache netic, it doesn't work more than once # if not _netic: _netic = COMObject(_netic_name) _netic.CheckPlanNow() _log.info('called.') except pythoncom.com_error, err: errstr = '%s\n\nPlayer Transmission Client (%s) not available.' % ( str(err), _netic_name) _log.error(errstr.replace('\n', ' ')) raise _ObjectNotAvailable, errstr
def check_plan(autostart=True): ''' Ask the Transmission Client to check for a new plan.xml file. Options: autostart - Start the Transmission Client service if needed. ''' import pythoncom global _netic if autostart: from scalatools import start_svc start_svc(_netic_svc) try: # don't cache netic, it doesn't work more than once # if not _netic: _netic = COMObject(_netic_name) _netic.CheckPlanNow() _log.info('called.') except pythoncom.com_error, err: errstr = '%s\n\nPlayer Transmission Client (%s) not available.' % ( str(err), _netic_name) _log.error( errstr.replace('\n', ' ') ) raise _ObjectNotAvailable, errstr
def thumbnail_gen(scriptpath, filename, width=96, height=96, options='', pagename='', xmltext='', autostart=True, **templ_args): r''' Generates thumbnails of Scala Scripts/Templates. Requires the Scala Server Support Service from Content Manager. Arguments: scriptpath - The full path to the Scala Script. filename - Full path to desired image (.jpg, .jpeg, .png) width - Thumbnail width in pixels height - Thumbnail height in pixels options - A string that can contain one of these flags: - 'rl': Rotate 90 degrees left - 'rr': Rotate 90 degrees right - 'ru': Rotate 180 degrees (upside down) - 'k': Keep aspect pagename - Name of the page to generate, defaults to first. Ignored when scriptpath points to a template. xmltext - An XML snippet that defines template fields, e.g: <ingredients> <text name="Headline">Breaking News</text> <boolean name="Enabled">On</boolean> <integer name="age">123</integer> <real name="price">1.23</real> <filename name="Logo">C:\logo.png</filename> </ingredients> templ_args - Alternately, additional keyword args passed will create xmltext automatically; type is inferred. eg. (Enabled=True, Logo=r'c:\logo.png') autostart - Start the Server Support service if necessary. Returns: numthumbs - The number of thumbnails created, as there may be more than one page in a script. Example: from scalalib import thumbnail_gen thumbnail_gen('d:\\tmpl.sca', 'd:\\thbn.jpg', 96, 96, options='k', tmpl_CityName='Kathmandu', tmpl_Greeting='d:\\Namaste.jpg') ''' import pythoncom global _thumbnl if autostart: from scalatools import start_svc start_svc(_thumb_svc) try: if not _thumbnl: # initialize vars _thumbnl = COMObject(_thumbnl_name) errmsgs = None numthumbs = 1 if templ_args: xmltext = '<ingredients>\n' for name, value in templ_args.items(): if type(value) is bool: vartype = 'boolean' if value: value = 'On' else: value = 'Off' elif type(value) is int: vartype = 'integer' elif type(value) is float: vartype = 'real' elif type(value) is str or type(value) is unicode: if (len(value) > 3 and value[1] == ':' and '\\' in value): vartype = 'filename' else: vartype = 'text' else: raise 'error: gen_thumbs - unknown type passed.' xmltext += ' <%s name="%s">%s</%s>\n' % (vartype, name, value, vartype) xmltext += '</ingredients>\n' _log.debug('xmltext generated: %r' % xmltext) if xmltext: _thumbnl.GeneratePreviewThumbnails(scriptpath, xmltext, filename, width, height, options, numthumbs, errmsgs) else: _thumbnl.GenerateThumbnail(scriptpath, pagename, filename, width, height, options, errmsgs) _log.info('Generated %s thumbnail(s) of "%s".' % (numthumbs, scriptpath)) if errmsgs: _log.warn(errmsgs) return numthumbs except pythoncom.com_error, err: _log.error('%s: %s' % (err, _thumbnl_name)) raise err
def publish(scriptlist, targeturl, targetfolder='', logfilename='', editpassword='', options='', autostart=True): r''' Performs the equivalent of the Publish to Network function of Scala Designer5. Requires the Scala Publish Automation EX Module5 which is an additional software component that is installed seperately. Arguments: scriptlist - A string containing the absolute paths of one or more script files to publish, one per line, or alternately, a python list of them. targeturl - Publish location path/URL with username and passwd. Examples: - UNC: \\server\share\folder - FTP URL: ftp://user:pass@host[:port]/folder/ - HTTP/s Content Manager URL: http://user:pass@host[:port]/folder?netname targetfolder - Sub-folder into which to publish logfilename - Absolute path to a log file to report progress, otherwise to: "%TEMP%\pub_log.txt". editpassword - Optional password to apply to published script(s). options - A string containing zero or more of these flags: - 'd': Show progress GUI. - 'i': Ignore errors. - 'f': Do NOT include fonts. - 'w': Do NOT include wipes. - 'x': Skip cleanup. - 'p': Use passive FTP. autostart - Start the Publisher service if necessary. Returns: handle - A unique handle for use with publish_check(). Example: # See the sca_publisher.py script for a general solution. import time, glob, scalalib as sl targeturl = 'http://*****:*****@mycm.com:8080/ContentManager?MyCo' scripts = glob.glob('*.sca') pubhandle = sl.publish(scripts, targeturl, options='d') while True: time.sleep(3) status = sl.publish_check(pubhandle) statstr = ('Publishing script %(currentscriptnum)s of %(numberofscripts)s' + ' - %(overallpercentdone)3.3s%% complete, %(currentscriptname)s ') print statstr % status if status.get('overallpercentdone') == 100: break ''' import pythoncom global _publshr if autostart: from scalatools import start_svc start_svc(_pub_svc) # massage parameters to make sure paths are absolute if type(scriptlist) is list: scriptlist = [os.path.abspath(x) for x in scriptlist] scriptlist = '\n'.join(scriptlist) elif type(scriptlist) is str: scriptlist = os.path.abspath(scriptlist) if not logfilename: logfilename = os.path.join(os.environ['TEMP'], 'pub_log.txt') else: logfilename = os.path.abspath(logfilename) local_opts = locals() # log parameters try: if not _publshr: _publshr = COMObject(_publshr_name) pubhandle = None _log.debug('options: %s' % local_opts) try: censoredurl = targeturl # censor url if needed. if (targeturl.lower().startswith('http') or targeturl.lower().startswith('ftp')): censoredurl = targeturl.split('//', 1) censoredurl = '%s%s%s%s' % (censoredurl[0], '//', 'xxx:xxx@', censoredurl[1].split('@', 1)[1]) _log.info('publishing to %s' % censoredurl) except IndexError: _log.info('publishing to %s' % targeturl) if targetfolder: pubhandle = _publshr.GoPublishFolder(scriptlist, targeturl, targetfolder, logfilename, editpassword, options) else: pubhandle = _publshr.GoPublish(scriptlist, targeturl, logfilename, editpassword, options) if pubhandle == None: _log.warn( 'Publish operation returned None. Is the dongle present?') return pubhandle except pythoncom.com_error, err: errstr = ( '%s: %s services not available. Is it installed, running, ' + 'and not disabled?') % (err.__class__.__name__, _publshr_name) _log.critical(errstr) raise err
def thumbnail_gen(scriptpath, filename, width=96, height=96, options='', pagename='', xmltext='', autostart=True, **templ_args): r''' Generates thumbnails of Scala Scripts/Templates. Requires the Scala Server Support Service from Content Manager. Arguments: scriptpath - The full path to the Scala Script. filename - Full path to desired image (.jpg, .jpeg, .png) width - Thumbnail width in pixels height - Thumbnail height in pixels options - A string that can contain one of these flags: - 'rl': Rotate 90 degrees left - 'rr': Rotate 90 degrees right - 'ru': Rotate 180 degrees (upside down) - 'k': Keep aspect pagename - Name of the page to generate, defaults to first. Ignored when scriptpath points to a template. xmltext - An XML snippet that defines template fields, e.g: <ingredients> <text name="Headline">Breaking News</text> <boolean name="Enabled">On</boolean> <integer name="age">123</integer> <real name="price">1.23</real> <filename name="Logo">C:\logo.png</filename> </ingredients> templ_args - Alternately, additional keyword args passed will create xmltext automatically; type is inferred. eg. (Enabled=True, Logo=r'c:\logo.png') autostart - Start the Server Support service if necessary. Returns: numthumbs - The number of thumbnails created, as there may be more than one page in a script. Example: from scalalib import thumbnail_gen thumbnail_gen('d:\\tmpl.sca', 'd:\\thbn.jpg', 96, 96, options='k', tmpl_CityName='Kathmandu', tmpl_Greeting='d:\\Namaste.jpg') ''' import pythoncom global _thumbnl if autostart: from scalatools import start_svc start_svc(_thumb_svc) try: if not _thumbnl: # initialize vars _thumbnl = COMObject(_thumbnl_name) errmsgs = None numthumbs = 1 if templ_args: xmltext = '<ingredients>\n' for name,value in templ_args.items(): if type(value) is bool: vartype = 'boolean' if value: value = 'On' else: value = 'Off' elif type(value) is int: vartype = 'integer' elif type(value) is float: vartype = 'real' elif type(value) is str or type(value) is unicode: if (len(value) > 3 and value[1] == ':' and '\\' in value): vartype = 'filename' else: vartype = 'text' else: raise 'error: gen_thumbs - unknown type passed.' xmltext += ' <%s name="%s">%s</%s>\n' % ( vartype, name, value, vartype) xmltext += '</ingredients>\n' _log.debug('xmltext generated: %r' % xmltext ) if xmltext: _thumbnl.GeneratePreviewThumbnails(scriptpath, xmltext, filename, width, height, options, numthumbs, errmsgs) else: _thumbnl.GenerateThumbnail(scriptpath, pagename, filename, width, height, options, errmsgs) _log.info('Generated %s thumbnail(s) of "%s".' % (numthumbs, scriptpath)) if errmsgs: _log.warn(errmsgs) return numthumbs except pythoncom.com_error, err: _log.error( '%s: %s' % (err, _thumbnl_name) ) raise err
def publish(scriptlist, targeturl, targetfolder='', logfilename='', editpassword='', options='', autostart=True): r''' Performs the equivalent of the Publish to Network function of Scala Designer5. Requires the Scala Publish Automation EX Module5 which is an additional software component that is installed seperately. Arguments: scriptlist - A string containing the absolute paths of one or more script files to publish, one per line, or alternately, a python list of them. targeturl - Publish location path/URL with username and passwd. Examples: - UNC: \\server\share\folder - FTP URL: ftp://user:pass@host[:port]/folder/ - HTTP/s Content Manager URL: http://user:pass@host[:port]/folder?netname targetfolder - Sub-folder into which to publish logfilename - Absolute path to a log file to report progress, otherwise to: "%TEMP%\pub_log.txt". editpassword - Optional password to apply to published script(s). options - A string containing zero or more of these flags: - 'd': Show progress GUI. - 'i': Ignore errors. - 'f': Do NOT include fonts. - 'w': Do NOT include wipes. - 'x': Skip cleanup. - 'p': Use passive FTP. autostart - Start the Publisher service if necessary. Returns: handle - A unique handle for use with publish_check(). Example: # See the sca_publisher.py script for a general solution. import time, glob, scalalib as sl targeturl = 'http://*****:*****@mycm.com:8080/ContentManager?MyCo' scripts = glob.glob('*.sca') pubhandle = sl.publish(scripts, targeturl, options='d') while True: time.sleep(3) status = sl.publish_check(pubhandle) statstr = ('Publishing script %(currentscriptnum)s of %(numberofscripts)s' + ' - %(overallpercentdone)3.3s%% complete, %(currentscriptname)s ') print statstr % status if status.get('overallpercentdone') == 100: break ''' import pythoncom global _publshr if autostart: from scalatools import start_svc start_svc(_pub_svc) # massage parameters to make sure paths are absolute if type(scriptlist) is list: scriptlist = [ os.path.abspath(x) for x in scriptlist ] scriptlist = '\n'.join(scriptlist) elif type(scriptlist) is str: scriptlist = os.path.abspath(scriptlist) if not logfilename: logfilename = os.path.join(os.environ['TEMP'], 'pub_log.txt') else: logfilename = os.path.abspath(logfilename) local_opts = locals() # log parameters try: if not _publshr: _publshr = COMObject(_publshr_name) pubhandle = None _log.debug('options: %s' % local_opts ) try: censoredurl = targeturl # censor url if needed. if ( targeturl.lower().startswith('http') or targeturl.lower().startswith('ftp') ): censoredurl = targeturl.split('//', 1) censoredurl = '%s%s%s%s' % (censoredurl[0], '//', 'xxx:xxx@', censoredurl[1].split('@',1)[1]) _log.info('publishing to %s' % censoredurl) except IndexError: _log.info('publishing to %s' % targeturl) if targetfolder: pubhandle = _publshr.GoPublishFolder(scriptlist, targeturl, targetfolder, logfilename, editpassword, options) else: pubhandle = _publshr.GoPublish(scriptlist, targeturl, logfilename, editpassword, options) if pubhandle == None: _log.warn('Publish operation returned None. Is the dongle present?') return pubhandle except pythoncom.com_error, err: errstr = ('%s: %s services not available. Is it installed, running, ' + 'and not disabled?') % (err.__class__.__name__, _publshr_name) _log.critical(errstr) raise err