DeDRM_tools/DeDRM_calibre_plugin/DeDRM_plugin/encodebase64.py

46 lines
936 B
Python
Raw Normal View History

2013-10-02 12:59:40 -06:00
#!/usr/bin/env python
# -*- coding: utf-8 -*-
2013-10-02 12:59:40 -06:00
# base64.py, version 1.0
# Copyright © 2010 Apprentice Alf
2013-10-02 12:59:40 -06:00
# Released under the terms of the GNU General Public Licence, version 3 or
# later. <http://www.gnu.org/licenses/>
2013-10-02 12:59:40 -06:00
# Revision history:
# 1 - Initial release. To allow Applescript to do base64 encoding
2013-10-02 12:59:40 -06:00
"""
Provide base64 encoding.
"""
2013-04-05 10:44:48 -06:00
2013-10-02 12:59:40 -06:00
from __future__ import with_statement
2013-04-05 10:44:48 -06:00
2013-10-02 12:59:40 -06:00
__license__ = 'GPL v3'
2013-04-05 10:44:48 -06:00
2013-10-02 12:59:40 -06:00
import sys
import os
import base64
2013-04-05 10:44:48 -06:00
2013-10-02 12:59:40 -06:00
def usage(progname):
print "Applies base64 encoding to the supplied file, sending to standard output"
print "Usage:"
print " %s <infile>" % progname
2013-04-05 10:44:48 -06:00
2013-10-02 12:59:40 -06:00
def cli_main(argv=sys.argv):
progname = os.path.basename(argv[0])
2013-04-05 10:44:48 -06:00
2013-10-02 12:59:40 -06:00
if len(argv)<2:
usage(progname)
sys.exit(2)
2013-04-05 10:44:48 -06:00
2013-10-02 12:59:40 -06:00
keypath = argv[1]
with open(keypath, 'rb') as f:
keyder = f.read()
print keyder.encode('base64')
2013-04-05 10:44:48 -06:00
return 0
2013-10-02 12:59:40 -06:00
if __name__ == '__main__':
sys.exit(cli_main())