Esempio n. 1
0
def process_package(repopath, filepath, filename):
    package_meta = {}
    # Extracting metadata
    package_process.uncompress_package(filepath, filename)
    package_meta = package_process.extract_package_metadata(filename)
    packages_metadata[package_meta["name"]] = package_meta

    # Moving package to directory
    l1 = filename[0]
    l2 = filename[1]
    if not os.path.exists(repopath + "/" + l1 + "/" + l2):
        os.makedirs(repopath + "/" + l1 + "/" + l2)
    shutil.move(repopath + "/incoming/" + filename, repopath + "/" + l1 + "/" + l2)
        
    # Cleaning up...
    package_process.cleanup(filename)
Esempio n. 2
0
def update_repo(repopath):
    older_packages = []
    equal_packages = []

    os.chdir(repopath)
    
    # Read current repository metadata
    print "Reading repository index file..."
    repoindex_file = open("repoindex")
    repoindex = repoindex_file.read().split('\n')
    repoindex_file.close()
    repoindex_file = open("repoindex", "w")
    
    print "Reading packages metadata file..."
    packages_metadata_file = open("packages_meta")
    packages_metadata = packages_metadata_file.read()
    packages_metadata = json.loads(packages_metadata)
    packages_metadata_file.close()
    packages_metadata_file = open("packages_meta", "w")
    
    # Getting package listing in incoming
    filelist = glob.glob("incoming/*.xpkg")
    
    for file in filelist:
        filename = file.split('/')[-1:][0]
        filepath = "/".join(file.split('/')[:-1])
        print "\nProcessing package", filename, "..."
        
        # Extracting metadata
        package_process.uncompress_package(filepath, filename)
        package_meta = package_process.extract_package_metadata(filename)
        
        
        # Checking package metadata
        # TODO: checks for 'rm -rf /' and similar
        if package_meta["name"] in packages_metadata:
            print "* Checking version..."
            version_state = package_process.compare_package_versions(packages_metadata[package_meta["name"]]["version"], packages_metadata[package_meta["name"]]["build"], package_meta["version"], package_meta["build"])
            
            # version_state == 2 only if new package is older, than package in repository.
            # Therefore we adding package name to list for future output and actions (maybe?)
            if version_state == 2:
                print "! This package is older that package in repository. Ignoring..."
                older_packages.append(package_meta["name"])
            
            # version_state == 1 only if new package version and package version in repository is equal.
            # Therefore we adding package name to list for future output and actions (maybe?)
            elif version_state == 1:
                print "! This package and package in repository have equal versions and builds. Ignoring..."
                equal_packages.append(package_meta["name"])
                
            # version_state == 0. This means that new package is newer, than package in repository.
            # Replacing older package metadata with new and changing file path in index file.
            else:
                print "o This package is newer, that package in repo. Updating..."
                process_package(repopath, filepath, filename)
                # Creating string of old package path for replacement
                oldpackage = packages_metadata[package_meta["name"]]["name"][0] + "/" + packages_metadata[package_meta["name"]]["name"][1] + "/" + packages_metadata[package_meta["name"]]["name"] + "-" + packages_metadata[package_meta["name"]]["version"] + "-" + packages_metadata[package_meta["name"]]["arch"] + "-" + str(packages_metadata[package_meta["name"]]["build"]) + ".xpkg"
                fileindex = repoindex.index(str(oldpackage))
                l1 = filename[0]
                l2 = filename[1]
                repoindex[fileindex] = l1 + "/" + l2 + "/" + filename
                packages_metadata[package_meta["name"]] = package_meta
                

        else:
            print "* This is a new package. Adding to repository..."
            process_package(repopath, filepath, filename)
            packages_metadata[package_meta["name"]] = package_meta
            l1 = filename[0]
            l2 = filename[1]
            repoindex.append(l1 + "/" + l2 + "/" + filename)
    
    # Cleaning up a bit...
    junkfail = False
    while True:
        if junkfail:
            break
        try:
            junk = repoindex.index("")
            repoindex.pop(junk)
        except:
            junkfail = True
    # Writing metadata
    packages_metadata_file.write(json.dumps(packages_metadata, indent=4))
    repoindex_file.write("\n".join(repoindex))
    packages_metadata_file.close()
    repoindex_file.close()
    print "Compressing packages metadata..."
    os.system("xz --compress --keep --force packages_meta")
    print "Medatada compressed."