--- airprint-generate.py 2012-10-06 19:49:51.000000000 +0200 +++ airprint-generate-rh.py 2015-04-07 20:35:38.626843480 +0200 @@ -20,6 +20,14 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +2015-04-07 Frank Bergmann, www.tuxad.com: + - blacklist some more types + - Red Hat / Fedora specific modifications: + * use /etc/avahi/services as default + * if image/urf is not available then create types/convs files (with + convs using pdftops as filter), recommend restarting cups and running + this script again """ import cups, os, optparse, re, urlparse @@ -85,8 +93,10 @@ 'image/x-xwindowdump': False, 'image/x-xpixmap': False, 'image/x-xbitmap': False, + 'image/x-bitmap': False, 'image/x-sun-raster': False, 'image/x-sgi-rgb': False, + 'image/x-photocd': False, 'image/x-portable-pixmap': False, 'image/x-portable-graymap': False, 'image/x-portable-bitmap': False, @@ -95,6 +105,8 @@ 'application/x-perl': False, 'application/x-csource': False, 'application/x-cshell': False, + 'application/vnd.cups-raw': False, + 'text/css': False, } class AirPrintGenerate(object): @@ -107,6 +119,7 @@ self.directory = directory self.prefix = prefix self.adminurl = adminurl + self.types_created = False if self.user: cups.setUser(self.user) @@ -191,7 +204,17 @@ defer.append(a) if 'image/urf' not in fmts: - sys.stderr.write('image/urf is not in mime types, %s may not be available on ios6 (see https://github.com/tjfontaine/airprint-generate/issues/5)%s' % (p, os.linesep)) + if not os.path.exists('/usr/share/cups/mime/airprint.types'): + sys.stderr.write('image/urf is not in mime types, generating airprint.types and airprint.convs; you should restart cups by "systemctl restart cups.service" and run this script again\n') + file = open('/usr/share/cups/mime/airprint.types', 'w') + file.write('image/urf urf string(0,UNIRAST<00>)\n') + file.close() + file = open('/usr/share/cups/mime/airprint.convs', 'w') + file.write('image/urf application/vnd.cups-postscript 66 pdftops\n') + file.close() + self.types_created = True + if not self.types_created: + sys.stderr.write('image/urf is not in mime types, %s may not be available on ios6 (see https://github.com/tjfontaine/airprint-generate/issues/5)%s' % (p, os.linesep)) fmts = ','.join(fmts+defer) @@ -243,7 +266,7 @@ dest='username', help='Username to authenticate with against CUPS', metavar='USER') parser.add_option('-d', '--directory', action="store", type="string", - dest='directory', help='Directory to create service files', + dest='directory', help='Directory to create service files, default: /etc/avahi/services', metavar='DIRECTORY') parser.add_option('-v', '--verbose', action="store_true", dest="verbose", help="Print debugging information to STDERR") @@ -261,15 +284,21 @@ cups.setPasswordCB(getpass) if options.directory: - if not os.path.exists(options.directory): - os.mkdir(options.directory) + servicedir = options.directory + if not os.path.exists(servicedir): + os.mkdir(servicedir) + else: + # default on Red Hat / Fedora: + servicedir = "/etc/avahi/services" + if not os.path.exists(servicedir): + raise Exception('avahi services directory does not exist, maybe you should install avahi.') apg = AirPrintGenerate( user=options.username, host=options.hostname, port=options.port, verbose=options.verbose, - directory=options.directory, + directory=servicedir, prefix=options.prefix, adminurl=options.adminurl, )