from Products.CMFCore.utils import getToolByName
from opencore.utils import setup
import transaction
import os, sys
from zipfile import ZipFile

app = setup(app)

zipfile = sys.argv[-2]
project = sys.argv[-1]

project = app.openplans.projects[project]
proj_id = project.getId()

zipfile = ZipFile(zipfile)

import tempfile
tempdir = tempfile.mkdtemp(prefix="--opencore-wiki-import-")

for path in zipfile.namelist():
    parts = path.split("/")
    if len(parts) < 2:
        continue
    if parts[1] == "wiki_history":
        if path.endswith("/"):
            try:
                os.makedirs(os.path.join(tempdir, *parts[2:]))
            except:
                pass
            continue
        else:
import sys
import transaction
from AccessControl.SecurityManagement import newSecurityManager
from AccessControl.SpecialUsers import system
from Products.CMFCore.utils import getToolByName

try:
    portal = sys.argv[1]
except IndexError:
    portal = 'openplans'

from opencore.utils import setup

app = setup(app, site=portal)
portal = app[portal]

wf = getToolByName(portal,'portal_workflow')
cat = getToolByName(portal,'portal_catalog')
storage = getToolByName(portal,'portal_repository')
content = cat(Language='all', portal_type='Document')
total=len(content)
skipped = 0
purged = 0
current=0
delta = 0

for obj in content:
    current+=1
    if current%10 == 0:
        print "%f%% %d more to go (%d objects purged so far)" % (((100.0*current)/total),total - current, purged)
    try: