Skip to content

Commit

Permalink
saving current files on Della
Browse files Browse the repository at this point in the history
  • Loading branch information
vineetbansal committed Apr 23, 2024
1 parent 5836eb4 commit 95b7f70
Show file tree
Hide file tree
Showing 198 changed files with 54,141 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ template/*
*.swp
__pycache__/
*.pyc
.ipynb_checkpoints/
236 changes: 236 additions & 0 deletions PythonSubmitDella/guiHelper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,236 @@
#!/usr/bin/python

# guiHelper has functions that help build the gui and connect to della. The functions are called by submitWorm analysis codes.
#


try:
import Tkinter as tk
import tkFileDialog
except ImportError:
import tkinter as tk
import tkinter.filedialog as tkFileDialog
import paramiko
import socket
import os
import pickle
import getpass


#server jobs willb e submitted to
SERVER ='della.princeton.edu'
#location of the ssh key file shared by lefierdata
KEYPATH='/tigress/LEIFER/.ssh/id_rsa'

#load the pickle files for default values to put into fields. The pickle files store your previous entries in the pickles2.p file in ~.
def pickle_load():
# get ready for pickled variables
pickle_path = (os.path.expanduser('~') + "/platypusTemp/")
pickle_file = pickle_path + "pickles2.p"
if not os.path.exists(pickle_path):
os.makedirs(pickle_path)

if not os.path.exists(pickle_file):
storedUsername = { "username": getpass.getuser() }
pickle.dump( storedUsername, open(pickle_file, "wb" ) )

# return the dictionary with all previous values stored.
try:
prevUser = pickle.load( open( pickle_file, "rb" ) )
except:
prevUser = {'username': getpass.getuser()}


#fill in default values
if 'username' not in prevUser:
prevUser['username'] = "USER"
if 'time' not in prevUser:
prevUser['time'] = "180"
if 'mem' not in prevUser:
prevUser['mem'] = "16000"
if 'date' not in prevUser:
prevUser['date'] = "testing_sets"
if 'folderName' not in prevUser:
prevUser['folderName'] = "Brain_working_dataset"
if 'frameNumber' not in prevUser:
prevUser['frameNumber'] = "1000"
if 'refNumber' not in prevUser:
prevUser['refNumber'] = "100"
if 'neuronNumber' not in prevUser:
prevUser['neuronNumber'] = "150"
if 'checkNumber' not in prevUser:
prevUser['checkNumber'] = "500"
if 'matlab_command' not in prevUser:
prevUser['matlab_command']='Put your code here!'
if 'code_path' not in prevUser:
prevUser['code_path']='Put the path to the .path file here!'


return prevUser


#read the submissionParameters.txt file in the data folder to get the number of frames.
def get_nframes(client,fullPath):

print('Getting number of frames from GUI')
subDataFile = fullPath + '/submissionParameters.txt'
client2 = client.open_sftp()
sub_data={}
# read each line, saving key-values pairs into a dictionary
try:
with client2.open(subDataFile) as remote_file:
for lines in remote_file:
lines=lines.split(" ")
print(lines)
sub_data[lines[0]]=lines[1]
except Exception:
raise NameError("Remote File not found")

if sub_data.get('NFrames') != None:
print('Getting number of frames from Remote')
NFrames=sub_data['NFrames']
return NFrames
else:
raise NameError("Cannot connect to get number of Frames")


def dellaConnect(username,password=None):
#use the username to connect to della, if password is provided, use it, otherwise, use ssh keys
if socket.gethostname()=='tigressdata.princeton.edu':
#if on tigressdata, use path to key file file in /tigress/LEIFEr
key = paramiko.RSAKey.from_private_key_file(KEYPATH)
elif socket.gethostname()=='tigressdata2.princeton.edu':
#key = paramiko.RSAKey.from_private_key_file(KEYPATH)
key = paramiko.RSAKey.from_private_key_file("/home/"+username+"/.ssh/id_rsa")
else:
key = None
# connect and submit job via sbatch
client = paramiko.SSHClient()
client.load_system_host_keys()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
if not password:
client.connect(SERVER, 22, username,pkey=key)
else:
try:
client.connect(SERVER, 22, username, password)
except Exception:
raise Exception('Cannont connect, problem with username password combo')
return client

def passwordReqCheck(username):
# check if a password is required for a given username
# try to see if a password is needed
try:
dellaConnect(username)
isNeedsPassword = False
except paramiko.AuthenticationException:
isNeedsPassword = True
return isNeedsPassword

def selectFolder(master=None):
# select a folder using a popup window
folder=tkFileDialog.askdirectory(mustexist=False , initialdir= '/tigress/LEIFER/PanNeuronal/')
if folder:
#parse the folder path and populate the filed on the gui.
path,folderName=os.path.split(folder)
path,date=os.path.split(path)
master.e['parent_path'].delete(0,tk.END)
master.e['parent_path'].insert(0,path)
master.e['date'].delete(0,tk.END)
master.e['date'].insert(0,date)
master.e['folder_name'].delete(0,tk.END)
master.e['folder_name'].insert(0,folderName)
print(folder)

def selectPath(master=None):
filename = tkFileDialog.askopenfilename(initialdir= '/tigress/LEIFER/communalCode/ ')
master.e['code_path'].delete(0,tk.END)
master.e['code_path'].insert(0,filename)
#
# #class for building the gui and populating the rows
class submitTK(tk.Tk):
#build the gui with some number of max rows and cols,
#submitTK is a subclass of tkinter's Tk().
def __init__(self, rows=10, cols=2):

tk.Tk.__init__(self)
#build rows and cols
for i in range(rows):
self.columnconfigure(i,pad=3)
for j in range(cols):
self.rowconfigure(j, pad=3)
# make counter for the row being populated
self.row_count=0
# self.e will have all the values of the rows stored
self.e=dict()

self.title("Options")

# add a text row to the field, the row will have a text label,
# row is added to the next open row.
# field name for using in the e,
# default field entry
# show, for passwords, use '*'

def addGuiField(self,label,name,default="",show=None):
master_label = tk.Label(self, text=label)
master_label.grid(row=self.row_count, column=0,sticky=tk.W+tk.E)
self.e[name] = tk.Entry(self,show=show)
self.e[name].insert(0, default)
self.e[name].grid(row=self.row_count, column=1,sticky=tk.W+tk.E)
self.row_count+=1

# make checkbox, again with label and field name
def addGuiCheck(self,label,name,default=1):
master_label = tk.Label(self, text=label)
master_label.grid(row=self.row_count, column=0, sticky=tk.W+tk.E)
var1= tk.IntVar()
self.e[name]= tk.Checkbutton(self, text=None, variable=var1)
self.e[name].var = var1
self.e[name].grid(row=self.row_count, column=1,sticky=tk.W+tk.E)
self.e[name].var.set(default)
self.row_count+=1

# add a button with a text label and a function callback handle.
def addGuiButton(self,label,b_command=None):
self.b = tk.Button(self, text=label, width=10, command=b_command)
self.b.grid(row=self.row_count,columnspan=2,sticky=tk.W+tk.E)
self.row_count+=1

#save values fo fields for defaults during next call
def pickleDump(self):
pickle_path = (os.path.expanduser('~') + "/platypusTemp/")
pickle_file = pickle_path + "pickles2.p"
prevUser=pickle_load()
#refill prevUser dict with master entries
if 'user_name' in self.e:
prevUser['username']=self.e['user_name'].get()
if 'time' in self.e:
prevUser['time']=self.e['time'].get()
if 'mem' in self.e:
prevUser['mem']=self.e['mem'].get()
if 'date' in self.e:
prevUser['date'] = self.e['date'].get()
if 'folder_name' in self.e:
prevUser['folderName']=self.e['folder_name'].get()
if 'nframes' in self.e:
prevUser['frameNumber']=self.e['nframes'].get()
if 'n_ref' in self.e:
prevUser['refNumber']=self.e['n_ref'].get()
if 'n_neurons' in self.e:
prevUser['neuronNumber']=self.e['n_neurons'].get()
if 'n_checks' in self.e:
prevUser['checkNumber']=self.e['n_checks'].get()
if 'matlab_command' in self.e:
prevUser['matlab_command']=self.e['matlab_command'].get()
if 'code_path' in self.e:
prevUser['code_path']=self.e['code_path'].get()

#save prevUser as pickle
pickle.dump(prevUser, open(pickle_file, "wb" ) )


# run the main loop.
def run(self):
tk.mainloop()

143 changes: 143 additions & 0 deletions PythonSubmitDella/paramiko/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
# Copyright (C) 2003-2011 Robey Pointer <[email protected]>
#
# This file is part of paramiko.
#
# Paramiko is free software; you can redistribute it and/or modify it under the
# terms of the GNU Lesser General Public License as published by the Free
# Software Foundation; either version 2.1 of the License, or (at your option)
# any later version.
#
# Paramiko 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 Lesser General Public License for more
# details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with Paramiko; if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.

# flake8: noqa
import sys
from paramiko._version import __version__, __version_info__
from paramiko.transport import SecurityOptions, Transport
from paramiko.client import (
SSHClient,
MissingHostKeyPolicy,
AutoAddPolicy,
RejectPolicy,
WarningPolicy,
)
from paramiko.auth_handler import AuthHandler
from paramiko.ssh_gss import GSSAuth, GSS_AUTH_AVAILABLE, GSS_EXCEPTIONS
from paramiko.channel import (
Channel,
ChannelFile,
ChannelStderrFile,
ChannelStdinFile,
)
from paramiko.ssh_exception import (
AuthenticationException,
BadAuthenticationType,
BadHostKeyException,
ChannelException,
ConfigParseError,
CouldNotCanonicalize,
IncompatiblePeer,
PasswordRequiredException,
ProxyCommandFailure,
SSHException,
)
from paramiko.server import ServerInterface, SubsystemHandler, InteractiveQuery
from paramiko.rsakey import RSAKey
from paramiko.dsskey import DSSKey
from paramiko.ecdsakey import ECDSAKey
from paramiko.ed25519key import Ed25519Key
from paramiko.sftp import SFTPError, BaseSFTP
from paramiko.sftp_client import SFTP, SFTPClient
from paramiko.sftp_server import SFTPServer
from paramiko.sftp_attr import SFTPAttributes
from paramiko.sftp_handle import SFTPHandle
from paramiko.sftp_si import SFTPServerInterface
from paramiko.sftp_file import SFTPFile
from paramiko.message import Message
from paramiko.packet import Packetizer
from paramiko.file import BufferedFile
from paramiko.agent import Agent, AgentKey
from paramiko.pkey import PKey, PublicBlob
from paramiko.hostkeys import HostKeys
from paramiko.config import SSHConfig, SSHConfigDict
from paramiko.proxy import ProxyCommand

from paramiko.common import (
AUTH_SUCCESSFUL,
AUTH_PARTIALLY_SUCCESSFUL,
AUTH_FAILED,
OPEN_SUCCEEDED,
OPEN_FAILED_ADMINISTRATIVELY_PROHIBITED,
OPEN_FAILED_CONNECT_FAILED,
OPEN_FAILED_UNKNOWN_CHANNEL_TYPE,
OPEN_FAILED_RESOURCE_SHORTAGE,
)

from paramiko.sftp import (
SFTP_OK,
SFTP_EOF,
SFTP_NO_SUCH_FILE,
SFTP_PERMISSION_DENIED,
SFTP_FAILURE,
SFTP_BAD_MESSAGE,
SFTP_NO_CONNECTION,
SFTP_CONNECTION_LOST,
SFTP_OP_UNSUPPORTED,
)

from paramiko.common import io_sleep


__author__ = "Jeff Forcier <[email protected]>"
__license__ = "GNU Lesser General Public License (LGPL)"

__all__ = [
"Agent",
"AgentKey",
"AuthenticationException",
"AutoAddPolicy",
"BadAuthenticationType",
"BadHostKeyException",
"BufferedFile",
"Channel",
"ChannelException",
"ConfigParseError",
"CouldNotCanonicalize",
"DSSKey",
"ECDSAKey",
"Ed25519Key",
"HostKeys",
"Message",
"MissingHostKeyPolicy",
"PKey",
"PasswordRequiredException",
"ProxyCommand",
"ProxyCommandFailure",
"RSAKey",
"RejectPolicy",
"SFTP",
"SFTPAttributes",
"SFTPClient",
"SFTPError",
"SFTPFile",
"SFTPHandle",
"SFTPServer",
"SFTPServerInterface",
"SSHClient",
"SSHConfig",
"SSHConfigDict",
"SSHException",
"SecurityOptions",
"ServerInterface",
"SubsystemHandler",
"Transport",
"WarningPolicy",
"io_sleep",
"util",
]
2 changes: 2 additions & 0 deletions PythonSubmitDella/paramiko/_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
__version_info__ = (2, 9, 2)
__version__ = ".".join(map(str, __version_info__))
Loading

0 comments on commit 95b7f70

Please sign in to comment.