Ejemplo n.º 1
0
def get_data():

    site, _ = open_root(get_default_config())
    now = str(datetime.utcnow())

    from_ = 'admin'
    to = ['joe', 'sarah']

    subject = uuid.uuid4().hex
    payload = uuid.uuid4().hex
    flags = ['read']

    thread_id = 'openhcd.' + uuid.uuid4().hex
    msg_id = 'openhcd.' +  now + '.' + uuid.uuid4().hex

    msg = MboxMessage(payload)
    msg['Message-Id'] = msg_id
    msg['Subject'] = subject
    msg['From'] = from_
    msg['To'] = ', '.join(to)
    msg['Date'] = now
    msg['X-oc-thread-id'] = thread_id
    msg['X-people-list'] = 'admin'

    return site, from_, to, msg, thread_id, msg_id, flags, subject, payload, now
Ejemplo n.º 2
0
    def test_add_message(self):

        subject = uuid.uuid4().hex
        payload = uuid.uuid4().hex

        site, _ = open_root(get_default_config())
        to = find_profiles(site)['sarah']

        with Replacer() as r:
            r.replace('opencore.views.mbox.authenticated_userid', _authenticated_user_id)
            r.replace('opencore.views.mbox._get_profile_details',
                    lambda context, request, user: {})

            request = DummyRequest(method='POST')
            request.api = DummyAPI()
            request.api.find_profile = (lambda userid: 
                    self.bob if userid == 'bob' else self.alice)
            request.POST = MultiDict([
                ('to[]', 'bob'),
                ('subject', subject),
                ('payload', payload),
                ])

            response = add_message(site, request)
            self.assertTrue("mbox_thread" in response.location)

            transaction.commit()
Ejemplo n.º 3
0
def main():
    parser = OptionParser(description=__doc__,
                          usage="%prog [options] old_name new_name")

    parser.add_option('-C', '--config', dest='config', default=None,
        help="Specify a paster config file. Defaults to $CWD/etc/openhcd.ini")
    parser.add_option('-d', '--dry-run', dest='dry_run',
        action="store_true", default=False,
        help="Don't commit the transactions")
    parser.add_option('-M', '--merge', dest='merge', action='store_true',
                      default=False, help='Merge with an existing user.')

    options, args = parser.parse_args()
    if len(args) < 2:
        parser.error("Too few parameters: %s" % repr(args))
    if len(args) > 2:
        parser.error("Too many parameters: %s" % repr(args))

    config = options.config
    if config is None:
        config = get_default_config()
    root, closer = open_root(config)

    old_name, new_name = args
    rename_user(root, old_name, new_name, options.merge, sys.stdout)

    if options.dry_run:
        transaction.abort()
    else:
        transaction.commit()
Ejemplo n.º 4
0
def main():
    parser = OptionParser(description=__doc__,
                          usage='usage: %prog [options] username password')
    parser.add_option('-C', '--config', dest='config', default=None,
                      help="Specify a paster config file. "
                           "Defaults to$CWD/etc/openhcd.ini")
    parser.add_option('--clear', dest='clear', default=False,
                      action='store_true',
                      help="Clear any existing announcement. Default false.")
    parser.add_option('-n', '--dry-run', dest='dry_run', default=False,
                      action='store_true',
                      help="Don't actually commit any change.")
    parser.add_option('-v', '--verbose', dest='verbose', action='count',
                      default='1', help="Show more information.")
    parser.add_option('-q', '--quiet', dest='verbose', action='store_const',
                      const=0, help="Show no extra information.")

    options, args = parser.parse_args()
    if options.clear:
        if args:
            parser.error("No arguments allowed with '--clear'")
        func = clear_site_announce
    else:
        func = set_site_announce

    config = options.config
    if config is None:
        config = get_default_config()
    root, closer = open_root(config)

    try:
        previous, now = func(root, *args)
    except:
        transaction.abort()
        raise
    if options.verbose:
        print 'Before:', previous
        print 'After:', now
    if options.dry_run:
        transaction.abort()
    else:
        transaction.commit()
Ejemplo n.º 5
0
def main(argv=sys.argv):
    config = None
    script = None
    if "-C" in argv:
        index = argv.index("-C")
        argv.pop(index)
        config = argv.pop(index)
    if len(argv) > 1:
        script = argv[1]
    if not config:
        config = get_default_config()
    root, closer = open_root(config)

    if script is None:
        cprt = 'Type "help" for more information. "root" is the openhcd ' "root object."
        banner = "Python %s on %s\n%s" % (sys.version, sys.platform, cprt)
        interact(banner, local={"root": root})
    else:
        code = compile(open(script).read(), script, "exec")
        exec code in {"root": root}
Ejemplo n.º 6
0
def main(argv=sys.argv):
    logging.basicConfig()
    log.setLevel(logging.INFO)

    parser = OptionParser(
        description="Move content to another folder",
        usage="%prog [options] content_path dest_folder",
        )
    parser.add_option('-C', '--config', dest='config', default=None,
        help="Specify a paster config file. Defaults to $CWD/etc/karl.ini")
    parser.add_option('-d', '--dry-run', dest='dry_run',
        action="store_true", default=False,
        help="Don't commit the transaction")
    parser.add_option('-S', '--security-state', dest='security_state',
                      default=None,
                      help="Force workflow transition to given state.  By "
                      "default no transition is performed.")
    options, args = parser.parse_args()

    if len(args) != 2:
        parser.error("Source content and destination folder are required")

    config = options.config
    if not config:
        config = get_default_config()
    root, closer = open_root(config)

    try:
        move_content(root, args[0], args[1], options.security_state)

    except:
        transaction.abort()
        raise

    else:
        if options.dry_run:
            log.info("Aborting transaction.")
            transaction.abort()
        else:
            log.info("Committing transaction.")
            transaction.commit()
Ejemplo n.º 7
0
def main():
    parser = OptionParser(description=__doc__)
    parser.add_option('-C', '--config', dest='config', default=None,
        help="Specify a paster config file. Defaults to $CWD/etc/karl.ini")
    parser.add_option('-d', '--dry-run', dest='dry_run',
        action="store_true", default=False,
        help="Don't commit the transactions")
    parser.add_option('-i', '--interval', dest='commit_interval',
        action="store", default=200,
        help="Commit every N transactions")
    parser.add_option('-p', '--path', dest='path',
        action="store", default=None, metavar='EXPR',
        help="Reindex only objects whose path matches a regular expression")
    parser.add_option('-n', '--index', dest='indexes',
        action="append", help="Reindex only the given index (can be repeated)")

    options, args = parser.parse_args()
    if args:
        parser.error("Too many parameters: %s" % repr(args))

    commit_interval = int(options.commit_interval)
    if options.path:
        path_re = re.compile(options.path)
    else:
        path_re = None

    config = options.config
    if config is None:
        config = get_default_config()
    root, closer = open_root(config)

    def output(msg):
        print msg

    kw = {}
    if options.indexes:
        kw['indexes'] = options.indexes

    reindex_catalog(root, path_re=path_re, commit_interval=commit_interval,
                    dry_run=options.dry_run, output=output, **kw)
Ejemplo n.º 8
0
def main(open_root=open_root, argv=sys.argv):
    parser = optparse.OptionParser(description=__doc__)
    parser.add_option('--dry-run', dest='dryrun',
        action='store_true', default=False,
        help="Don't actually commit the transaction")
    options, args = parser.parse_args(argv[1:])
    if len(args) < 1:
        log.error('Please specify the users you wish to make admins')
        return
    
    config = get_default_config()
    root, closer = open_root(config)

    users = root.users
    
    for userid in args:
        make_admin_user(users, userid)

    if not options.dryrun:
        transaction.commit()
    else: #pragma NO COVERAGE
        transaction.abort()
Ejemplo n.º 9
0
    def test_show_mbox(self):

        _people_url = uuid.uuid4().hex
        _firstname = uuid.uuid4().hex
        _lastname = uuid.uuid4().hex
        _country = uuid.uuid4().hex

        class _DummyAPI(object):

            static_url = '/foo/bar'

            def find_profile(*ignored_args, **ignored_kwargs):
                class _Dummy(object):
                    firstname = _firstname
                    lastname = _lastname
                    country = _country
                    organization = uuid.uuid4().hex
                    thumb_url = lambda _profile, _request: '/test-thumb.jpg'

                return _Dummy()

            people_url = _people_url

        with Replacer() as r:
            r.replace('opencore.views.mbox.authenticated_userid', _authenticated_user_id)
            r.replace('opencore.views.mbox._get_profile_details',
                    lambda context, request, user: {})


            site, from_, _, msg, thread_id, _, _, _, payload, _ = get_data()
            to = find_profiles(site)['admin']
            self.mbt.send_message(site, from_, to, msg, should_commit=True)

            site, _ = open_root(get_default_config())
            request = DummyRequest()
            request.params['thread_id'] = thread_id
            request.api = _DummyAPI()

            response = show_mbox_thread(site, request)

            self.assertTrue(isinstance(response['api'], _DummyAPI))

            self.assertTrue(len(response['messages']), 1)
            message = response['messages'][0]

            flags = message['flags']
            if flags:
                self.assertEquals(flags, ['READ'])

            self.assertEquals(message['from'], 'admin')
            self.assertEquals(message['from_country'], _country)
            self.assertEquals(message['from_firstname'], _firstname)
            self.assertEquals(message['from_lastname'], _lastname)
            self.assertEquals(message['from_photo'], '/test-thumb.jpg')
            self.assertEquals(message['payload'], payload)
            self.assertTrue(len(message['payload']) > 20)
            self.assertTrue(len(message['queue_id']) > 20)

            self.assertTrue(len(message['to_data']) == 2)
            to_data = message['to_data']

            for to_datum in to_data:
                self.assertEquals(to_datum['country'], _country)
                self.assertEquals(to_datum['firstname'], _firstname)
                self.assertEquals(to_datum['lastname'], _lastname)

                name = to_datum['name']
                self.assertTrue(name in ('joe', 'sarah'))
                self.assertEquals(to_datum['photo_url'], '/test-thumb.jpg')
Ejemplo n.º 10
0
                if set_version < 0:
                    raise Exception
            except:
                usage('Bad version number %s' % v)

    if latest and (set_version is not None):
        usage('Cannot use both --latest and --set-version together')

    if set_version and not package:
        usage('Not setting db version to %s (specify --package to '
              'specify which package to set the db version for)' % set_version)

    # hook gsm for good measure and max fwd compat
    getSiteManager.sethook(get_current_registry)

    root, closer = open_root(get_default_config())

    managers = list(getUtilitiesFor(IEvolutionManager))

    if package and package not in [x[0] for x in managers]:
        usage('No such package "%s"' % package)

    for pkg_name, factory in managers:
        if (package is None) or (pkg_name == package):
            __import__(pkg_name)
            pkg = sys.modules[pkg_name]
            VERSION = pkg.VERSION
            print 'Package %s' % pkg_name
            manager = factory(root, pkg_name, VERSION, 0)
            db_version = manager.get_db_version()
            print 'Code at software version %s' % VERSION