Skip to content

Commit

Permalink
Merge pull request #56 from mhrivnak/mongoengine
Browse files Browse the repository at this point in the history
converted to use mongoengine
  • Loading branch information
mhrivnak committed Jan 18, 2016
2 parents 20653a6 + 05c2dd3 commit f48f238
Show file tree
Hide file tree
Showing 12 changed files with 389 additions and 781 deletions.
31 changes: 17 additions & 14 deletions plugins/pulp_python/plugins/distributors/steps.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
from gettext import gettext as _
import itertools
import logging
import os
from xml.etree import cElementTree as ElementTree

from pulp.plugins.util.publish_step import AtomicDirectoryPublishStep, PluginStep
from pulp.server.controllers import repository as repo_controller

from pulp_python.common import constants
from pulp_python.plugins import models
from pulp_python.plugins.distributors import configuration


Expand All @@ -30,7 +33,7 @@ def process_main(self):
"""
Publish all the python files themselves by creating the symlinks to the storage paths.
"""
for name, packages in _get_packages(self.get_conduit()).items():
for name, packages in _get_packages(self.get_conduit().repo_id).items():
for package in packages:
relative_path = _get_package_path(name, package['filename'])
symlink_path = os.path.join(self.parent.web_working_dir, relative_path)
Expand Down Expand Up @@ -62,7 +65,7 @@ def process_main(self):
os.makedirs(simple_path)
simple_index_path = os.path.join(simple_path, 'index.html')

packages = _get_packages(self.get_conduit())
packages = _get_packages(self.get_conduit().repo_id)

with open(simple_index_path, 'w') as index:
html = ElementTree.Element('html')
Expand Down Expand Up @@ -168,27 +171,27 @@ def _get_package_path(name, filename):
return os.path.join('packages', 'source', name[0], name, filename)


def _get_packages(conduit):
def _get_packages(repo_id):
"""
Build and return a data structure of the available packages. The keys each index a list of
dictionaries. The inner dictionaries are of the form
{'version': VERSION, 'filename': FILENAME, 'checksum': MD5SUM, 'checksum_type': TYPE,
'storage_path': PATH}
:param conduit: A SingleRepoUnitsMixin object configured for the repo you are publishing.
:type conduit: pulp.plugins.conduits.mixins.SingleRepoUnitsMixin
:param repo_id: ID of the repo being published.
:type repo_id: basestring
:return: A dictionary of all the packages in the repo to be published
:rtype: dict
"""
packages = {}
for p in conduit.get_units():
name = p.unit_key['name']
if name not in packages:
packages[name] = []
packages[name].append(
{'version': p.unit_key['version'],
'filename': p.metadata['_filename'],
'checksum': p.metadata['_checksum'],
'checksum_type': p.metadata['_checksum_type'],
fields = ('version', '_filename', '_checksum', '_checksum_type', 'name', '_storage_path')
unit_querysets = repo_controller.get_unit_model_querysets(repo_id, models.Package)
unit_querysets = (q.only(*fields) for q in unit_querysets)
for p in itertools.chain(*unit_querysets):
packages.setdefault(p.name, []).append(
{'version': p.version,
'filename': p._filename,
'checksum': p._checksum,
'checksum_type': p._checksum_type,
'storage_path': p.storage_path})
return packages
18 changes: 9 additions & 9 deletions plugins/pulp_python/plugins/importers/importer.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from gettext import gettext as _
from itertools import chain
import shutil
import tempfile

from pulp.plugins.importer import Importer
from pulp.server.db.model import criteria
from pulp.server.controllers import repository as repo_controller

from pulp_python.common import constants
from pulp_python.plugins import models
Expand Down Expand Up @@ -65,11 +66,12 @@ def import_units(self, source_repo, dest_repo, import_conduit, config, units=Non
:rtype: list
"""
if units is None:
search = criteria.UnitAssociationCriteria(type_ids=[constants.PACKAGE_TYPE_ID])
units = import_conduit.get_source_units(criteria=search)
units = chain(*repo_controller.get_unit_model_querysets(source_repo.repo_obj.repo_id,
models.Package))

units = list(units)
for u in units:
import_conduit.associate_unit(u)
repo_controller.associate_single_unit(dest_repo.repo_obj, u)

return units

Expand Down Expand Up @@ -181,11 +183,9 @@ def upload_unit(self, repo, type_id, unit_key, metadata, file_path, conduit, con
:rtype: dict
"""
package = models.Package.from_archive(file_path)
package.init_unit(conduit)

shutil.move(file_path, package.storage_path)

package.save_unit(conduit)
package.save()
package.import_content(file_path)
repo_controller.associate_single_unit(repo.repo_obj, package)

return {'success_flag': True, 'summary': {}, 'details': {}}

Expand Down
Loading

0 comments on commit f48f238

Please sign in to comment.