##// END OF EJS Templates
Migrate to Mergely 3.3.4....
Migrate to Mergely 3.3.4. RhodeCode 2.2.5 distributed Mergely 3.3.4 with some of the changes that Mergely 3.3.3 in RhodeCode 1.7.2 also had. That do however not seem to be changes we want for Kallithea this way and we take the 3.3.4 files as they are. I've also included the Mergely license file, as downloaded from: http://www.mergely.com/license.php That LICENSE file is kept in HTML just as it was downloaded from their website. While it's a bit annoying to keep the license file in HTML, this is the way it came from upstream so we'll leave it that way. Since the Javascript code is used with other GPLv3 Javascript, we are using the GPL option of Mergely's tri-license. Finally, note that previously, this was incorrectly called "mergerly", so the opportunity is taken here to correct the name. That required changes to diff_2way.html. As commands:: $ wget -N --output-document LICENSE-MERGELY.html http://www.mergely.com/license.php $ hg add LICENSE-MERGELY.html $ hg mv rhodecode/public/css/mergerly.css rhodecode/public/css/mergely.css $ hg mv rhodecode/public/js/mergerly.js rhodecode/public/js/mergely.js $ sed -i 's,mergerly\.,mergely,g' rhodecode/templates/files/diff_2way.html $ ( cd /tmp; \ wget -N http://www.mergely.com/releases/mergely-3.3.4.zip; \ unzip mergely-3.3.4.zip ) $ sha256sum /tmp/mergely-3.3.4.zip 87415d30494bbe829c248881aa7cdc0303f7e70b458a5f687615564d4498cc82 mergely-3.3.4.zip $ cp /tmp/mergely-3.3.4/lib/mergely.js rhodecode/public/js/mergely.js $ cp /tmp/mergely-3.3.4/lib/mergely.css rhodecode/public/css/mergely.css $ sed -i -e '/^ \* Version/a\ *\n * NOTE by bkuhn@sfconservancy.org for Kallithea:\n * Mergely license appears at http://www.mergely.com/license.php and in LICENSE-MERGELY.html' rhodecode/public/js/mergely.js rhodecode/public/css/mergely.css

File last commit:

r4116:ffd45b18 rhodecode-2.2.5-gpl
r4125:aa3b5594 rhodecode-2.2.5-gpl
Show More
rhodecode_gist.py
171 lines | 5.7 KiB | text/x-python | PythonLexer
Implemented simple gist functionality ref #530....
r3840 # -*- coding: utf-8 -*-
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
Bradley M. Kuhn
Imported some of the GPLv3'd changes from RhodeCode v2.2.5....
r4116 """
rhodecode.bin.rhodecode_gist
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Gist CLI client for RhodeCode
:created_on: May 9, 2013
:author: marcink
:copyright: (c) 2013 RhodeCode GmbH.
:license: GPLv3, see LICENSE for more details.
"""
Implemented simple gist functionality ref #530....
r3840
from __future__ import with_statement
import os
import sys
import stat
import argparse
import fileinput
Added --format into gist CLI...
r3875 from rhodecode.bin.base import json, api_call, RcConf, FORMAT_JSON, FORMAT_PRETTY
Implemented simple gist functionality ref #530....
r3840
def argparser(argv):
usage = (
"rhodecode-gist [-h] [--format=FORMAT] [--apikey=APIKEY] [--apihost=APIHOST] "
Explicitly tell fileinput that we use '-' as read source...
r3881 "[--config=CONFIG] [--save-config] [GIST OPTIONS] "
Implemented simple gist functionality ref #530....
r3840 "[filename or stdin use - for terminal stdin ]\n"
"Create config file: rhodecode-gist --apikey=<key> --apihost=http://rhodecode.server --save-config"
)
parser = argparse.ArgumentParser(description='RhodeCode Gist cli',
usage=usage)
## config
group = parser.add_argument_group('config')
group.add_argument('--apikey', help='api access key')
group.add_argument('--apihost', help='api host')
Explicitly tell fileinput that we use '-' as read source...
r3881 group.add_argument('--config', help='config file path DEFAULT: ~/.rhodecode')
Implemented simple gist functionality ref #530....
r3840 group.add_argument('--save-config', action='store_true',
help='save the given config into a file')
group = parser.add_argument_group('GIST')
group.add_argument('-p', '--private', action='store_true',
Explicitly tell fileinput that we use '-' as read source...
r3881 help='create private Gist')
group.add_argument('-f', '--filename',
help='set uploaded gist filename, '
'also defines syntax highlighting')
Implemented simple gist functionality ref #530....
r3840 group.add_argument('-d', '--description', help='Gist description')
group.add_argument('-l', '--lifetime', metavar='MINUTES',
Explicitly tell fileinput that we use '-' as read source...
r3881 help='gist lifetime in minutes, -1 (DEFAULT) is forever')
Added --format into gist CLI...
r3875 group.add_argument('--format', dest='format', type=str,
Explicitly tell fileinput that we use '-' as read source...
r3881 help='output format DEFAULT: `%s` can '
'be also `%s`' % (FORMAT_PRETTY, FORMAT_JSON),
Added --format into gist CLI...
r3875 default=FORMAT_PRETTY
)
Implemented simple gist functionality ref #530....
r3840 args, other = parser.parse_known_args()
return parser, args, other
def _run(argv):
conf = None
parser, args, other = argparser(argv)
api_credentials_given = (args.apikey and args.apihost)
if args.save_config:
if not api_credentials_given:
raise parser.error('--save-config requires --apikey and --apihost')
conf = RcConf(config_location=args.config,
autocreate=True, config={'apikey': args.apikey,
'apihost': args.apihost})
sys.exit()
if not conf:
conf = RcConf(config_location=args.config, autoload=True)
if not conf:
if not api_credentials_given:
parser.error('Could not find config file and missing '
'--apikey or --apihost in params')
apikey = args.apikey or conf['apikey']
host = args.apihost or conf['apihost']
DEFAULT_FILENAME = 'gistfile1.txt'
if other:
# skip multifiles for now
filename = other[0]
if filename == '-':
filename = DEFAULT_FILENAME
gist_content = ''
Explicitly tell fileinput that we use '-' as read source...
r3881 for line in fileinput.input('-'):
Implemented simple gist functionality ref #530....
r3840 gist_content += line
else:
with open(filename, 'rb') as f:
gist_content = f.read()
else:
filename = DEFAULT_FILENAME
gist_content = None
# little bit hacky but cross platform check where the
# stdin comes from we skip the terminal case it can be handled by '-'
mode = os.fstat(0).st_mode
if stat.S_ISFIFO(mode):
# "stdin is piped"
gist_content = sys.stdin.read()
elif stat.S_ISREG(mode):
# "stdin is redirected"
gist_content = sys.stdin.read()
else:
# "stdin is terminal"
pass
# make sure we don't upload binary stuff
if gist_content and '\0' in gist_content:
raise Exception('Error: binary files upload is not possible')
gist cli should convert given paths to basenames
r3845 filename = os.path.basename(args.filename or filename)
Implemented simple gist functionality ref #530....
r3840 if gist_content:
files = {
filename: {
'content': gist_content,
'lexer': None
}
}
margs = dict(
sync gist api and cli with rhodecode-pam....
r3958 lifetime=args.lifetime,
description=args.description,
Implemented simple gist functionality ref #530....
r3840 gist_type='private' if args.private else 'public',
files=files
)
Added --format into gist CLI...
r3875 json_data = api_call(apikey, host, 'create_gist', **margs)['result']
if args.format == FORMAT_JSON:
print json.dumps(json_data)
elif args.format == FORMAT_PRETTY:
sync gist api and cli with rhodecode-pam....
r3958 print json_data
print 'Created %s gist %s' % (json_data['gist']['type'],
json_data['gist']['url'])
Implemented simple gist functionality ref #530....
r3840 return 0
def main(argv=None):
"""
Main execution function for cli
:param argv:
"""
if argv is None:
argv = sys.argv
try:
return _run(argv)
except Exception, e:
print e
return 1
if __name__ == '__main__':
sys.exit(main(sys.argv))