Ejemplo n.º 1
0
def _run_xpath(xpath):
    _, twill_locals = get_twill_glocals()
    browser = get_browser()
    html = browser.get_html()
    tree = lxml.html.document_fromstring(html)

    try:
        results = tree.xpath(xpath)
    except XPathEvalError:
        err_msg = "Invalid xpath expression: '%s'" % xpath
        log_error(err_msg)
        raise TwillException(err_msg)

    # XXX we aggregate all the values together and warn when there is more than
    # one result
    if results:
        if len(results) > 1:
            log_warn("xpath '%s' found multiple results: using all of them" % xpath)
        result = "\n".join(lxml.html.tostring(r) for r in results)
    else:
        log_error("xpath '%s' found no results")
        result = ""
    # in case we want to cache it at some point
    twill_locals["__xpath_result__"] = result
    twill_locals["__xpath_expr__"] = xpath
    return result
Ejemplo n.º 2
0
def handle_exception(msg, e):
    maybe_print_stack()
    log_error("Caught exception at %s" %
              time.strftime('%Y-%m-%d %H:%M:%S', time.localtime()))
    html = twill.get_browser().get_html()
    if options.dump_file == '-':
        print html
    else:
        dump_file_name = os.path.expanduser(options.dump_file)
            
        try:
            if html is not None:
                if options.show_error_in_browser:
                    # If we are showing it in the browser, lets get the
                    # paths right (even if if means changing the HTML a
                    # little)
                    base_href = '\n<!-- added by flunc: --><base href="%s">' % twill.get_browser().get_url()
                    match = re.search('<head.*?>', html, re.I|re.S)
                    if match:
                        html = html[:match.end()] + base_href + html[match.end():]
                    else:
                        html = base_href + html
                f = open(dump_file_name, 'wb')
                f.write(html)
                f.close()
                log_info("saved error html to: %s" % dump_file_name)
        except IOError, e:
            log_warn("Unable to save error HTML to: %s" % dump_file_name)
Ejemplo n.º 3
0
def handle_exception(msg, e):
    maybe_print_stack()
    log_error("Caught exception at %s" %
              time.strftime('%Y-%m-%d %H:%M:%S', time.localtime()))
    html = twill.get_browser().get_html()
    if options.dump_file == '-':
        print html
    else:
        dump_file_name = os.path.expanduser(options.dump_file)

        try:
            if html is not None:
                if options.show_error_in_browser:
                    # If we are showing it in the browser, lets get the
                    # paths right (even if if means changing the HTML a
                    # little)
                    base_href = '\n<!-- added by flunc: --><base href="%s">' % twill.get_browser(
                    ).get_url()
                    match = re.search('<head.*?>', html, re.I | re.S)
                    if match:
                        html = html[:match.end()] + base_href + html[match.end(
                        ):]
                    else:
                        html = base_href + html
                f = open(dump_file_name, 'wb')
                f.write(html)
                f.close()
                log_info("saved error html to: %s" % dump_file_name)
        except IOError, e:
            log_warn("Unable to save error HTML to: %s" % dump_file_name)
Ejemplo n.º 4
0
def _run_xpath(xpath):
    _, twill_locals = get_twill_glocals()
    browser = get_browser()
    html = browser.get_html()
    tree = lxml.html.document_fromstring(html)

    try:
        results = tree.xpath(xpath)
    except XPathEvalError:
        err_msg = "Invalid xpath expression: '%s'" % xpath
        log_error(err_msg)
        raise TwillException(err_msg)

    #XXX we aggregate all the values together and warn when there is more than
    #one result
    if results:
        if len(results) > 1:
            log_warn("xpath '%s' found multiple results: using all of them" %
                     xpath)
        result = '\n'.join(lxml.html.tostring(r) for r in results)
    else:
        log_error("xpath '%s' found no results")
        result = ''
    # in case we want to cache it at some point
    twill_locals['__xpath_result__'] = result
    twill_locals['__xpath_expr__'] = xpath
    return result
Ejemplo n.º 5
0
def zope_delobject(container, obj, admin_user, admin_pw):
    # use a the 'cleanup_base_url', which may be different than the base_url
    base_url = get_twill_var('cleanup_base_url')
    prepath = get_twill_var('prepath')

    log_warn("(zope) Deleting %s from %s on %s" % (obj, container, base_url))

    scheme, uri = urllib.splittype(base_url)
    host, path = urllib.splithost(uri)
    if prepath is not None:
        path = prepath + path
    auth_url = "%s://%s:%s@%s%s/" % (scheme, admin_user, admin_pw, host, path)
    portal = XMLRPCServer(auth_url)
    try:
        getattr(portal, container).manage_delObjects([obj])
    except Fault, e:
        ignorable = '%s does not exist' % obj
        if str(e).count(ignorable):
            log_warn("(zope) can't delete %s/%s/%s, it didn't exist" %
                     (uri, container, obj))
        elif options.verbose:
            raise
        else:
            log_error("Error removing '%s' from '%s': %s" %
                      (obj, container, str(e)))
Ejemplo n.º 6
0
def create_doc(container,
               admin_user,
               admin_pw,
               id,
               title,
               body,
               revision=None):
    base_url = get_twill_var('base_url')
    prepath = get_twill_var('prepath')

    log_warn("(zope) Creating document %s in %s" % (id, container))
    scheme, uri = urllib.splittype(base_url)
    host, path = urllib.splithost(uri)
    if prepath is not None:
        path = prepath + path
    auth_url = "%s://%s:%s@%s%s/" % (scheme, admin_user, admin_pw, host, path)
    portal = XMLRPCServer(auth_url)
    getattr(portal, container).invokeFactory('Document', id)
    item = getattr(getattr(portal, container), id)
    item.setTitle(title)
    item.setText(body)

    # XXX getting error:
    # TypeError: cannot marshal <type 'instancemethod'> objects
    #    if revision:
    #        getattr(portal, 'portal_repository').save(item, revision)

    item.reindexObject()
Ejemplo n.º 7
0
def export_file_contains(filename, content):
    globals, locals = get_twill_glocals()
    z, zipname = globals["__project_export__"]
    if filename not in z.namelist():
        raise TwillAssertionError("file %s not found in project export zipfile" % filename)
    log_warn("inspecting contents of file '%s' in project export zipfile '%s' " % (filename, zipname))
    body = z.read(filename)
    if content not in body:
        raise TwillAssertionError("text '%s' not found in contents of file '%s': %s" % (content, filename, body))
Ejemplo n.º 8
0
def inspect(filename):
    globals, locals = get_twill_glocals()
    z, zipname = globals['__project_export__']
    if filename not in z.namelist():
        raise TwillAssertionError("file %s not found in project export zipfile" % filename)
    log_warn("inspecting contents of file '%s' in project export zipfile '%s' " % (
            filename, zipname))
    body = z.read(filename)
    import pdb; pdb.set_trace()
Ejemplo n.º 9
0
 def power_state_monitor(self):
     log_info('starting power state monitor')
     while True:
         self.power_state = self.powerman.read()
         if self.power_state.critical:
             log_warn('critical power state: emergency landing')
             # disable system interface and take over control:
             self.icarus_takeover = True
             if not self.emergency_land:
                 self.emergency_landing()
Ejemplo n.º 10
0
 def power_state_monitor(self):
     log_info("starting power state monitor")
     while True:
         self.power_state = self.powerman.read()
         if self.power_state.critical:
             log_warn("critical power state: emergency landing")
             # disable system interface and take over control:
             self.icarus_takeover = True
             if not self.emergency_land:
                 self.emergency_landing()
Ejemplo n.º 11
0
def inspect(filename):
    globals, locals = get_twill_glocals()
    z, zipname = globals["__project_export__"]
    if filename not in z.namelist():
        raise TwillAssertionError("file %s not found in project export zipfile" % filename)
    log_warn("inspecting contents of file '%s' in project export zipfile '%s' " % (filename, zipname))
    body = z.read(filename)
    import pdb

    pdb.set_trace()
Ejemplo n.º 12
0
 def battery_warning(self):
    # do something in order to indicate a low battery:
    msg = 'CRITICAL WARNING: SYSTEM BATTERY VOLTAGE IS LOW; IMMEDIATE SHUTDOWN REQUIRED OR SYSTEM WILL BE DAMAGED'
    log_warn(msg)
    system('echo "%s" | wall' % msg)
    while True:
       self.gpio_mosfet.set_gpio(5, False)
       sleep(0.1)
       self.gpio_mosfet.set_gpio(5, True)
       sleep(0.1)
Ejemplo n.º 13
0
def export_file_contains(filename, content):
    globals, locals = get_twill_glocals()
    z, zipname = globals['__project_export__']
    if filename not in z.namelist():
        raise TwillAssertionError("file %s not found in project export zipfile" % filename)
    log_warn("inspecting contents of file '%s' in project export zipfile '%s' " % (
            filename, zipname))
    body = z.read(filename)
    if content not in body:
        raise TwillAssertionError("text '%s' not found in contents of file '%s': %s" % (
                content, filename, body))
Ejemplo n.º 14
0
def do_cleanup_for(name):
    if has_cleanup_handler(name) and not options.no_cleanup_mode: 
        log_info("running cleanup handler for %s" % name)
        try:
            suite_data = file(current_namespace[-1].cleanup[name]).read()
            calls = parse_suite(suite_data)
            for script,args,line in calls:
                try:
                    if current_namespace[-1].suites.get(script):
                        log_warn("Cannot call sub-suite %s during cleanup at %s(%d)" % (script,name,line))
                    else:
                        log_info("running cleanup: %s" % name)
                        script_data = read_test(script)
                        try:
                            parameters = make_dict_from_call(args,get_twill_glocals()[0])
                        except (ValueError, TypeError, SyntaxError), e:
                            e.args = ("\"%s%s\": Only positional argument passing is supported in suites." % \
                                          (name, args), ) + e.args[1:]
                            raise e
                        script_data = make_twill_local_defs(parameters) + script_data 
                        twill.execute_string(script_data, no_reset=1)
                except Exception, e:
                    maybe_print_stack() 
                    log_warn("Cleanup call to %s failed at %s(%d)" 
                         % (script + args, name + CLEANUP, line))
        except IOError,e:
            maybe_print_stack()
            log_warn("Unable to read cleanup handler for %s" % name)
        except Exception,e:
            maybe_print_stack()
            log_warn("Exception during cleanup handler for %s" % name)
Ejemplo n.º 15
0
def run_cat_queue(admin_user, admin_pw): 
    globals, locals = get_twill_glocals()

    base_url = globals.get('base_url')
    prepath = globals.get('prepath')

    log_warn("(zope) Running catalog queue for %s" % (base_url))

    scheme, uri = urllib.splittype(base_url) 
    host, path = urllib.splithost(uri)
    if prepath is not None:
        path = prepath + path
    auth_url = "%s://%s:%s@%s%s/" % (scheme, admin_user, admin_pw, host, path)
    portal = XMLRPCServer(auth_url)

    portal.portal_catalog_queue.manage_process()
Ejemplo n.º 16
0
def run_cat_queue(admin_user, admin_pw):
    globals, locals = get_twill_glocals()

    base_url = globals.get("base_url")
    prepath = globals.get("prepath")

    log_warn("(zope) Running catalog queue for %s" % (base_url))

    scheme, uri = urllib.splittype(base_url)
    host, path = urllib.splithost(uri)
    if prepath is not None:
        path = prepath + path
    auth_url = "%s://%s:%s@%s%s/" % (scheme, admin_user, admin_pw, host, path)
    portal = XMLRPCServer(auth_url)

    portal.portal_catalog_queue.manage_process()
Ejemplo n.º 17
0
   def run(self):
      arg = self.icarus.arg
      core = self.icarus.core
      mon_data = self.icarus.mon_data
      params = self.icarus.core.params

      if arg.HasField('move_data'):
         z_setpoint = arg.move_data.z
         if arg.HasField('rel'):
            log_warn('rel field ignored for take-off')
         if arg.HasField('glob'):
            if not arg.glob:
               if z_setpoint < core.params.start_alt + mon_data.z + 3.0:
                  msg = 'absolute z setpoint %f is below current altitude' % z_setpoint
                  log_err(msg)
                  raise ValueError(msg)
               log_info('taking off to absolute altitude %f' % z_setpoint)
            else:
               z_setpoint = mon_data.z + z_setpoint
               log_info('taking off to relative altitude %f' % z_setpoint)
      else:
         z_setpoint = self.STD_HOVERING_ALT

      try:
         core.spin_up()
      except:
         core.spin_down()
         self.fsm.failed()
         log_error('could not spin up motors');
         return

      if self.canceled:
         core.spin_down()
         log_error('take-off canceled');
         return

      # "point of no return":
      # reset controllers:
      core.set_ctrl_param(POS_YAW, mon_data.yaw)
      core.set_ctrl_param(POS_X, mon_data.x)
      core.set_ctrl_param(POS_Y, mon_data.y)
      core.reset_ctrl()

      # set new altitude setpoint and stabilize:
      core.set_ctrl_param(POS_Z, z_setpoint)
      self.stabilize()
      self.fsm.done()
Ejemplo n.º 18
0
def run_test(name, args):

    # this pushes the correct namespace on the stack
    # should be popped
    test = current_namespace[-1].lookup(name)
    if test is None:
        raise NameError("Unable to locate %s or %s in search path" %
                        (name + TEST, name + SUITE))
    name = test

    current = current_namespace[-1]
    try:
        if current.suites.get(name):
            if args:
                log_warn("Arguments provided to suites are ignored! [%s%s]" %
                         (name, args))
            return run_suite(name)
        elif current.tests.get(name):

            # don't do anything in cleanup only mode
            if options.cleanup_mode:
                return []

            try:
                log_info("running test: %s" % name)
                output_stream.indent()
                try:
                    script = file(current.tests[name]).read()
                    try:
                        parameters = make_dict_from_call(
                            args,
                            get_twill_glocals()[0])
                    except (ValueError, TypeError, SyntaxError), e:
                        e.args = ("\"%s%s\": Only positional argument passing is supported in suites." % \
                                      (name, args), ) + e.args[1:]
                        raise e
                    script = make_twill_local_defs(parameters) + script
                    twill.execute_string(script, no_reset=1)
                    return []
                except IOError, e:
                    handle_exception(
                        "Unable to read test '%s'" % (name + TEST), e)
                    return [name]
                except Exception, e:
                    handle_exception("Error running %s" % name, e)
                    return [name]
Ejemplo n.º 19
0
def get_uid(username, admin_user, admin_pw): 
    globals, locals = get_twill_glocals()

    base_url = globals.get('base_url')
    prepath = globals.get('prepath')

    log_warn("(zope) Getting uid for user %s on %s" % (username, base_url))

    scheme, uri = urllib.splittype(base_url) 
    host, path = urllib.splithost(uri)
    if prepath is not None:
        path = prepath + path
    auth_url = "%s://%s:%s@%s%s/" % (scheme, admin_user, admin_pw, host, path)
    portal = XMLRPCServer(auth_url)

    confirmation_code = getattr(portal.portal_memberdata, username).getUserConfirmationCode()

    locals['__uid__'] = confirmation_code
Ejemplo n.º 20
0
def run_test(name,args):

    # this pushes the correct namespace on the stack
    # should be popped
    test = current_namespace[-1].lookup(name)
    if test is None:
        raise NameError("Unable to locate %s or %s in search path" %
                        (name + TEST, name + SUITE))
    name = test

    current = current_namespace[-1]
    try:
        if current.suites.get(name):
            if args:
                log_warn("Arguments provided to suites are ignored! [%s%s]" 
                         % (name,args))
            return run_suite(name)
        elif current.tests.get(name):

            # don't do anything in cleanup only mode 
            if options.cleanup_mode:
                return []

            try:
                log_info("running test: %s" % name)
                output_stream.indent()
                try:            
                    script = file(current.tests[name]).read()
                    try:
                        parameters = make_dict_from_call(args,get_twill_glocals()[0])
                    except (ValueError, TypeError, SyntaxError), e:
                        e.args = ("\"%s%s\": Only positional argument passing is supported in suites." % \
                                      (name, args), ) + e.args[1:]
                        raise e
                    script = make_twill_local_defs(parameters) + script
                    twill.execute_string(script, no_reset=1)
                    return []
                except IOError, e: 
                    handle_exception("Unable to read test '%s'" % (name + TEST), e)
                    return [name]
                except Exception, e: 
                    handle_exception("Error running %s" % name, e)
                    return [name]
Ejemplo n.º 21
0
def run_export_queue(admin_user, admin_pw, expected=None):
    globals, locals = get_twill_glocals()

    base_url = globals.get("base_url")
    prepath = globals.get("prepath")

    log_warn("(zope) Running export queue for %s" % (base_url))

    scheme, uri = urllib.splittype(base_url)
    host, path = urllib.splithost(uri)
    if prepath is not None:
        path = prepath + path
    auth_url = "%s://%s:%s@%s%s/" % (scheme, admin_user, admin_pw, host, path)
    portal = XMLRPCServer(auth_url)

    # pass in a maxwait of 1 second to speed things up
    exports = portal.manage_project_export_queue(1)
    if expected is not None and expected not in exports:
        raise TwillAssertionError("project id %s not found in exported projects: %r" % (expected, exports))
Ejemplo n.º 22
0
def get_uid(username, admin_user, admin_pw):
    globals, locals = get_twill_glocals()

    base_url = globals.get('base_url')
    prepath = globals.get('prepath')

    log_warn("(zope) Getting uid for user %s on %s" % (username, base_url))

    scheme, uri = urllib.splittype(base_url)
    host, path = urllib.splithost(uri)
    if prepath is not None:
        path = prepath + path
    auth_url = "%s://%s:%s@%s%s/" % (scheme, admin_user, admin_pw, host, path)
    portal = XMLRPCServer(auth_url)

    confirmation_code = getattr(portal.portal_memberdata,
                                username).getUserConfirmationCode()

    locals['__uid__'] = confirmation_code
Ejemplo n.º 23
0
def run_export_queue(admin_user, admin_pw, expected=None):
    globals, locals = get_twill_glocals()

    base_url = globals.get('base_url')
    prepath = globals.get('prepath')

    log_warn("(zope) Running export queue for %s" % (base_url))

    scheme, uri = urllib.splittype(base_url) 
    host, path = urllib.splithost(uri)
    if prepath is not None:
        path = prepath + path
    auth_url = "%s://%s:%s@%s%s/" % (scheme, admin_user, admin_pw, host, path)
    portal = XMLRPCServer(auth_url)

    # pass in a maxwait of 1 second to speed things up
    exports = portal.manage_project_export_queue(1)
    if expected is not None and expected not in exports:
        raise TwillAssertionError("project id %s not found in exported projects: %r" % (expected, exports))
Ejemplo n.º 24
0
def opencore_user_cleanup(admin_user, admin_pw):
    globals, locals = get_twill_glocals()

    base_url = globals.get('base_url')
    prepath = globals.get('prepath')

    log_warn("(zope) Cleaning up local roles for %s" % (base_url))

    scheme, uri = urllib.splittype(base_url)
    host, path = urllib.splithost(uri)
    if prepath is not None:
        path = prepath + path
    auth_url = "%s://%s:%s@%s%s/" % (scheme, admin_user, admin_pw, host, path)
    portal = XMLRPCServer(auth_url)

    try:
        getattr(portal, 'member-postdelete-cleanup')()
    except Fault, e:
        log_warn("could not clean up local roles, maybe your version of opencore doesn't support it?")
Ejemplo n.º 25
0
   def run(self):
      arg = self.icarus.arg
      pilot = self.icarus.pilot
      mon_data = self.icarus.mon_data
      params = self.icarus.pilot.params

      if arg.HasField('move_data'):
         z_setpoint = arg.move_data.z
         if arg.HasField('rel'):
            log_warn('rel field ignored for take-off')
         if arg.HasField('glob'):
            if not arg.glob:
               if z_setpoint < pilot.params.start_alt + mon_data.z + 3.0:
                  msg = 'absolute z setpoint %f is below current altitude' % z_setpoint
                  log_err(msg)
                  raise ValueError(msg)
               log_info('taking off to absolute altitude %f' % z_setpoint)
            else:
               z_setpoint = mon_data.z + z_setpoint
               log_info('taking off to relative altitude %f' % z_setpoint)
      else:
         z_setpoint = self.STD_HOVERING_ALT

      pilot.start_motors()

      if self.canceled:
         pilot.stop_motors()
         log_error('take-off canceled');
         return

      # "point of no return":
      # reset controllers:
      pilot.set_ctrl_param(POS_YAW, mon_data.yaw)
      pilot.set_ctrl_param(POS_E, mon_data.e)
      pilot.set_ctrl_param(POS_N, mon_data.n)
      pilot.reset_ctrl()

      # set new altitude setpoint and stabilize:
      pilot.set_ctrl_param(POS_U, u_setpoint)
      self.stabilize()
      self.fsm.handle('done')
Ejemplo n.º 26
0
    def run(self):
        arg = self.icarus.arg
        pilot = self.icarus.pilot
        mon_data = self.icarus.mon_data
        params = self.icarus.pilot.params

        if arg.HasField('move_data'):
            z_setpoint = arg.move_data.z
            if arg.HasField('rel'):
                log_warn('rel field ignored for take-off')
            if arg.HasField('glob'):
                if not arg.glob:
                    if z_setpoint < pilot.params.start_alt + mon_data.z + 3.0:
                        msg = 'absolute z setpoint %f is below current altitude' % z_setpoint
                        log_err(msg)
                        raise ValueError(msg)
                    log_info('taking off to absolute altitude %f' % z_setpoint)
                else:
                    z_setpoint = mon_data.z + z_setpoint
                    log_info('taking off to relative altitude %f' % z_setpoint)
        else:
            z_setpoint = self.STD_HOVERING_ALT

        pilot.start_motors()

        if self.canceled:
            pilot.stop_motors()
            log_error('take-off canceled')
            return

        # "point of no return":
        # reset controllers:
        pilot.set_ctrl_param(POS_YAW, mon_data.yaw)
        pilot.set_ctrl_param(POS_E, mon_data.e)
        pilot.set_ctrl_param(POS_N, mon_data.n)
        pilot.reset_ctrl()

        # set new altitude setpoint and stabilize:
        pilot.set_ctrl_param(POS_U, u_setpoint)
        self.stabilize()
        self.fsm.handle('done')
Ejemplo n.º 27
0
def opencore_user_cleanup(admin_user, admin_pw):
    globals, locals = get_twill_glocals()

    base_url = globals.get('base_url')
    prepath = globals.get('prepath')

    log_warn("(zope) Cleaning up local roles for %s" % (base_url))

    scheme, uri = urllib.splittype(base_url)
    host, path = urllib.splithost(uri)
    if prepath is not None:
        path = prepath + path
    auth_url = "%s://%s:%s@%s%s/" % (scheme, admin_user, admin_pw, host, path)
    portal = XMLRPCServer(auth_url)

    try:
        getattr(portal, 'member-postdelete-cleanup')()
    except Fault, e:
        log_warn(
            "could not clean up local roles, maybe your version of opencore doesn't support it?"
        )
Ejemplo n.º 28
0
def send_mail_string(mailStr, base_url=None):
    if base_url is None:
        tglobals, tlocals = get_twill_glocals()
        base_url = tglobals['base_url']

    receiverURL = "%s/send_listen_mail" % base_url.rstrip("/")

    tglobals, tlocals = get_twill_glocals()
    ctx = tglobals.copy()
    ctx.update(tlocals)
    mailStr = substitute_vars(mailStr, ctx)

    mail = email.message_from_string(mailStr)
    body = mail.get_payload()
    sender = mail['From']
    recipient = mail['To']
    subject = mail['Subject']
    log_warn("sending email: Subject: '%s'; From: '%s'; To: '%s'" %
             (subject, sender, recipient))

    send(receiverURL, mailStr)
Ejemplo n.º 29
0
def destroy_posts(projurl):
    """delete all blog posts in a project"""

    log_warn("(wordpress) Deleting posts")
    
    url = '%s/blog/wp-admin/edit.php' % projurl

    def delete_links():
        go(url)
        return [link.url for link in get_browser()._browser.links()
                if link.text == 'Delete']

    try:
        for link in delete_links():
            go('%s/blog/wp-admin/%s' % (projurl, link))
    except:
        if options.verbose:
            raise
        log_error("Error removing posts from '%s'" % projurl)

    assert not delete_links()
Ejemplo n.º 30
0
def send_mail_string(mailStr, base_url=None):
    if base_url is None:
        tglobals, tlocals = get_twill_glocals()
        base_url = tglobals['base_url']

    receiverURL = "%s/send_listen_mail" % base_url.rstrip("/")

    tglobals, tlocals = get_twill_glocals()
    ctx = tglobals.copy()
    ctx.update(tlocals)
    mailStr = substitute_vars(mailStr, ctx)

    mail = email.message_from_string(mailStr)
    body = mail.get_payload()
    sender = mail['From']
    recipient = mail['To']
    subject = mail['Subject']
    log_warn("sending email: Subject: '%s'; From: '%s'; To: '%s'" % (
            subject, sender, recipient))

    send(receiverURL, mailStr)
Ejemplo n.º 31
0
def create_doc(container, admin_user, admin_pw, id, title, body, revision=None): 
    base_url = get_twill_var('base_url')
    prepath = get_twill_var('prepath')

    log_warn("(zope) Creating document %s in %s" % (id, container))
    scheme, uri = urllib.splittype(base_url) 
    host, path = urllib.splithost(uri)
    if prepath is not None:
        path = prepath + path
    auth_url = "%s://%s:%s@%s%s/" % (scheme, admin_user, admin_pw, host, path)
    portal = XMLRPCServer(auth_url)
    getattr(portal, container).invokeFactory('Document', id)
    item = getattr(getattr(portal, container), id)
    item.setTitle(title)
    item.setText(body)

    # XXX getting error:
    # TypeError: cannot marshal <type 'instancemethod'> objects
#    if revision:
#        getattr(portal, 'portal_repository').save(item, revision)

    item.reindexObject()
Ejemplo n.º 32
0
def zope_delobject(container, obj, admin_user, admin_pw):
    # use a the 'cleanup_base_url', which may be different than the base_url
    base_url = get_twill_var('cleanup_base_url')
    prepath = get_twill_var('prepath')

    log_warn("(zope) Deleting %s from %s on %s" % (obj, container, base_url))

    scheme, uri = urllib.splittype(base_url) 
    host, path = urllib.splithost(uri)
    if prepath is not None:
        path = prepath + path
    auth_url = "%s://%s:%s@%s%s/" % (scheme, admin_user, admin_pw, host, path)
    portal = XMLRPCServer(auth_url)
    try:
        getattr(portal, container).manage_delObjects([obj])
    except Fault, e:
        ignorable = '%s does not exist' % obj
        if str(e).count(ignorable):
            log_warn("(zope) can't delete %s/%s/%s, it didn't exist" % (uri, container, obj))
        elif options.verbose:
            raise
        else:
            log_error("Error removing '%s' from '%s': %s" % (obj, container, str(e)))
Ejemplo n.º 33
0
def do_cleanup_for(name):
    if has_cleanup_handler(name) and not options.no_cleanup_mode:
        log_info("running cleanup handler for %s" % name)
        try:
            suite_data = file(current_namespace[-1].cleanup[name]).read()
            calls = parse_suite(suite_data)
            for script, args, line in calls:
                try:
                    if current_namespace[-1].suites.get(script):
                        log_warn(
                            "Cannot call sub-suite %s during cleanup at %s(%d)"
                            % (script, name, line))
                    else:
                        log_info("running cleanup: %s" % name)
                        script_data = read_test(script)
                        try:
                            parameters = make_dict_from_call(
                                args,
                                get_twill_glocals()[0])
                        except (ValueError, TypeError, SyntaxError), e:
                            e.args = ("\"%s%s\": Only positional argument passing is supported in suites." % \
                                          (name, args), ) + e.args[1:]
                            raise e
                        script_data = make_twill_local_defs(
                            parameters) + script_data
                        twill.execute_string(script_data, no_reset=1)
                except Exception, e:
                    maybe_print_stack()
                    log_warn("Cleanup call to %s failed at %s(%d)" %
                             (script + args, name + CLEANUP, line))
        except IOError, e:
            maybe_print_stack()
            log_warn("Unable to read cleanup handler for %s" % name)
        except Exception, e:
            maybe_print_stack()
            log_warn("Exception during cleanup handler for %s" % name)
Ejemplo n.º 34
0
                f = open(dump_file_name, 'wb')
                f.write(html)
                f.close()
                log_info("saved error html to: %s" % dump_file_name)
        except IOError, e:
            log_warn("Unable to save error HTML to: %s" % dump_file_name)

    if e.args:
        log_error("%s (%s)" % (msg, e.args[0]))
    else:
        log_error(msg)

    if options.show_error_in_browser:
        if options.dump_file == '-':
            log_warn(
                "Web browser view is not supported when dumping error html to standard out."
            )
        else:
            try:
                log_info("Launching web browser...")
                import webbrowser
                path = os.path.abspath(os.path.expanduser(options.dump_file))
                webbrowser.open('file://' + path)
            except:
                maybe_print_stack()
                log_error("Unable to open current HTML in webbrowser")

    if options.interactive:
        try:
            do_twill_repl()
        except Exception:
Ejemplo n.º 35
0
                        html = base_href + html
                f = open(dump_file_name, 'wb')
                f.write(html)
                f.close()
                log_info("saved error html to: %s" % dump_file_name)
        except IOError, e:
            log_warn("Unable to save error HTML to: %s" % dump_file_name)

    if e.args:
        log_error("%s (%s)" % (msg,e.args[0]))
    else:
        log_error(msg)

    if options.show_error_in_browser:
        if options.dump_file == '-': 
            log_warn("Web browser view is not supported when dumping error html to standard out.")
        else:
            try:
                log_info("Launching web browser...")
                import webbrowser
                path = os.path.abspath(os.path.expanduser(options.dump_file))
                webbrowser.open('file://' + path)            
            except: 
                maybe_print_stack()
                log_error("Unable to open current HTML in webbrowser")
        

    if options.interactive:
        try: 
            do_twill_repl()
        except Exception:
Ejemplo n.º 36
0
def main(argv=None):
    if argv is None:
        argv = sys.argv

    parser, usage = get_optparser()

    global options 
    options, args = parser.parse_args(argv)

    global name_lookup
    directory = os.path.expanduser(options.search_path)
    name_lookup = Namespace(directory)
    global current_namespace
    current_namespace = [name_lookup]

    if options.recursive:
        name_lookup.flatten()

    if options.list_suites:
        list_suites()
        return

    if len(args) < 2: 
        die("No tests specified", parser)

    if options.cleanup_mode and options.no_cleanup_mode:
        die("Conflicting options specified, only one of cleanup-mode, no-cleanup-mode may be specified.",parser)

    # showing an error in the browser implies interactive mode
    if options.show_error_in_browser:
        options.interactive = True

    if options.browser: 
        os.environ['BROWSER'] = options.browser

    scheme, uri = urllib.splittype(options.base_url)
    if scheme is None: 
        log_warn("no scheme specified in test url, assuming http")
        options.base_url = "http://" + options.base_url 
    elif not scheme == 'http' and not scheme == 'https':
        die("unsupported scheme '%s' in '%s'" % (scheme,options.base_url))
    
    host, path = urllib.splithost(uri)

    log_info("Running against %s, host: %s path=%s" % \
        (options.base_url,host,path))
    # define utility variables to help point scripts at desired location
    define_twill_vars(base_url=options.base_url)
    define_twill_vars(base_host=host)
    define_twill_vars(base_path=path)
    define_twill_vars(test_path=os.path.realpath(options.search_path))

    # use the base_url if the cleanup_base_url was not specified
    if options.cleanup_base_url is None:
        options.cleanup_base_url = options.base_url
    define_twill_vars(cleanup_base_url=options.cleanup_base_url)
    
    if options.config_file: 
        try: 
            global CONFIG_OVERRIDE_SCRIPT 
            CONFIG_OVERRIDE_SCRIPT = read_configuration(options.config_file)
        except IOError, msg:
            die(msg)
Ejemplo n.º 37
0
def main(argv=None):
    if argv is None:
        argv = sys.argv

    parser, usage = get_optparser()

    global options
    options, args = parser.parse_args(argv)

    global name_lookup
    directory = os.path.expanduser(options.search_path)
    name_lookup = Namespace(directory)
    global current_namespace
    current_namespace = [name_lookup]

    if options.recursive:
        name_lookup.flatten()

    if options.list_suites:
        list_suites()
        return

    if len(args) < 2:
        die("No tests specified", parser)

    if options.cleanup_mode and options.no_cleanup_mode:
        die(
            "Conflicting options specified, only one of cleanup-mode, no-cleanup-mode may be specified.",
            parser)

    # showing an error in the browser implies interactive mode
    if options.show_error_in_browser:
        options.interactive = True

    if options.browser:
        os.environ['BROWSER'] = options.browser

    scheme, uri = urllib.splittype(options.base_url)
    if scheme is None:
        log_warn("no scheme specified in test url, assuming http")
        options.base_url = "http://" + options.base_url
    elif not scheme == 'http' and not scheme == 'https':
        die("unsupported scheme '%s' in '%s'" % (scheme, options.base_url))

    host, path = urllib.splithost(uri)

    log_info("Running against %s, host: %s path=%s" % \
        (options.base_url,host,path))
    # define utility variables to help point scripts at desired location
    define_twill_vars(base_url=options.base_url)
    define_twill_vars(base_host=host)
    define_twill_vars(base_path=path)
    define_twill_vars(test_path=os.path.realpath(options.search_path))

    # use the base_url if the cleanup_base_url was not specified
    if options.cleanup_base_url is None:
        options.cleanup_base_url = options.base_url
    define_twill_vars(cleanup_base_url=options.cleanup_base_url)

    if options.config_file:
        try:
            global CONFIG_OVERRIDE_SCRIPT
            CONFIG_OVERRIDE_SCRIPT = read_configuration(options.config_file)
            log_info("Loaded global config overrides: %s" %
                     options.config_file)
        except IOError, msg:
            die(msg)