Back to index

enigmail  1.4.3
Functions | Variables
build.upload Namespace Reference

Functions

def RequireEnvironmentVariable
def OptionalEnvironmentVariable
def FixupMsysPath
def WindowsPathToMsysPath
def AppendOptionalArgsToSSHCommandline
def DoSSHCommand
def DoSCPFile
def GetRemotePath
def UploadFiles

Variables

tuple host = RequireEnvironmentVariable('UPLOAD_HOST')
tuple user = RequireEnvironmentVariable('UPLOAD_USER')
tuple path = OptionalEnvironmentVariable('UPLOAD_PATH')
tuple upload_to_temp_dir = OptionalEnvironmentVariable('UPLOAD_TO_TEMP')
tuple port = OptionalEnvironmentVariable('UPLOAD_PORT')
tuple key = OptionalEnvironmentVariable('UPLOAD_SSH_KEY')
tuple post_upload_command = OptionalEnvironmentVariable('POST_UPLOAD_CMD')
tuple parser = OptionParser(usage="usage: %prog [options] <files>")
string action = "store"
string help = "Preserve file paths relative to this path when uploading. If unset, all files will be uploaded directly to UPLOAD_PATH."
 verbose = True)

Function Documentation

def build.upload.AppendOptionalArgsToSSHCommandline (   cmdline,
  port,
  ssh_key 
)
Given optional port and ssh key values, append valid OpenSSH
commandline arguments to the list cmdline if the values are not None.

Definition at line 101 of file upload.py.

00101 
00102 def AppendOptionalArgsToSSHCommandline(cmdline, port, ssh_key):
00103     """Given optional port and ssh key values, append valid OpenSSH
00104     commandline arguments to the list cmdline if the values are not None."""
00105     if port is not None:
00106         cmdline.append("-P%d" % port)
00107     if ssh_key is not None:
00108         # Don't interpret ~ paths - ssh can handle that on its own
00109         if not ssh_key.startswith('~'):
00110             ssh_key = WindowsPathToMsysPath(ssh_key)
00111         cmdline.extend(["-o", "IdentityFile=%s" % ssh_key])

Here is the call graph for this function:

Here is the caller graph for this function:

def build.upload.DoSCPFile (   file,
  remote_path,
  user,
  host,
  port = None,
  ssh_key = None 
)
Upload file to user@host:remote_path using scp. Optionally use
port and ssh_key, if provided.

Definition at line 125 of file upload.py.

00125 
00126 def DoSCPFile(file, remote_path, user, host, port=None, ssh_key=None):
00127     """Upload file to user@host:remote_path using scp. Optionally use
00128     port and ssh_key, if provided."""
00129     cmdline = ["scp"]
00130     AppendOptionalArgsToSSHCommandline(cmdline, port, ssh_key)
00131     cmdline.extend([WindowsPathToMsysPath(file),
00132                     "%s@%s:%s" % (user, host, remote_path)])
00133     check_call(cmdline)

Here is the call graph for this function:

Here is the caller graph for this function:

def build.upload.DoSSHCommand (   command,
  user,
  host,
  port = None,
  ssh_key = None 
)
Execute command on user@host using ssh. Optionally use
port and ssh_key, if provided.

Definition at line 112 of file upload.py.

00112 
00113 def DoSSHCommand(command, user, host, port=None, ssh_key=None):
00114     """Execute command on user@host using ssh. Optionally use
00115     port and ssh_key, if provided."""
00116     cmdline = ["ssh"]
00117     AppendOptionalArgsToSSHCommandline(cmdline, port, ssh_key)
00118     cmdline.extend(["%s@%s" % (user, host), command])
00119     cmd = Popen(cmdline, stdout=PIPE)
00120     retcode = cmd.wait()
00121     if retcode != 0:
00122         raise Exception("Command %s returned non-zero exit code: %i" % \
00123           (cmdline, retcode))
00124     return cmd.stdout.read().strip()

Here is the call graph for this function:

Here is the caller graph for this function:

MSYS helpfully translates absolute pathnames in environment variables
and commandline arguments into Windows native paths. This sucks if you're
trying to pass an absolute path on a remote server. This function attempts
to un-mangle such paths.

Definition at line 77 of file upload.py.

00077 
00078 def FixupMsysPath(path):
00079     """MSYS helpfully translates absolute pathnames in environment variables
00080     and commandline arguments into Windows native paths. This sucks if you're
00081     trying to pass an absolute path on a remote server. This function attempts
00082     to un-mangle such paths."""
00083     if 'OSTYPE' in os.environ and os.environ['OSTYPE'] == 'msys':
00084         # sort of awful, find out where our shell is (should be in msys/bin)
00085         # and strip the first part of that path out of the other path
00086         if 'SHELL' in os.environ:
00087             sh = os.environ['SHELL']
00088             msys = sh[:sh.find('/bin')]
00089             if path.startswith(msys):
00090                 path = path[len(msys):]
00091     return path

def build.upload.GetRemotePath (   path,
  local_file,
  base_path 
)
Given a remote path to upload to, a full path to a local file, and an
optional full path that is a base path of the local file, construct the
full remote path to place the file in. If base_path is not None, include
the relative path from base_path to file.

Definition at line 134 of file upload.py.

00134 
00135 def GetRemotePath(path, local_file, base_path):
00136     """Given a remote path to upload to, a full path to a local file, and an
00137     optional full path that is a base path of the local file, construct the
00138     full remote path to place the file in. If base_path is not None, include
00139     the relative path from base_path to file."""
00140     if base_path is None or not local_file.startswith(base_path):
00141         return path
00142     dir = os.path.dirname(local_file)
00143     # strip base_path + extra slash and make it unixy
00144     dir = dir[len(base_path)+1:].replace('\\','/')
00145     return path + dir

Here is the caller graph for this function:

Return the value of the environment variable named v, or None
if it's unset (or empty).

Definition at line 70 of file upload.py.

00070 
00071 def OptionalEnvironmentVariable(v):
00072     """Return the value of the environment variable named v, or None
00073     if it's unset (or empty)."""
00074     if v in os.environ and os.environ[v] != "":
00075         return os.environ[v]
00076     return None

Return the value of the environment variable named v, or print
an error and exit if it's unset (or empty).

Definition at line 62 of file upload.py.

00062 
00063 def RequireEnvironmentVariable(v):
00064     """Return the value of the environment variable named v, or print
00065     an error and exit if it's unset (or empty)."""
00066     if not v in os.environ or os.environ[v] == "":
00067         print "Error: required environment variable %s not set" % v
00068         sys.exit(1)
00069     return os.environ[v]

def build.upload.UploadFiles (   user,
  host,
  path,
  files,
  verbose = False,
  port = None,
  ssh_key = None,
  base_path = None,
  upload_to_temp_dir = False,
  post_upload_command = None 
)
Upload each file in the list files to user@host:path. Optionally pass
port and ssh_key to the ssh commands. If base_path is not None, upload
files including their path relative to base_path. If upload_to_temp_dir is
True files will be uploaded to a temporary directory on the remote server.
Generally, you should have a post upload command specified in these cases
that can move them around to their correct location(s).
If post_upload_command is not None, execute that command on the remote host
after uploading all files, passing it the upload path, and the full paths to
all files uploaded.
If verbose is True, print status updates while working.

Definition at line 146 of file upload.py.

00146 
00147 def UploadFiles(user, host, path, files, verbose=False, port=None, ssh_key=None, base_path=None, upload_to_temp_dir=False, post_upload_command=None):
00148     """Upload each file in the list files to user@host:path. Optionally pass
00149     port and ssh_key to the ssh commands. If base_path is not None, upload
00150     files including their path relative to base_path. If upload_to_temp_dir is
00151     True files will be uploaded to a temporary directory on the remote server.
00152     Generally, you should have a post upload command specified in these cases
00153     that can move them around to their correct location(s).
00154     If post_upload_command is not None, execute that command on the remote host
00155     after uploading all files, passing it the upload path, and the full paths to
00156     all files uploaded.
00157     If verbose is True, print status updates while working."""
00158     if upload_to_temp_dir:
00159         path = DoSSHCommand("mktemp -d", user, host, port=port, ssh_key=ssh_key)
00160     if not path.endswith("/"):
00161         path += "/"
00162     if base_path is not None:
00163         base_path = os.path.abspath(base_path)
00164     remote_files = []
00165     try:
00166         for file in files:
00167             file = os.path.abspath(file)
00168             if not os.path.isfile(file):
00169                 raise IOError("File not found: %s" % file)
00170             # first ensure that path exists remotely
00171             remote_path = GetRemotePath(path, file, base_path)
00172             DoSSHCommand("mkdir -p " + remote_path, user, host, port=port, ssh_key=ssh_key)
00173             if verbose:
00174                 print "Uploading " + file
00175             DoSCPFile(file, remote_path, user, host, port=port, ssh_key=ssh_key)
00176             remote_files.append(remote_path + '/' + os.path.basename(file))
00177         if post_upload_command is not None:
00178             if verbose:
00179                 print "Running post-upload command: " + post_upload_command
00180             file_list = '"' + '" "'.join(remote_files) + '"'
00181             DoSSHCommand('%s "%s" %s' % (post_upload_command, path, file_list), user, host, port=port, ssh_key=ssh_key)
00182     finally:
00183         if upload_to_temp_dir:
00184             DoSSHCommand("rm -rf %s" % path, user, host, port=port,
00185                          ssh_key=ssh_key)
00186     if verbose:
00187         print "Upload complete"

Here is the call graph for this function:

Translate a Windows pathname to an MSYS pathname.
Necessary because we call out to ssh/scp, which are MSYS binaries
and expect MSYS paths.

Definition at line 92 of file upload.py.

00092 
00093 def WindowsPathToMsysPath(path):
00094     """Translate a Windows pathname to an MSYS pathname.
00095     Necessary because we call out to ssh/scp, which are MSYS binaries
00096     and expect MSYS paths."""
00097     if sys.platform != 'win32':
00098         return path
00099     (drive, path) = os.path.splitdrive(os.path.abspath(path))
00100     return "/" + drive[0] + path.replace('\\','/')

Here is the caller graph for this function:


Variable Documentation

string build.upload.action = "store"

Definition at line 210 of file upload.py.

string build.upload.help = "Preserve file paths relative to this path when uploading. If unset, all files will be uploaded directly to UPLOAD_PATH."

Definition at line 211 of file upload.py.

Definition at line 189 of file upload.py.

tuple build.upload.key = OptionalEnvironmentVariable('UPLOAD_SSH_KEY')

Definition at line 196 of file upload.py.

tuple build.upload.parser = OptionParser(usage="usage: %prog [options] <files>")

Definition at line 208 of file upload.py.

Definition at line 191 of file upload.py.

Definition at line 193 of file upload.py.

Definition at line 197 of file upload.py.

Definition at line 192 of file upload.py.

Definition at line 190 of file upload.py.

Definition at line 220 of file upload.py.