示例#1
0
文件: main.cpp 项目: Deledrius/Plasma
void FindPackages(std::vector<plFileName>& fileNames, std::vector<plFileName>& pathNames, const plFileName& path, const ST::string& parent_package=ST::null)
{
    std::vector<plFileName> packages;
    FindSubDirs(packages, path);
    for (int i = 0; i < packages.size(); i++)
    {
        ST::string packageName;
        if (!parent_package.is_empty())
            packageName = parent_package + ".";
        packageName += packages[i].AsString();
        std::vector<plFileName> packageFileNames;
        std::vector<plFileName> packagePathNames;
        plFileName packagePath = plFileName::Join(path, packages[i]);
        FindFiles(packageFileNames, packagePathNames, packagePath);

        // Check for the magic file to make sure this is really a package...
        if (std::find(packageFileNames.begin(), packageFileNames.end(), kModuleFile) != packageFileNames.end()) {
            for (int j = 0; j < packageFileNames.size(); j++) {
                fileNames.push_back(packageName+"."+packageFileNames[j].AsString());
                pathNames.push_back(packagePathNames[j]);
            }
            FindPackages(fileNames, pathNames, packagePath, packageName);
        }
    }
}
示例#2
0
static void AddPackage(PackagePattern *pattern)
{
    fprintf(stderr, "Trying to install all packages matching pattern %s\n", SerializePackagePattern(pattern));

    Rlist *matching_available = FindPackages(AVAILABLE_PACKAGES_FILE_NAME, pattern);

    if (matching_available == NULL)
    {
        fprintf(stderr, "Unable to find any package matching %s\n", SerializePackagePattern(pattern));
        exit(1);
    }

    Rlist *rp;

    for (rp = matching_available; rp; rp = rp->next)
    {
        Package *p = (Package *) rp->item;

        PackagePattern *pat = MatchAllVersions((Package *) rp->item);

        if (FindPackages(INSTALLED_PACKAGES_FILE_NAME, pat) != NULL)
        {
            fprintf(stderr, "Package %s is already installed.\n", SerializePackage(p));
            exit(1);
        }
    }

    Rlist *installed_packages = ReadPackageEntries(INSTALLED_PACKAGES_FILE_NAME);

    for (rp = matching_available; rp; rp = rp->next)
    {
        Package *p = (Package *) rp->item;

        RlistAppendAlien(&installed_packages, p);
        fprintf(stderr, "Succesfully installed package %s\n", SerializePackage(p));
    }

    SavePackages(INSTALLED_PACKAGES_FILE_NAME, installed_packages);
    exit(0);
}
示例#3
0
static void AddPackage(PackagePattern *pattern)
{
    fprintf(stderr, "Trying to install all packages matching pattern %s\n", SerializePackagePattern(pattern));

    Seq *matching_available = FindPackages(AVAILABLE_PACKAGES_FILE_NAME, pattern);

    if (SeqLength(matching_available) == 0)
    {
        fprintf(stderr, "Unable to find any package matching %s\n", SerializePackagePattern(pattern));
        exit(EXIT_FAILURE);
    }

    for (size_t i = 0; i < SeqLength(matching_available); i++)
    {
        Package *p = SeqAt(matching_available, i);

        PackagePattern *pat = MatchAllVersions(p);

        if (SeqLength(FindPackages(INSTALLED_PACKAGES_FILE_NAME, pat)) > 0)
        {
            fprintf(stderr, "Package %s is already installed.\n", SerializePackage(p));
            exit(EXIT_FAILURE);
        }
    }

    Seq *installed_packages = ReadPackageEntries(INSTALLED_PACKAGES_FILE_NAME);

    for (size_t i = 0; i < SeqLength(matching_available); i++)
    {
        Package *p = SeqAt(matching_available, i);

        SeqAppend(installed_packages, p);
        fprintf(stderr, "Successfully installed package %s\n", SerializePackage(p));
    }

    SavePackages(INSTALLED_PACKAGES_FILE_NAME, installed_packages);
    exit(EXIT_SUCCESS);
}
示例#4
0
static void PopulateAvailable(const char *arg)
{
    Package *p = DeserializePackage(arg);
    PackagePattern *pattern = MatchSame(p);

    if (FindPackages(AVAILABLE_PACKAGES_FILE_NAME, pattern) != NULL)
    {
        fprintf(stderr, "Skipping already available package %s\n", SerializePackage(p));
        return;
    }

    Rlist *available_packages = ReadPackageEntries(AVAILABLE_PACKAGES_FILE_NAME);

    RlistAppendAlien(&available_packages, p);
    SavePackages(AVAILABLE_PACKAGES_FILE_NAME, available_packages);
}
示例#5
0
文件: main.cpp 项目: Deledrius/Plasma
void PackDirectory(const plFileName& dir, const plFileName& rootPath, const plFileName& pakName, std::vector<plFileName>& extraDirs, bool packSysAndPlasma = false)
{
    ST::printf("\nCreating {} using the contents of {}\n", pakName, dir);
    ST::printf("Changing working directory to {}\n", rootPath);
    if (!plFileSystem::SetCWD(rootPath))
    {
        ST::printf("ERROR: Directory change to {} failed for some reason\n", rootPath);
        fputs("Unable to continue with the packing of this directory, aborting...\n", stdout);
        return;
    }
    else
        ST::printf("Directory changed to {}\n", rootPath);

    std::vector<plFileName> fileNames;
    std::vector<plFileName> pathNames;

    FindFiles(fileNames, pathNames, dir);
    FindPackages(fileNames, pathNames, dir);
    if (packSysAndPlasma)
    {
        fputs("Adding the system and plasma directories to this pack file\n", stdout);
        plFileName tempPath;
        tempPath = plFileName::Join(dir, "system");
        FindFiles(fileNames, pathNames, tempPath);
        FindPackages(fileNames, pathNames, tempPath);
        tempPath = plFileName::Join(dir, "plasma");
        FindFiles(fileNames, pathNames, tempPath);
        FindPackages(fileNames, pathNames, tempPath);
    }


    // ok, we know how many files we're gonna pack, so make a fake index (we'll fill in later)
    hsUNIXStream s;
    if (!s.Open(pakName, "wb"))
        return;

    s.WriteLE32(fileNames.size());

    int i;
    for (i = 0; i < fileNames.size(); i++)
    {
        s.WriteSafeString(fileNames[i].AsString());
        s.WriteLE32(0);
    }

    PythonInterface::initPython(rootPath);
    for (i = 0; i < extraDirs.size(); i++)
        PythonInterface::addPythonPath(plFileName::Join(rootPath, extraDirs[i]));

    // set to maximum optimization (includes removing __doc__ strings)
    Py_OptimizeFlag = 2;

    std::vector<uint32_t> filePositions;
    filePositions.resize(fileNames.size());

    for (i = 0; i < fileNames.size(); i++)
    {
        // strip '.py' from the file name
        plFileName properFileName = fileNames[i].StripFileExt();
        uint32_t initialPos = s.GetPosition();
        WritePythonFile(properFileName, pathNames[i], &s);
        uint32_t endPos = s.GetPosition();

        filePositions[i] = initialPos;
    }

    s.SetPosition(sizeof(uint32_t));
    for (i = 0; i < fileNames.size(); i++)
    {
        s.WriteSafeString(fileNames[i].AsString());
        s.WriteLE32(filePositions[i]);
    }

    s.Close();

    PythonInterface::finiPython();
}