Upload GPG signature.

This commit is contained in:
Martin v. Löwis 2005-03-22 15:51:14 +00:00
parent c448a91ee8
commit f74b923ae5
1 changed files with 16 additions and 3 deletions

View File

@ -4,9 +4,10 @@ Implements the Distutils 'upload' subcommand (upload package to PyPI)."""
from distutils.errors import * from distutils.errors import *
from distutils.core import Command from distutils.core import Command
from md5 import md5
from distutils.sysconfig import get_python_version from distutils.sysconfig import get_python_version
from distutils.spawn import spawn
from distutils import log from distutils import log
from md5 import md5
import os import os
import platform import platform
import ConfigParser import ConfigParser
@ -26,14 +27,17 @@ class upload(Command):
"url of repository [default: %s]" % DEFAULT_REPOSITORY), "url of repository [default: %s]" % DEFAULT_REPOSITORY),
('show-response', None, ('show-response', None,
'display full response text from server'), 'display full response text from server'),
('sign', 's',
'sign files to upload using gpg'),
] ]
boolean_options = ['show-response'] boolean_options = ['show-response', 'sign']
def initialize_options(self): def initialize_options(self):
self.username = '' self.username = ''
self.password = '' self.password = ''
self.repository = '' self.repository = ''
self.show_response = 0 self.show_response = 0
self.sign = False
def finalize_options(self): def finalize_options(self):
if os.environ.has_key('HOME'): if os.environ.has_key('HOME'):
@ -61,11 +65,16 @@ class upload(Command):
self.upload_file(command, filename) self.upload_file(command, filename)
def upload_file(self, command, filename): def upload_file(self, command, filename):
# Sign if requested
if self.sign:
spawn(("gpg", "--sign", "-a", filename),
dry_run=self.dry_run)
# Fill in the data # Fill in the data
content = open(filename).read() content = open(filename).read()
data = { data = {
':action':'file_upload', ':action':'file_upload',
'protcol_version':'1',
'name':self.distribution.get_name(), 'name':self.distribution.get_name(),
'version':self.distribution.get_version(), 'version':self.distribution.get_version(),
'content':(os.path.basename(filename),content), 'content':(os.path.basename(filename),content),
@ -82,6 +91,10 @@ class upload(Command):
comment = 'built for %s' % platform.platform(terse=1) comment = 'built for %s' % platform.platform(terse=1)
data['comment'] = comment data['comment'] = comment
if self.sign:
data['gpg_signature'] = (os.path.basename(filename) + ".asc",
open(filename+".asc").read())
# set up the authentication # set up the authentication
auth = "Basic " + base64.encodestring(self.username + ":" + self.password).strip() auth = "Basic " + base64.encodestring(self.username + ":" + self.password).strip()
@ -148,7 +161,7 @@ class upload(Command):
log.INFO) log.INFO)
else: else:
self.announce('Upload failed (%s): %s' % (r.status, r.reason), self.announce('Upload failed (%s): %s' % (r.status, r.reason),
log.INFO) log.ERROR)
if self.show_response: if self.show_response:
print '-'*75, r.read(), '-'*75 print '-'*75, r.read(), '-'*75