如何创建安装python依赖项的RPM?

时间:2019-12-18 09:23:23

标签: python-2.7 rpm rpmbuild rpm-spec centos5

我有一个具有flask依赖项的python应用程序。

我所需要做的就是从该应用程序创建一个RPM,并且使用该RPM,我应该能够将依赖项安装到另一台计算机上。

我尝试过的事情

  1. 创建了setup.py文件,
// Libraries that need to be loaded 
#include <stdio.h> 
#include <stdlib.h> 
#include <string.h>
#include <unistd.h>

//function declarations 
int fileLength(char *filename);
void addwords(char* filename, int start, int end);
char* cudaCrypt(char* rawPassword);

//host variables
char *HostEncrypted;
char **HostPasswords;
char **HostEncpasswords;
long HostPassIndex;

__device__ int stringCompare(const char *s1, const char *s2, int size){
    int check = 0;

    for(int i=0; i<size; i++){

        if ( s1[i] == s2[i]){
            check ++;
        }
    }
    if (check == 11){
        return 0;
    } else {
        return 1;   
    }       
}

__global__ void crack(char **DeviceEncPasswords, char *DeviceEncrypted, long DevicePassIndex, int *DevicePermutations){
    //generating a unique ID    
    int id = blockDim.x * blockIdx.x + threadIdx.x;
    //making sure the unique ID is within the index
    printf("here is the 0 element of the dctionary %s", DeviceEncPasswords[0]);
    //printf("\nid = %d and permutations = %d ans the string i am compating to is %s",id,*DevicePermutations,DeviceEncrypted);
    if(id < *DevicePermutations){
        printf("\n\tComparing %s with %s", DeviceEncrypted,DeviceEncPasswords[id]);
        int p = stringCompare(DeviceEncPasswords[id],DeviceEncrypted,11);
        if (p == 0 ){
        DevicePassIndex = id;
        }
    }   
}

int main(int argc, char *argv[] ){
    //check correct number of arguments 
    if (argc != 3){ 
        printf("\tYou have not entered enough arguments\n\tThis requires you to enter the name of the dictionary file to use"); 
    }   
    HostEncrypted = argv[1];

    printf("\n\tThe key you are attempting to break is");
    printf("\n\t%s",HostEncrypted);

    //count how many entries in the dictionary file
    int *permutations = (int*)malloc(sizeof(int));

    permutations[0] = fileLength(argv[2]); 
    printf("\n\t%s contains %d possible passwords\n",argv[2], permutations[0]);

    //allocate memory for array of unencrypted passwords
    HostPasswords = (char**)malloc(sizeof(char*)*permutations[0]);
    for (int e = 0; e < permutations[0]; e++){
        HostPasswords[e] = (char*)malloc(sizeof(char)*5);
    }

    //allocate memory into array of unencrypted passwords
    HostEncpasswords = (char**)malloc(sizeof(char*)*permutations[0]);
    for (int e = 0; e < permutations[0]; e++){
        HostEncpasswords[e] = (char*)malloc(sizeof(char)*10);
    }

    //add the words from the dictionary to the list 
    addwords(argv[2],0,permutations[0]); 

    printf("\nadded the raw passwords to the array");
    //populate array of encrypted passwords
    for (int r = 0; r < permutations[0]; r++){
        memcpy(HostEncpasswords[r], cudaCrypt(HostPasswords[r]),11);
    }
    printf("\nadded the enc passwords to the array");

    //printf("\n\tplain text = %s and encypted = %s",HostPasswords[permutations-1], HostEncpasswords[permutations-1]);

    //create device variables
    char **DeviceEncPasswords;
    char *DeviceEncrypted;
    long DevicePassIndex;
    int *DevicePermutations;

    //allocated memory on the GPU
    cudaMalloc((void**) &DeviceEncPasswords, ((sizeof(char)*11)*permutations[0]));
    cudaMalloc((void**) &DeviceEncrypted, ((sizeof(char)*11)));
    cudaMalloc((void**) &DevicePassIndex, (sizeof(long)));
    cudaMalloc((void**) &DevicePermutations, (sizeof(int)));

    //copy the data to the GPU
    cudaMemcpy(DeviceEncrypted, HostEncrypted, sizeof(char)*11, cudaMemcpyHostToDevice);
    cudaMemcpy(DeviceEncPasswords, HostEncpasswords, ((sizeof(char)*11)*permutations[0]), cudaMemcpyHostToDevice);
    cudaMemcpy(&DevicePassIndex, &HostPassIndex, sizeof(long), cudaMemcpyHostToDevice);
    cudaMemcpy(DevicePermutations, permutations, sizeof(int), cudaMemcpyHostToDevice);

    crack<<<300,300>>>(DeviceEncPasswords,DeviceEncrypted,DevicePassIndex,DevicePermutations);

    cudaDeviceSynchronize();

    cudaMemcpy(&HostPassIndex, &DevicePassIndex,sizeof(long),cudaMemcpyDeviceToHost);

    printf("\n\tThe cracked password is %s\n",HostPasswords[HostPassIndex]);
}
/* Function to get the length of the file, by counting the new line characters */ 
int fileLength(char *filename) { 
    int length = 0; 
    FILE *myFile; 
    myFile = fopen(filename, "r"); 
    while(!feof(myFile)) { 
        int ch = fgetc(myFile); 
            if(ch == '\n'){ 
                length++; 
            } 
        } 
    fclose(myFile); 
    return length; 
}

//Function to add the entries in the file to the dictionary list
void addwords(char* filename, int start, int end){ 
    FILE *myFile; 
    myFile = fopen(filename,"r"); 
        for(int i = start; i < end; i++){ 
            fscanf(myFile, "%s",HostPasswords[i]);
        } 
    fclose(myFile); 
}

//given crypt password function
char* cudaCrypt(char* rawPassword){

    static char newPassword[11]; //use static as a local pointer should not be returned

    newPassword[0] = rawPassword[0] + 2;
    newPassword[1] = rawPassword[0] - 2;
    newPassword[2] = rawPassword[0] + 1;
    newPassword[3] = rawPassword[1] + 3;
    newPassword[4] = rawPassword[1] - 3;
    newPassword[5] = rawPassword[1] - 1;
    newPassword[6] = rawPassword[2] + 2;
    newPassword[7] = rawPassword[2] - 2;
    newPassword[8] = rawPassword[3] + 4;
    newPassword[9] = rawPassword[3] - 4;
    newPassword[10] = '\0';

    for(int i =0; i<10; i++){
        if(i >= 0 && i < 6){ //checking all lower case letter limits
            if(newPassword[i] > 122){
                newPassword[i] = (newPassword[i] - 122) + 97;
            }else if(newPassword[i] < 97){
                newPassword[i] = (97 - newPassword[i]) + 97;
            }
        }else{ //checking number section
            if(newPassword[i] > 57){
                newPassword[i] = (newPassword[i] - 57) + 48;
            }else if(newPassword[i] < 48){
                newPassword[i] = (48 - newPassword[i]) + 48;
            }
        }
    }
    return newPassword;
}```

  1. 运行该命令

    setup( name='sample-package', version='1.0.0.0', author="Niranj Rajasekaran", author_email="nrajasekaran@test.com", package_dir={'': 'src/py'}, namespace_packages=['main'], packages=find_packages('src/py/'), install_requires=['Flask'] )

  2. python setup.py bdist_rpm中有两个RPM,一个是noarch,另一个是src

  3. 我尝试使用此方法安装noarch rpm

    dist/

我能够在yum install {generated-file}.rpm中获得sample-package-1.0.0.0.egg文件,但不能在烧瓶中找到。

两个问题,

  1. 我的方法正确吗?
  2. 如果是的话,我缺少什么?

1 个答案:

答案 0 :(得分:1)

bdist_rpm缺少很多功能,并且IMO维护得不好。例如。 pyp2rpm更好地转换了现有的PYPI模块。但是您的模块似乎不在PYPI上,因此您需要手动将其指定为bdist_rpm,因为它无法从setup.py检索此信息。

运行:

  python setup.py bdist_rpm --requires python-flask

这将产生一个需要python-flask软件包的rpm文件。对于较新的RHEL / Fedora,它将为python3-flask