Ejemplo n.º 1
0
def from_unicode(scm_unicode):
    """
    Import scm data from unicode string.

    Strings return from Django model are all unicode. So it will be much
    easier to only deal with unicode string.
    """
    # 1.parse
    rawdata = parse_blocks(scm_unicode, MAPPING)

    # 2.extract and transform
    uc = build_user_cache(rawdata)
    users = transform_users(uc.all())

    (
        domains,
        subdomains,
        domainroles,
        subdomainroles,
        domainrole_users,
        subdomainrole_users,
    ) = transform_domains(rawdata, uc)

    (
        trees,
        tree_licenses,
        treeroles,
        treerole_users,
    ) = transform_trees(rawdata, uc)

    # 3.load
    loader = get_default_loader()
    loader.sync_entity(users, User)
    delete_domains = loader.sync_entity(domains, Domain)
    delete_subdomains = loader.sync_entity(subdomains, SubDomain)
    delete_domainroles = loader.sync_entity(domainroles, DomainRole)
    delete_subdomainroles = loader.sync_entity(subdomainroles, SubDomainRole)
    delete_trees = loader.sync_entity(trees, GitTree)
    delete_treeroles = loader.sync_entity(treeroles, GitTreeRole)

    loader.sync_nnr(domainrole_users, DomainRole, User)
    loader.sync_nnr(subdomainrole_users, SubDomainRole, User)
    loader.sync_nnr(tree_licenses, GitTree, License)
    loader.sync_nnr(treerole_users, GitTreeRole, User)

    delete_treeroles()
    delete_subdomainroles()
    delete_domainroles()
    delete_trees()
    delete_subdomains()
    delete_domains()
Ejemplo n.º 2
0
def from_dir(prod, prod_path):
    """
    Load snapshot related data into database, which includes project-trees
    relationship, trees-packages relationship and images.
    """
    # 1.transform
    (products_trees, packages, trees_packages,
     images) = transform(prod, prod_path)

    # 2.load
    loader = get_default_loader()
    loader.sync_entity(packages, Package)
    loader.sync_entity(images, Image)

    loader.sync_nnr(products_trees, Product, GitTree, remove=False)
    loader.sync_nnr(trees_packages, GitTree, Package, remove=False)
Ejemplo n.º 3
0
def from_dir(prod, prod_path):
    """
    Load snapshot related data into database, which includes project-trees
    relationship, trees-packages relationship and images.
    """
    # 1.transform
    (products_trees,
     packages, trees_packages,
     images) = transform(prod, prod_path)

    # 2.load
    loader = get_default_loader()
    loader.sync_entity(packages, Package)
    loader.sync_entity(images, Image)

    loader.sync_nnr(products_trees, Product, GitTree, remove=False)
    loader.sync_nnr(trees_packages, GitTree, Package, remove=False)
Ejemplo n.º 4
0
def from_unicode(scm_unicode):
    """
    Import scm data from unicode string.

    Strings return from Django model are all unicode. So it will be much
    easier to only deal with unicode string.
    """
    # 1.parse
    rawdata = parse_blocks(scm_unicode, MAPPING)

    # 2.extract and transform
    uc = build_user_cache(rawdata)
    users = transform_users(uc.all())

    (domains, subdomains,
     domainroles, subdomainroles,
     domainrole_users, subdomainrole_users,
     ) = transform_domains(rawdata, uc)

    (trees, tree_licenses,
     treeroles, treerole_users,
     ) = transform_trees(rawdata, uc)


    # 3.load
    loader = get_default_loader()
    loader.sync_entity(users, User)
    delete_domains = loader.sync_entity(domains, Domain)
    delete_subdomains = loader.sync_entity(subdomains, SubDomain)
    delete_domainroles = loader.sync_entity(domainroles, DomainRole)
    delete_subdomainroles = loader.sync_entity(subdomainroles, SubDomainRole)
    delete_trees = loader.sync_entity(trees, GitTree)
    delete_treeroles = loader.sync_entity(treeroles, GitTreeRole)

    loader.sync_nnr(domainrole_users, DomainRole, User)
    loader.sync_nnr(subdomainrole_users, SubDomainRole, User)
    loader.sync_nnr(tree_licenses, GitTree, License)
    loader.sync_nnr(treerole_users, GitTreeRole, User)

    delete_treeroles()
    delete_subdomainroles()
    delete_domainroles()
    delete_trees()
    delete_subdomains()
    delete_domains()