Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

addmodels funcion #953

Merged
merged 9 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions installer/constants/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
MODELS_URL = "http://scipion.cnb.csic.es/downloads/scipion/software/em"
SCIPION_FILES_REMOTE_PATH = "scipionfiles/downloads/scipion/software/em"
SCIPION_TESTS_URLS = "http://scipion.cnb.csic.es/downloads/scipion/data/tests"
SCIPION_SOFTWARE_EM = "scipionfiles/downloads/scipion/software/em"

# Other variables
TAB_SIZE = 4
Expand Down
4 changes: 3 additions & 1 deletion installer/constants/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,8 @@
f'./xmipp {MODE_GIT} checkout devel'
],
MODE_ADD_MODEL: [
f'./xmipp {MODE_ADD_MODEL} [email protected] /home/myuser/mymodel'
f'./xmipp {MODE_ADD_MODEL} [email protected] /home/myuser/mymodel',
f'./xmipp {MODE_ADD_MODEL} [email protected] /home/myuser/mymodel --update'

]
}
52 changes: 52 additions & 0 deletions installer/modelsDLTK.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# * Authors: Alberto García ([email protected])
# *
# *
# * This program is free software; you can redistribute it and/or modify
# * it under the terms of the GNU General Public License as published by
# * the Free Software Foundation; either version 2 of the License, or
# * (at your option) any later version.
# *
# * This program is distributed in the hope that it will be useful,
# * but WITHOUT ANY WARRANTY; without even the implied warranty of
# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# * GNU General Public License for more details.
# *
# * You should have received a copy of the GNU General Public License
# * along with this program; if not, write to the Free Software
# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
# * 02111-1307 USA
# *
# * All comments concerning this program package may be sent to the
# * e-mail address '[email protected]'
# ***************************************************************************/

import os, sys
from .utils import runJob
from .constants import SCIPION_SOFTWARE_EM, MODELS_URL
from .logger import blue, red, yellow, logger


def addModels(login: str, modelPath: str, update: bool):
modelPath = modelPath.rstrip("/")
modelName = os.path.basename(modelPath)
modelsDir = os.path.dirname(modelPath)
albertmena marked this conversation as resolved.
Show resolved Hide resolved
update = '--update' if update else ''
tgzFileModel = f"xmipp_model_{modelName}.tgz"
localFileModel = os.path.join(modelsDir, tgzFileModel)
logger(f"Creating the {tgzFileModel} model.",forceConsoleOutput=True)
runJob("tar czf %s %s" % (tgzFileModel, modelName), cwd=modelsDir)
albertmena marked this conversation as resolved.
Show resolved Hide resolved

logger(yellow("Warning: Uploading, please BE CAREFUL! This can be dangerous."),forceConsoleOutput=True)
logger(f'You are going to be connected to {login} to write in folder {SCIPION_SOFTWARE_EM}.',forceConsoleOutput=True)
if input("Continue? YES/no\n").lower() != 'YES':
albertmena marked this conversation as resolved.
Show resolved Hide resolved
sys.exit()

logger("Trying to upload the model using '%s' as login" % login,forceConsoleOutput=True)
args = "%s %s %s %s" % (login, os.path.abspath(localFileModel), SCIPION_SOFTWARE_EM, update)
retCode, log = runJob(f"dist/bin/xmipp_sync_data upload {args}", showCommand=True, showError=True)
if retCode == 0:
logger("'%s' model successfully uploaded! Removing the local .tgz" % modelName)
runJob("rm %s" % localFileModel)
albertmena marked this conversation as resolved.
Show resolved Hide resolved



9 changes: 7 additions & 2 deletions xmipp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python3
# ***************************************************************************
# * Authors: Alberto García ([email protected])
# * Martín Salinas ([email protected])
# * Martín Salinas ([email protected])
# *
# *
# * This program is free software; you can redistribute it and/or modify
Expand Down Expand Up @@ -44,6 +44,7 @@ from installer.main import getSources, exitXmipp, handleRetCode, getSectionMessa
from installer.logger import logger, yellow, red, blue
from installer.api import sendApiPOST
from installer.test import runTests
from installer import modelsDLTK

####################### EXECUTION MODES #######################
def __getProjectRootDir() -> str:
Expand All @@ -63,7 +64,11 @@ def modeAddModel(args: argparse.Namespace):
#### Params:
- args (Namespace): Command line arguments parsed by argparse library.
"""
pass
if not os.path.isdir(args.modelPath):
logger("<modelsPath> is not a directory. Please, check the path. \n"
"The name of the model will be the name of that folder.\n")
else:
modelsDLTK.addModels(login=args.login, modelPath=args.modelPath, update=args.update)

def modeCleanBin():
"""
Expand Down
Loading