HaikuPorts
  • Login
  • Preferences
  • Help/Guide
  • Wiki
  • Timeline
  • Roadmap
  • View Tickets
  • Search
  • Port Log
  • Blog

Context Navigation

  • Back to Ticket #476

Ticket #476: sftp.diff

File sftp.diff, 3.4 KB (added by jrabbit, 5 years ago)

combined sftp diff

  • haikuporter

     
    2626import commands 
    2727from subprocess import check_call, Popen, CalledProcessError 
    2828from optparse import OptionParser 
     29try: 
     30    import paramiko 
     31except ImportError: 
     32    pass 
    2933 
    3034# -- HaikuPorts options ------------------------------------------------------- 
    3135 
    … …  
    5963confTypes = {} 
    6064confTypes['PACKAGES_PATH'] = [types.StringType] 
    6165confTypes['PATCH_OPTIONS'] = [types.StringType] 
     66confTypes['SSH_KEY'] = [types.StringType] 
     67confTypes['SSH_USER'] = [types.StringType] 
     68confTypes['SSH_PORT'] = [types.IntType] 
     69confTypes['SFTP_TARGET'] = [types.StringType] 
     70confTypes['SFTP_FOLDER'] = [types.StringType] 
    6271 
    6372# allowed types of the BepFile values 
    6473 
    … …  
    10441053        shutil.rmtree(self.distroDir) 
    10451054 
    10461055        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) 
    10471068 
     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 
    10481088    def makePatchedArchive(self): 
    10491089        """Create a patched source archive""" 
    10501090 
    … …  
    10801120        shutil.rmtree(self.workDir) 
    10811121 
    10821122        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) 
    10831135 
    10841136    def prompt_installer(self, name): 
    10851137        apps = {  # map command to package 
    … …  
    10881140            'hg': 'mercurial', 
    10891141            'cvs': 'cvs', 
    10901142            'bzr': 'bazaar', 
     1143            'paramiko' : 'pycrypto paramiko' 
    10911144            } 
    10921145        if self.options.yes: 
    10931146            check_call('installoptionalpackage' + ' ' 
    … …  
    14791532    default=False, 
    14801533    help='Answer yes to all questions', 
    14811534    ) 
     1535parser.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    ) 
    14821543 
    14831544parser.add_option('--test', action='store_true', dest='test', 
    14841545                  default=False, help='Run tests on resulting binaries') 

Download in other formats:

  • Original Format

Trac Powered

Powered by Trac 0.13dev-r10686
By Edgewall Software.

Visit the Trac open source project at
http://trac.edgewall.org/