diff options
| author | Philipp Hagemeister <phihag@phihag.de> | 2016-06-04 22:55:21 +0200 | 
|---|---|---|
| committer | Philipp Hagemeister <phihag@phihag.de> | 2016-06-04 22:55:21 +0200 | 
| commit | c93b4eacebe62e3993da790cbea8fbf62e161f07 (patch) | |
| tree | 1b6a356fa6d0fa38f76a466012fc630096f94f9b /devscripts | |
| parent | 71b9cb3107e156c7f17ec4cdf1d09421cb4dd4b1 (diff) | |
| parent | 633b444fd29aa9d8b3ba722285ae2475ae66595f (diff) | |
git pushMerge branch 'master' of github.com:rg3/youtube-dl
Diffstat (limited to 'devscripts')
| -rw-r--r-- | devscripts/buildserver.py | 6 | ||||
| -rw-r--r-- | devscripts/create-github-release.py | 112 | ||||
| -rwxr-xr-x | devscripts/release.sh | 7 | 
3 files changed, 116 insertions, 9 deletions
| diff --git a/devscripts/buildserver.py b/devscripts/buildserver.py index f7979c43e..fc99c3213 100644 --- a/devscripts/buildserver.py +++ b/devscripts/buildserver.py @@ -13,6 +13,7 @@ import os.path  sys.path.insert(0, os.path.dirname(os.path.dirname((os.path.abspath(__file__)))))  from youtube_dl.compat import ( +    compat_input,      compat_http_server,      compat_str,      compat_urlparse, @@ -30,11 +31,6 @@ try:  except ImportError:  # Python 2      import SocketServer as compat_socketserver -try: -    compat_input = raw_input -except NameError:  # Python 3 -    compat_input = input -  class BuildHTTPServer(compat_socketserver.ThreadingMixIn, compat_http_server.HTTPServer):      allow_reuse_address = True diff --git a/devscripts/create-github-release.py b/devscripts/create-github-release.py new file mode 100644 index 000000000..f74d39490 --- /dev/null +++ b/devscripts/create-github-release.py @@ -0,0 +1,112 @@ +#!/usr/bin/env python +from __future__ import unicode_literals + +import base64 +import json +import mimetypes +import netrc +import optparse +import os +import sys + +sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) + +from youtube_dl.compat import ( +    compat_basestring, +    compat_input, +    compat_getpass, +    compat_print, +    compat_urllib_request, +) +from youtube_dl.utils import ( +    make_HTTPS_handler, +    sanitized_Request, +) + + +class GitHubReleaser(object): +    _API_URL = 'https://api.github.com/repos/rg3/youtube-dl/releases' +    _UPLOADS_URL = 'https://uploads.github.com/repos/rg3/youtube-dl/releases/%s/assets?name=%s' +    _NETRC_MACHINE = 'github.com' + +    def __init__(self, debuglevel=0): +        self._init_github_account() +        https_handler = make_HTTPS_handler({}, debuglevel=debuglevel) +        self._opener = compat_urllib_request.build_opener(https_handler) + +    def _init_github_account(self): +        try: +            info = netrc.netrc().authenticators(self._NETRC_MACHINE) +            if info is not None: +                self._username = info[0] +                self._password = info[2] +                compat_print('Using GitHub credentials found in .netrc...') +                return +            else: +                compat_print('No GitHub credentials found in .netrc') +        except (IOError, netrc.NetrcParseError): +            compat_print('Unable to parse .netrc') +        self._username = compat_input( +            'Type your GitHub username or email address and press [Return]: ') +        self._password = compat_getpass( +            'Type your GitHub password and press [Return]: ') + +    def _call(self, req): +        if isinstance(req, compat_basestring): +            req = sanitized_Request(req) +        # Authorizing manually since GitHub does not response with 401 with +        # WWW-Authenticate header set (see +        # https://developer.github.com/v3/#basic-authentication) +        b64 = base64.b64encode( +            ('%s:%s' % (self._username, self._password)).encode('utf-8')).decode('ascii') +        req.add_header('Authorization', 'Basic %s' % b64) +        response = self._opener.open(req).read().decode('utf-8') +        return json.loads(response) + +    def list_releases(self): +        return self._call(self._API_URL) + +    def create_release(self, tag_name, name=None, body='', draft=False, prerelease=False): +        data = { +            'tag_name': tag_name, +            'target_commitish': 'master', +            'name': name, +            'body': body, +            'draft': draft, +            'prerelease': prerelease, +        } +        req = sanitized_Request(self._API_URL, json.dumps(data).encode('utf-8')) +        return self._call(req) + +    def create_asset(self, release_id, asset): +        asset_name = os.path.basename(asset) +        url = self._UPLOADS_URL % (release_id, asset_name) +        # Our files are small enough to be loaded directly into memory. +        data = open(asset, 'rb').read() +        req = sanitized_Request(url, data) +        mime_type, _ = mimetypes.guess_type(asset_name) +        req.add_header('Content-Type', mime_type or 'application/octet-stream') +        return self._call(req) + + +def main(): +    parser = optparse.OptionParser(usage='%prog VERSION BUILDPATH') +    options, args = parser.parse_args() +    if len(args) != 2: +        parser.error('Expected a version and a build directory') + +    version, build_path = args + +    releaser = GitHubReleaser(debuglevel=0) + +    new_release = releaser.create_release( +        version, name='youtube-dl %s' % version, draft=True, prerelease=True) +    release_id = new_release['id'] + +    for asset in os.listdir(build_path): +        compat_print('Uploading %s...' % asset) +        releaser.create_asset(release_id, os.path.join(build_path, asset)) + + +if __name__ == '__main__': +    main() diff --git a/devscripts/release.sh b/devscripts/release.sh index 1a7b1e054..87e8eda50 100755 --- a/devscripts/release.sh +++ b/devscripts/release.sh @@ -95,17 +95,16 @@ RELEASE_FILES="youtube-dl youtube-dl.exe youtube-dl-$version.tar.gz"  (cd build/$version/ && sha256sum $RELEASE_FILES > SHA2-256SUMS)  (cd build/$version/ && sha512sum $RELEASE_FILES > SHA2-512SUMS) -/bin/echo -e "\n### Signing and uploading the new binaries to yt-dl.org ..." +/bin/echo -e "\n### Signing and uploading the new binaries to GitHub..."  for f in $RELEASE_FILES; do gpg --passphrase-repeat 5 --detach-sig "build/$version/$f"; done -echo 'TODO: upload on GitHub' -exit 1 +ROOT=$(pwd) +python devscripts/create-github-release.py $version "$ROOT/build/$version"  ssh ytdl@yt-dl.org "sh html/update_latest.sh $version"  /bin/echo -e "\n### Now switching to gh-pages..."  git clone --branch gh-pages --single-branch . build/gh-pages -ROOT=$(pwd)  (      set -e      ORIGIN_URL=$(git config --get remote.origin.url) | 
