Esempio n. 1
0
def modifyRESTServer(Module):
    logging.debug('Performing the RESTServer file modification for module ' +
                  Module)
    i = config.importer()
    try:
        suffix = str(datetime.datetime.now())  # Get the timestamp as suffix
        suffix = suffix.replace(':', '')  # Just remove unsupported character
        suffix = suffix.replace(' ', '')  # for file name
        rollbackName = 'RESTServer_' + suffix + '.py'

        if not os.path.exists(
                i.rollbackPath):  # Create the directory if not exist yet
            os.makedirs(i.rollbackPath)

        shutil.move('RESTServer.py', os.path.join(
            i.rollbackPath,
            rollbackName))  # Moving the original file to rollback folder

        #fin = open(os.path.join(i.rollbackPath,rollbackName),'r')               # Open the original file
        fout = open('RESTServer.py', 'w')  # Open the new file
        fout.write('import sys\n')  # To be sure sys is defined before use it
        fout.write('sys.path.append ("Modules/' + Module +
                   '")\n')  # Add the new path as PYTHONPATH
        fout.write('import ' + Module +
                   ' \n')  # Write the new import line in the new file

        # Open the RESTServer.py file in a list and remove the import line
        lines = [
            line.rstrip('\n')
            for line in open(os.path.join(i.rollbackPath, rollbackName))
        ]

        for line in lines:
            if (line != 'import sys'):
                fout.write(line + '\n')

        fout.close()

        #Adding the new Module in the PYTHONPATH sysvar
        sys.path.append('Modules/' + Module)

        logging.debug(
            'Modification of the RESTServer.py file done correctly. The original file was saved as '
            + rollbackName)
        return [1, rollbackName]
    except Exception:
        logging.exception(
            'Error while modifying the RESTServer.py file for module ' +
            Module)
        raise
def modifyRESTServer(Module):
    logging.debug('Performing the RESTServer file modification for module '+Module)
    i = config.importer()
    try:
        suffix=str(datetime.datetime.now())                                      # Get the timestamp as suffix
        suffix = suffix.replace(':','')                                          # Just remove unsupported character
        suffix = suffix.replace(' ','')                                          # for file name
        rollbackName = 'RESTServer_'+suffix+'.py'

        if not  os.path.exists(i.rollbackPath):                                  # Create the directory if not exist yet
            os.makedirs(i.rollbackPath)

        shutil.move('RESTServer.py',os.path.join(i.rollbackPath,rollbackName))   # Moving the original file to rollback folder

        #fin = open(os.path.join(i.rollbackPath,rollbackName),'r')               # Open the original file
        fout = open('RESTServer.py','w')                                         # Open the new file
        fout.write('import sys\n')                                               # To be sure sys is defined before use it
        fout.write('sys.path.append ("Modules/'+Module+'")\n')                   # Add the new path as PYTHONPATH
        fout.write('import '+Module+' \n')                                       # Write the new import line in the new file

        # Open the RESTServer.py file in a list and remove the import line
        lines = [line.rstrip('\n') for line in open(os.path.join(i.rollbackPath,rollbackName))]

        for line in lines:
            if(line != 'import sys'):
                fout.write(line+'\n')

        fout.close()

        #Adding the new Module in the PYTHONPATH sysvar
        sys.path.append('Modules/'+Module)

        logging.debug('Modification of the RESTServer.py file done correctly. The original file was saved as '+rollbackName)
        return [1, rollbackName]
    except Exception:
        logging.exception('Error while modifying the RESTServer.py file for module '+Module)
        raise
Esempio n. 3
0
import zipfile, os.path
import sys
import os
import config
import shutil
import datetime
import logging
import argparse
import urllib.request
import time

c = config.ImportModule()
i = config.importer()
modules = []
ModProp = {}
importedModules = {}

# Logging definition
log = config.Log
logging.basicConfig(filename=log.flog, format=log.format, level=log.level)
'''
    This function download the TarBall Module file directly from GitHub
'''


def downloadFromGitHub(moduleName):
    logging.debug('Downloading Module ', moduleName)
    try:
        if not os.path.exists(
                'cash/Modules/'):  # Create the directory if not exist yet
            os.makedirs('cash/Modules/')
import zipfile,os.path
import sys
import os
import config
import shutil
import datetime
import logging
import argparse
import urllib.request
import time

c = config.ImportModule()
i = config.importer()
modules = []
ModProp = {}
importedModules = {}



# Logging definition
log=config.Log
logging.basicConfig(filename=log.flog, format=log.format, level=log.level)


'''
    This function download the TarBall Module file directly from GitHub
'''
def downloadFromGitHub(moduleName):
    logging.debug('Downloading Module ',moduleName)
    try:
        if not  os.path.exists('cash/Modules/'):                                          # Create the directory if not exist yet