def createPreProject(userId, projectId, projectName, projectType): pjHome = '' if config.dir_home_user != "": pjHome = config.dir_home + "/" + config.dir_home_user + '/' + str( userId) + '/system' else: pjHome = config.dir_home + '/' + str(userId) + '/system' if not os.path.exists(pjHome): os.makedirs(pjHome) shell.execute('cp ' + config.file_system_readme + ' ' + pjHome + '/') path = config.dir_home_user + '/' + str(userId) + '/system/' + str( projectId) + '/1' # 1--version of pj, vesionInit=1 dir = config.dir_home + path if (fileManager.createDir(dir)): notebook = fileManager.createProject(dir, projectId, projectName, projectType, path) sysout.log(TAG, "first project = " + str(notebook)) return notebook return 'System can not create user dir of -- ' + dir
def deleteFile(path): try: if os.path.exists(path): d = shell.execute('rm -r ' + path) print("d ======== ") print(d) return (1, 'Delete Sccess!') else: return (2, 'File not exists!') except Exception as e: return (0, 'Delete Failed, cause: ' + e)
def createProject(path, projectId, projectName, type, filePath): notebook = config.getNotebook(type) if notebook is not None: nb = notebook.get("nb") h5 = notebook.get("h5") py = notebook.get('py') shell.execute('cp ' + nb + ' ' + path + '/') shell.execute('cp ' + h5 + ' ' + path + '/') shell.execute('cp ' + py + ' ' + path + '/') shell.execute('cp ~/.jupyter/custom/custom.css ' + path + '/') # if projectId != None: # shell.execute('mv ' + config.getNotebookName() + ' ' + str(projectId) + '.ipynb') # shell.execute('mv ' + config.getH5Name() + ' ' + str(projectId) + '.ipynb') jupyter.executingNb(path, config.getNotebookName(), type) return { 'projectId': projectId, 'projectName': projectName, 'projectType': type, 'version': 1, 'notebook': config.ns_doname + '/notebooks/storage' + filePath + '/' + config.getNotebookName(), 'html': config.ns_doname + '/notebooks/storage' + filePath + '/' + config.getH5Name(), 'py': config.ns_doname + '/notebooks/storage' + filePath + '/' + config.getPYName() # 'notebook': config.ns_doname + '/notebooks' + filePath + '/' + config.getNotebookName(), # 'html': config.ns_doname + '/notebooks' + filePath + '/' + config.getH5Name(), # 'py': config.ns_doname + '/notebooks' + filePath + '/' + config.getPYName() } else: return None
def createNewVersion(userId, projectId, projectName, versionCur): (exist, result) = checkVersion(userId, projectId, versionCur) if not exist: return result maxVersion = result curPath = config.dir_home_user + '/' + str(userId) + '/system/' + str( projectId) + '/' + str(versionCur) curNb = config.dir_home + curPath + '/' + config.getNotebookName() curH5 = config.dir_home + curPath + '/' + config.getH5Name() curPY = config.dir_home + curPath + '/' + config.getPYName() version = maxVersion + 1 path = config.dir_home_user + '/' + str(userId) + '/system/' + str( projectId) + '/' + str(version) dir = config.dir_home + path if (fileManager.createDir(dir)): print(config.dir_home + curPath) if not os.path.exists(config.dir_home + curPath): return resp_err_version_old_err else: shell.execute('cp ' + curNb + ' ' + dir + '/') shell.execute('cp ' + curH5 + ' ' + dir + '/') shell.execute('cp ' + curPY + ' ' + dir + '/') return { 'projectId': projectId, 'projectName': projectName, 'version': version, 'notebook': config.ns_doname + '/notebooks' + path + '/' + config.getNotebookName(), 'html': config.ns_doname + '/notebooks' + path + '/' + config.getH5Name(), 'py': config.ns_doname + '/notebooks' + path + '/' + config.getPYName() } else: return resp_err_version_create_dir_err
def start(): shell.execute('jupyter notebook --port ' + config.ns_port + ' --no-browser')
def convertNb(form, nbName): if form is None: # form = 'HTML' shell.execute('jupyter nbconvert ' + nbName) else: shell.execute('jupyter nbconvert --to ' + form + nbName)