[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

[Pkg-fonts-devel] Bug#658154: dh-make: Please add dh-make-font script into dh-make package



Package: dh-make
Version: 0.59
Severity: wishlist

dh-make-font is Font packaging helper for Debian. This thread explains use of
the tool [1] and in this discussion thread [2] in pkg-fonts in which we decided
to raise this bug to include dh-make-font as part of dh-make package. Please
consider adding these script into dh-make package. Source of the script is
available here [3] in collab-maint

[1] http://lists.alioth.debian.org/pipermail/pkg-fonts-
devel/2011-December/009273.html
[2] http://lists.alioth.debian.org/pipermail/pkg-fonts-
devel/2012-January/009519.html
[3] http://anonscm.debian.org/gitweb/?p=collab-maint/dh-make-font.git;a=summary

Thank you



-- System Information:
Debian Release: wheezy/sid
  APT prefers testing
  APT policy: (500, 'testing')
Architecture: amd64 (x86_64)

Kernel: Linux 3.1.0-1-amd64 (SMP w/2 CPU cores)
Locale: LANG=C, LC_CTYPE= (charmap=ANSI_X3.4-1968)
Shell: /bin/sh linked to /bin/dash

Versions of packages dh-make depends on:
ii  debhelper  9.20120115
ii  dpkg-dev   1.16.1.2
ii  make       3.81-8.1
ii  perl       5.14.2-6

dh-make recommends no packages.

Versions of packages dh-make suggests:
ii  build-essential  11.5

-- no debconf information
..TH dh-make-font 1 "December 2011"
..SH NAME
dh\-make\-font \- Debian Font packaging helper

..SH SYNOPSIS
..B dh\-make\-font
[
..B \-h, \-\-help
]

..B dh\-make\-font
[
..B \-c, \-\-copyright <type>
]
..I font_folder

..B dh\-make\-font
[
..B \-p, \-\-package <name[_version]>
]
..I font_folder

..B dh\-make\-font
[
..B \-\-maint MAINT]
]
..I font_folder

..SH DESCRIPTION
..PP
dh\-make\-font tool is a wrapper on dh_make command. This is a font package
helper for Debian.
..PP
..SH GENERAL OPTIONS

..TP
\-h, \-\-help
Print a help message.

..TP
\-c <type>, \-\-copyright <type>
Use <type> as license in copyright file for the package. Type can be
one of apache|artistic|bsd|gpl|gpl2|gpl3|lgpl|lgpl2|lgpl3|x11.

..TP
\-p <name[_version]>, \-\-package <name[_version]>
Force package name to be <name> if name_version is given this will set
version number of package bypassing the directory checking.

..TP
\-\-maint <MAINTAINER>
Override default maintainer by MAINTAINER. By default maintainer is set
to *Debian Fonts Task Force*. MAINTAINER should be in the form
..I Maintainer Name <maint.email>

..TP
..I font_folder
This is the name of the folder in which you have extracted the fonts.
Rules for folder name are same as dh_make. If you didn't give proper
name dh_make will fail.

..TP
\-v, \-\-version
Show the version number of program and exit.


..SH COPYRIGHT AND AUTHORS
Copyright \(co 2011-2012 Vasudev Kamath <kamathvasudev@gmail.com>
            2011-2012 Muneeb Shaikh <iammuneeb@gmail.com>
            2011-2012 Shravan Aras <123.shravan@gmail.com>

License GPLv2: GNU GPL version 2 <http://gnu.org/licenses/gpl2.html>.


This man page is written by Vasudev Kamath <kamathvasudev@gmail.com> and Muneeb Shaikh <iammuneeb@gmail.com>
#!/usr/bin/env python

import argparse
import sys
import os
import re


required_files = ["control", "copyright", "changelog", "source", "compat",
                  "rules", "format"]
DEFAULT_MAINTAINER = "Debian Fonts Task Force <pkg-fonts-devel@lists.alioth.debian.org>"
UPLOADERS = (os.environ.get('DEBFULLNAME') + " <" + os.environ.get('DEBEMAIL') + ">")\
    if os.environ.has_key('DEBEMAIL') else "#Please fill in your name and email"
PACKAGE = ""

font_reg_exp = re.compile("((.)*\.ttf|sfd|otf)")	# RE to check
font_sfd_regx = re.compile("((.)*\.sfd)")           # RE to check font source file
font_source=False

watch = """
version=3
#please put upstream url for watch expression
"""


# This section of code parses the command line arguments.
arguments = argparse.ArgumentParser(description='dh-make-font',
                                   epilog='Font package helper')
arguments.add_argument('-c','--copyright',
                       help='''use <type> of license in copyright file
                            (apache|artistic|bsd|gpl|gpl2|gpl3|lgpl|lgpl2|
                             lgpl3|x11)''')
arguments.add_argument('-p','--package',
                       help='''force package name to be <name>
                            if name_version is given this will set version
                            number of package bypassing the directory checking.''')
arguments.add_argument('--maint',
                       help='''Override default *Maintainer* which is
                             Debian Fonts Task Force <pkg-fonts-devel@lists.alioth.debian.org>''')
arguments.add_argument('foldername',
                       help='Extracted folder containing fonts')
arguments.add_argument('-v', '--version', action='version',
                        help='Show the version number of dh_make_font', 
                        version='''%(prog)s -  prepare Debian packaging for fonts, version 0.1''')


def check_files():
        """
           This function checks if there is either .ttf .otf or .sfd
           file in the given folder. If that file is present only then
           we will continue after all this tool is for font packaging :)

           `-return` 0 if one of the .sfd .ttf or .otf file is present
                     -1 other wise
                     
        """
	global font_source        
	# We need to perform a directory traversal to find .ttf .otf or .sfd.
	# Any one will do. [We are so kind arn't we]
	for dirpath,dirnames,filenames in os.walk('.'):
		for filename in filenames:
			if font_reg_exp.search(filename):
				if font_sfd_regx.search(filename):
					font_source=True
				return 0
		return -1 # No need to go into sub directories
	return -1

def call_dh_make(args):
        """
            `-args`: Arguments passed to this script this is of type NameSpace
                    class returned by argparse.parse_args
            `-return`: Returns 0 like all other *nix utilities on success and non
                       zero value on error. Error should be documented in dh_make
                       manual
                       
           This function is a wrapper over the dh_make command 

        """
        global PACKAGE
        
	args_string = " -createorig" # Stores the final argument to be passed to dh_make
	if(args.copyright):
		args_string += " -c "+args.copyright
	if(args.package):
		args_string += " -p "+args.package
                PACKAGE = args.package.split('_')[0] if args.package.find('_') else args.package
        else:
                """
                   If user has not supplied -p or --package option which should be passed to
                   dh_make then we will do it ourselves rather than allowing dh_make to decide

                   According to pkg-fonts policy font package should be named `fonts-<foundry>-something`
                   where foundry is optional.

                    1. We will check if folder name begins with fonts- if yes we will pass it to dh_make
                       with -p option.
                    2. If it doesn't we will create package name by appending fonts- to `foldername`

                  Additionally foldername-version is changed to foldername_version which is expected by
                  dh_make as value for -p option

                  In case of any error dh_make will bark at you and not me :)
                    
                """
                folder = ""
                if args.foldername.count('-') > 1:
                        """
                          If we have more than one - in foldername that means foldername is in
                          format folder-name-version. So lets split on - and join first 2 part
                          again on - and join last part with the latter with _ in between

                          #FIXME: Bad English?
                          #FIXME: Any better way?
                          
                        """
                        folder_split = args.foldername.split('-')
                        folder = ('-').join(folder_split[:-1]) + '_' + folder_split[-1]
                elif args.foldername.count('-') == 1:
                        """
                          If there is only one - we are happy :)
                        """
                        folder = args.foldername.replace('-','_')


                if not folder.startswith('fonts-'):
                        args_string += " -p fonts-" + folder
                        folder = 'fonts-' + folder
                else:
                        args_string += " -p " + folder
                        
                PACKAGE = folder.split('_')[0] if folder.find('_') else folder
                        
	# Make a call to the system function.
	return os.system("dh_make"+args_string)


def update_control_file(args):
        """
        
           This function updates the control file which is generated by
           dh_make
             1. Section is set to fonts
             2. Priority optional
             3. if Maintainer is not overriden by --maint DEFAULT_MAINTAINER
                else use value given by user with --maint
             4. Uploaders is added using DEBEMAIL and DEBFULLNAME environment
                variable
             5. Build-Depends will have fontforge dependency as a comment in
                case upstream provides .sfd, user can uncomment it.
             6. Architecture is changed to all
             7. shlibs depends is removed from Depends

           All remaining are kept as is and finally written back to control file
           
        """
        control_content = ""
        with open('control',"rb") as fd:
                contents = fd.read().split('\n')
                for line in contents:
                        if line.startswith('Maintainer:'):
                                if args.maint:
                                        control_content += "Maintainer: "+args.maint
                                else:
                                        control_content += "Maintainer: " + DEFAULT_MAINTAINER

                                control_content += "\nUploaders: "+UPLOADERS
                        elif line.startswith('Build-Depends:'):
                                if font_source:
                                        control_content += line +", fontforge"
                                else:
                                        control_content += line
                        elif line.startswith('Architecture:'):
                                control_content += "Architecture: all"
                        elif line.startswith('Section:'):
                                control_content += "Section: fonts"
                        elif line.startswith('Priority:'):
                                control_content += "Priority: optional"
                        elif line.startswith('Depends:'):
                                control_content += "Depends: ${misc:Depends}"
                        else:
                                control_content += line

                        control_content += "\n"
                                
                with open('control','wb') as fd:
                        fd.write(control_content)

def create_install_and_links():
        """
           This function writes install file it checks for availabilty of
           ttf or otf file and writes a proper install file also if a font
           config .conf file is available creates a links file to do proper
           linking
        """
        global PACKAGE
        install = ""
        for dirpath,dirnames,filenames in os.walk('..'):
                if dirnames != 'debian':
                        for filename in filenames:
                                if filename.endswith('.ttf'):
                                        install += "./"+filename + " usr/share/fonts/truetype/" + PACKAGE + "/"
                                elif filename.endswith('.otf'):
                                        install += "./"+filename + " usr/share/fonts/truetype/" + PACKAGE + "/"
                                elif filename.endswith('.conf'):
                                        install += "./"+filename + " etc/fonts/conf.avail"
                                        print "\nFound a fontconfig configuration file. Added it to debian/install"
                                        with open('links','w') as fd:
                                                fd.write('etc/fonts/conf.avail/'+filename + ' etc/fonts/conf.d/'+filename)
                                                print "\nI've symlinked conf file in etc/fonts/conf.d. Please update fontconfig priority appropriately"
                                                
                                # TODO: What to do when sfd?
                                install += "\n"
        with open('install','w') as fd:
                fd.write(install)

def print_todo():
        print("""
**************************************************
       TODO for the maintainers
**************************************************

    1. Please add short and long description in debian/control file
    2. Please add appropriate lines in debian/changelog
    3. Please add DEP5 format URI in debian/copyright
    4. Please add fonts copyright in debian/copyright
    5. Check debian/install and debian/links if they exist
    6. Build the package and enjoy!
""")
                               
def main():
        """
        Main part of the script. Kept in seperate function to have a good
        redability
        """
        args = arguments.parse_args()
        os.chdir(os.path.abspath(args.foldername))

        if(check_files()):
                print("I could not find .ttf, .sfd, .otf. At least one should be present.")
                exit(256)

        if(call_dh_make(args)):
                print("dh_make_font: dh_make died so I die.")
                exit(256)

        os.chdir(os.path.abspath('debian'))
        for dirpath,dirname,filenames in os.walk('.'):
                for filename in filenames:
                        if not filename in required_files:
                                os.remove(filename)

        with open('watch','w') as fd:
                fd.write(watch)        

        update_control_file(args)
        create_install_and_links()
        print_todo()

if __name__ == "__main__":
        main()

Reply to: