Ticket #476: sftp.diff
| File sftp.diff, 3.4 KB (added by jrabbit, 5 years ago) |
|---|
-
haikuporter
26 26 import commands 27 27 from subprocess import check_call, Popen, CalledProcessError 28 28 from optparse import OptionParser 29 try: 30 import paramiko 31 except ImportError: 32 pass 29 33 30 34 # -- HaikuPorts options ------------------------------------------------------- 31 35 … … 59 63 confTypes = {} 60 64 confTypes['PACKAGES_PATH'] = [types.StringType] 61 65 confTypes['PATCH_OPTIONS'] = [types.StringType] 66 confTypes['SSH_KEY'] = [types.StringType] 67 confTypes['SSH_USER'] = [types.StringType] 68 confTypes['SSH_PORT'] = [types.IntType] 69 confTypes['SFTP_TARGET'] = [types.StringType] 70 confTypes['SFTP_FOLDER'] = [types.StringType] 62 71 63 72 # allowed types of the BepFile values 64 73 … … 1044 1053 shutil.rmtree(self.distroDir) 1045 1054 1046 1055 print 'Package saved to: ' + zipFile 1056 1057 if self.options.upload: 1058 if paramiko: 1059 if self.confKeys['SFTP_TARGET']: 1060 print 'Uploading package to %s' \ 1061 % self.confKeys['SFTP_TARGET'] 1062 sendFile(zipfile) 1063 else: 1064 print 'Cannot read the SFTP options from ' + \ 1065 'your haikuports.conf' 1066 else: 1067 self.prompt_installer(paramiko) 1047 1068 1069 def sendFile(self, zipfile): 1070 """upload file to SFTP server""" 1071 1072 key = self.confKeys['SSH_KEY'] 1073 user = self.confKeys['SSH_USER'] 1074 port = self.confKeys['SSH_PORT'] 1075 host = self.confKeys['SFTP_TARGET'] 1076 dest_folder = self.confKeys['SFTP_FOLDER'] 1077 1078 t = paramiko.Transport((host, port)) 1079 pkey = paramiko.RSAKey.from_private_key_file(key) 1080 t.connect(username=user, pkey=pkey) 1081 sftp = paramiko.SFTPClient.from_transport(t) 1082 1083 stfp.put(zipfile, os.join(dest_folder,self.portCategory, 1084 os.path.split(zipfile)[1])) 1085 sftp.close() 1086 t.close() 1087 1048 1088 def makePatchedArchive(self): 1049 1089 """Create a patched source archive""" 1050 1090 … … 1080 1120 shutil.rmtree(self.workDir) 1081 1121 1082 1122 print 'Archive saved to: ' + archiveFile 1123 1124 if self.options.upload: 1125 if paramiko: 1126 if self.confKeys['SFTP_TARGET']: 1127 print 'Uploading archive to %s' \ 1128 % self.confKeys['SFTP_TARGET'] 1129 sendFile(zipfile) 1130 else: 1131 print 'Cannot read the SFTP options from ' + \ 1132 'your haikuports.conf' 1133 else: 1134 self.prompt_installer(paramiko) 1083 1135 1084 1136 def prompt_installer(self, name): 1085 1137 apps = { # map command to package … … 1088 1140 'hg': 'mercurial', 1089 1141 'cvs': 'cvs', 1090 1142 'bzr': 'bazaar', 1143 'paramiko' : 'pycrypto paramiko' 1091 1144 } 1092 1145 if self.options.yes: 1093 1146 check_call('installoptionalpackage' + ' ' … … 1479 1532 default=False, 1480 1533 help='Answer yes to all questions', 1481 1534 ) 1535 parser.add_option( 1536 '-u', 1537 '--upload', 1538 action='store_true', 1539 dest='upload', 1540 default=False, 1541 help='used with -d or -z to upload the resulting file to a SFTP site', 1542 ) 1482 1543 1483 1544 parser.add_option('--test', action='store_true', dest='test', 1484 1545 default=False, help='Run tests on resulting binaries')
