{ "info": { "author": "Rafael Oliveira", "author_email": "rafaelbco@gmail.com", "bugtrack_url": null, "classifiers": [ "Framework :: Plone", "Programming Language :: Python", "Topic :: Software Development :: Libraries :: Python Modules" ], "description": "prdg.ploneio\n============\n\n.. contents::\n\nOverview\n--------\n\nProvide a set of views allowing to import and export content into and from\na Plone Site.\n\nThe export views are named in the pattern @@${format}-to-${output}, where:\n\n- ${format} can be one of:\n - ``dicts``: A pickle file containing a sequence of dicts.\n - ``html``: HTML files in a directory structure ressambling the folder\n structure of the site. \n \n- ${output} can be one of:\n - ``archive``: A downloadable ``.tar.gz`` file.\n - ``directory``: A directory in the server. In this case the ``directory``\n parameter must be passed in the request, containg the path to the\n directory.\n\nThe export views are context-sensitive, i.e, content in the context and\nsubfolders is exported.\n\nOne import view is provided: ``@@dicts-from-directory``. The ``directory``\nparameter must be passed in the request, containg a path to a directory\ncontaining a file named ``dicts.pickle``.\n\nThe format of the returned dicts for importing and exporting is specified in \n``prdg.plone.util.structure.create_dict_from_obj``.\n\nThe import view always import to the root of the portal, using the ``_path``\nkey of the dicts to determine where to put each object. This key must contain\na tuple representing the path of the object, relative to the portal root.\nThe dicts exported by this package always will contain this key.\n\nExamples\n--------\n\nSome setup code for the examples::\n\n >>> import pickle, os\n >>> from os.path import join\n >>> portal = self.portal\n >>> browser = self.browser\n >>> folder = self.folder \n >>> catalog = self.catalog\n >>> tmpdir = self.tmpdir\n \nWe have an empty folder, let's add some objects::\n \n >>> len(folder.objectIds())\n 0\n >>> id = folder.invokeFactory(\n ... id='obj1', type_name='Document', title='Doc 1', text='blah'\n ... )\n >>> id = folder.invokeFactory(\n ... id='folder2', type_name='Folder', title='Folder 2'\n ... )\n >>> folder2 = folder[id]\n >>> id = folder2.invokeFactory(\n ... id='obj2', type_name='Document', title='Doc 2', text='blah 2'\n ... )\n \nExporting to a pickle file containg dicts\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n \nLet's export the folder to a pickle file containing dicts. We do it\nby accessing a view::\n \n >>> view = folder.unrestrictedTraverse('@@dicts-to-archive')\n >>> view.context\n >> tar_gz_str = view()\n >>> pickle_str = self.extract_to_str(tar_gz_str, 'dicts.pickle')\n >>> dicts = pickle.loads(pickle_str)\n >>> dicts\n [{...}, ...]\n\nLet's check if the all objects in ``folder`` were exported:: \n\n >>> brains = catalog(path='/'.join(folder.getPhysicalPath()))\n >>> len(dicts) == len(brains)\n True\n\nLet's check if the returned dicts match the objects in ``folder``::\n \n >>> objs = [b.getObject() for b in brains] \n >>> set(d['id'] for d in dicts) == set(o.getId() for o in objs)\n True\n >>> set(d['title'] for d in dicts) == set(o.Title() for o in objs) \n True\n >>> set(d.get('text') for d in dicts if d.has_key('text')) \\\n ... == set(o.getText() for o in objs if hasattr(o, 'getText'))\n True \n \nInstead of downloading a .tar.gz file we could export to a directory in the\nserver::\n\n >>> view = folder.unrestrictedTraverse('@@dicts-to-directory')\n >>> view.context\n >> view.request['directory'] = tmpdir\n >>> view()\n 'Success.'\n >>> pickle_path = join(tmpdir, 'dicts.pickle')\n >>> pickle_file = open(pickle_path)\n >>> dicts = pickle.load(pickle_file)\n >>> dicts\n [{...}, ...]\n \nExporting to other formats\n^^^^^^^^^^^^^^^^^^^^^^^^^^\n\nHTML to archive::\n\n >>> view = folder.unrestrictedTraverse('@@html-to-archive')\n >>> tar_gz_str = view()\n >>> len(tar_gz_str) > 0\n True\n \nHTML to directory::\n \n >>> old_tmpdir_len = len(os.listdir(tmpdir))\n >>> view = folder.unrestrictedTraverse('@@html-to-directory')\n >>> view.request['directory'] = tmpdir\n >>> view()\n 'Success.'\n >>> len(os.listdir(tmpdir)) > old_tmpdir_len\n True\n \nImporting\n^^^^^^^^^\n\nRemember we have a pickle file created in the previous example::\n \n >>> import_dir = tmpdir\n >>> 'dicts.pickle' in os.listdir(import_dir)\n True\n\nLet's empty our ``folder``. Later we'll use the import view to re-create the \nobjects::\n \n >>> old_folder_len = len(catalog(path='/'.join(folder.getPhysicalPath())))\n >>> old_folder_len > 0\n True\n >>> folder.manage_delObjects(ids=folder.objectIds())\n >>> len(folder.objectIds())\n 0\n\nNow we'll import the pickle file::\n\n >>> view = portal.unrestrictedTraverse('@@dicts-from-directory')\n >>> view.request['directory'] = import_dir\n >>> view()\n 'Success.'\n \nLet's verify::\n\n >>> brains = catalog(path='/'.join(folder.getPhysicalPath()))\n >>> len(brains) == len(dicts) \n True\n >>> len(brains) == old_folder_len\n True\n >>> objs = [b.getObject() for b in brains] \n >>> set(d['id'] for d in dicts) == set(o.getId() for o in objs)\n True\n >>> set(d['title'] for d in dicts) == set(o.Title() for o in objs) \n True\n\n\nCredits\n-------\n\nDeveloped at `Paradigma Internet` (http://www.paradigma.com.br). \n \n \n \n \nChangelog\n=========\n\n0.0.2 (20ago2009)\n-----------------\n\n* Big refactoring.", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "http://code.google.com/p/prdg-python/", "keywords": "", "license": "GPL", "maintainer": null, "maintainer_email": null, "name": "prdg.ploneio", "package_url": "https://pypi.org/project/prdg.ploneio/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/prdg.ploneio/", "project_urls": { "Download": "UNKNOWN", "Homepage": "http://code.google.com/p/prdg-python/" }, "release_url": "https://pypi.org/project/prdg.ploneio/0.0.2/", "requires_dist": null, "requires_python": null, "summary": "Provide a set of views allowing to import and export content into and from a Plone Site.", "version": "0.0.2" }, "last_serial": 796654, "releases": { "0.0.1": [ { "comment_text": "", "digests": { "md5": "a8c880f7cc4586be4e0c2684a153c8ea", "sha256": "1c220326ba24039396c4735a7a6366f3e1a7412315d2fb2cbdf6bf0c13357763" }, "downloads": -1, "filename": "prdg.ploneio-0.0.1.zip", "has_sig": false, "md5_digest": "a8c880f7cc4586be4e0c2684a153c8ea", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 15653, "upload_time": "2009-06-15T18:54:17", "url": "https://files.pythonhosted.org/packages/a1/24/8c0b3722e215a1dd024a3b13db3ca067d507f7858b7f806d70f158434baa/prdg.ploneio-0.0.1.zip" } ], "0.0.2": [ { "comment_text": "", "digests": { "md5": "207aabd6b412f5d32b615e03bca3353e", "sha256": "141a9bb8c5a29f4e7981a922c5712713ae1d87417140a80c1b6a981193edbdbe" }, "downloads": -1, "filename": "prdg.ploneio-0.0.2.zip", "has_sig": false, "md5_digest": "207aabd6b412f5d32b615e03bca3353e", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 18743, "upload_time": "2009-08-20T20:48:29", "url": "https://files.pythonhosted.org/packages/41/e2/a56b925b12cd773cd0efafd550848d0422b2cd54a3542c91b125e20ac72e/prdg.ploneio-0.0.2.zip" } ], "0.0.2dev-r70": [] }, "urls": [ { "comment_text": "", "digests": { "md5": "207aabd6b412f5d32b615e03bca3353e", "sha256": "141a9bb8c5a29f4e7981a922c5712713ae1d87417140a80c1b6a981193edbdbe" }, "downloads": -1, "filename": "prdg.ploneio-0.0.2.zip", "has_sig": false, "md5_digest": "207aabd6b412f5d32b615e03bca3353e", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 18743, "upload_time": "2009-08-20T20:48:29", "url": "https://files.pythonhosted.org/packages/41/e2/a56b925b12cd773cd0efafd550848d0422b2cd54a3542c91b125e20ac72e/prdg.ploneio-0.0.2.zip" } ] }