[Debian-in-commits] [SCM] dh-make-font.git branch, master, updated. 197cb2fff43cd34414433b4bf98cf8ac83679176

Vasudev Kamath kamathvasudev at gmail.com
Wed Sep 19 07:03:34 UTC 2012


The following commit has been merged in the master branch:
commit 0517d2fd3de4fa569e1d3792e0687a856cb5c00d
Author: Vasudev Kamath <kamathvasudev at gmail.com>
Date:   Mon Jul 16 22:30:30 2012 +0530

    Added -u option to insert upstream url in control file and if --maint not provided then update with pkg-fonts git repository url for Vcs-Git and Vcs-Browser fields (avoiding Svn purposefully ;-) )

diff --git a/dh-make-font b/dh-make-font
index ffdb543..91963e6 100755
--- a/dh-make-font
+++ b/dh-make-font
@@ -2,10 +2,117 @@
 
 import sys
 import os
+import re
+import argparse
 
-from variables import *
-from dhmakehelper import call_dh_make
+##########################################################################
+#                                                                        #
+# Variables                                                              #
+#                                                                        #
+##########################################################################
 
+required_files = ["control", "copyright", "changelog", "source", "compat",
+                  "rules", "format"]
+
+DEFAULT_MAINTAINER = "Debian Fonts Task Force <pkg-fonts-devel at 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 = ""
+
+
+GENERATES_TTF = False
+GENERATES_OTF = False
+
+font_reg_exp = re.compile("((.)*\.ttf|sfd|otf)")	# RE to check
+font_sfd_regx = re.compile("((.)*\.sfd)")           # RE to check font source file
+generate_function = re.compile("Generate\(.*\)")
+
+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 at lists.alioth.debian.org>''')
+arguments.add_argument('foldername',
+                       help='Extracted folder containing fonts')
+
+arguments.add_argument('-u','--upstream',
+                       help='''Provide an upstream URL. If this value is provided
+                               it will be substituted in control and copyright file''')
+
+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.2''')
+
+
+
+###########################################################################
+#                                                                         #
+#  Validation functions                                                   #
+#                                                                         #
+###########################################################################
+
+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 check_generatepe(filepath):
+        global GENERATES_TTF, GENERATES_OTF
+        with open(filepath) as fd:
+                content = fd.read()
+                if generate_function.search(content):
+                        # We did find Generate function
+                        for function in generate_function.findall(content):
+                                if function.find('.ttf') != -1:
+                                        GENERATES_TTF = True
+                                        break
+                                elif function.find('.otf') != -1:
+                                        GENERATES_OTF = True
+                                        break
+
+
+
+###########################################################################
+#                                                                         #
+# Functions which edit the files inside debian/ folder of package         #
+#                                                                         #
+###########################################################################
 
 def update_control_file(args):
         """
@@ -50,6 +157,12 @@ def update_control_file(args):
                                 control_content += "Priority: optional"
                         elif line.startswith('Depends:'):
                                 control_content += "Depends: ${misc:Depends}"
+                        elif line.startswith('Homepage:') and args.upstream:
+                                control_content += "Homepage: " + args.upstream
+                        elif line.startswith('#Vcs-Git:') and not args.maint:
+                                control_content += "Vcs-Git: " + 'git://git.debian.org/pkg-fonts/' + PACKAGE + '.git'
+                        elif line.startswith('#Vcs-Browser:') and not args.maint:
+                                control_content += "Vcs-Browser: " + 'http://git.debian.org/?p=pkg-fonts/' + PACKAGE + '.git;a=summary'
                         else:
                                 control_content += line
 
@@ -57,8 +170,8 @@ def update_control_file(args):
                                 
                 with open('control','wb') as fd:
                         fd.write(control_content)
-                
-def create_install_and_links():
+
+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
@@ -66,36 +179,123 @@ def create_install_and_links():
            linking
         """
         global PACKAGE
-        install_dir = PACKAGE.split('fonts-')[1]
         install = ""
+        install_dir = PACKAGE.split('fonts-')[1]
+        
         for dirpath,dirnames,filenames in os.walk('..'):
                 if dirnames != 'debian':
                         for filename in filenames:
                                 if filename.endswith('.ttf'):
-                                        install += "./"+filename + " usr/share/fonts/truetype/" + install_dir + "/\n"
+                                        install += "./"+filename + \
+                                                   " usr/share/fonts/truetype/" + install_dir + "/\n"
                                 elif filename.endswith('.otf'):
-                                        install += "./"+filename + " usr/share/fonts/truetype/" + install_dir + "/\n"
+                                        install += "./"+filename + \
+                                                   " usr/share/fonts/truetype/" + install_dir + "/\n"
                                 elif filename.endswith('.sfd'):
                                         if 'generate.pe' in filenames:
                                                 check_generatepe(os.path.join(dirpath,filenames[filenames.index('generate.pe')]))
                                                 if GENERATES_TTF:
-                                                        install += "./"+filename.replace('sfd','ttf') + " usr/share/fonts/truetype/" + install_dir + "/\n"
+                                                        install += "./"+filename.replace('sfd','ttf')\
+                                                                   + " usr/share/fonts/truetype/" + install_dir + "/\n"
                                                 elif GENERATES_OTF:
-                                                        install += "./"+filename.replace('sfd','otf') + " usr/share/fonts/opentype/" + install_dir + "/\n"
+                                                        install += "./"+filename.replace('sfd','otf')\
+                                                                   + " usr/share/fonts/opentype/" + install_dir + "/\n"
                                                 else:
-                                                        print "\n*Unable to determine if source generates TTF or OTF file. Please manually edit the debian/install file*"      
+                                                        print "\n*Unable to determine if source generates TTF or OTF file.\nPlease manually edit the debian/install file*"
                                         else:
-                                                print "\n*Unable to determine if source generates TTF or OTF file. Please manually edit the debian/install file*"
-                                        
+                                                print "\n*Unable to determine if source generates TTF or OTF file.\nPlease manually edit the debian/install file*"
+                                                        
                                 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"
-                                                
+                                                print '''\nI've symlinked conf file in etc/fonts/conf.d.\nPlease update fontconfig priority appropriately'''
         with open('install','w') as fd:
                 fd.write(install)
+        
+
+
+###########################################################################
+#                                                                         #
+#  dh_make helper function                                                #
+#                                                                         #
+###########################################################################
+
+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)
+
+
+###########################################################################
+#                                                                         #
+#  Generic functions                                                      #
+#                                                                         #
+###########################################################################
 
 def print_todo():
         print("""
@@ -112,7 +312,9 @@ def print_todo():
        proper in debian/install
     7. Build the package and enjoy!
 """)
-                               
+
+
+
 def main():
         """
         Main part of the script. Kept in seperate function to have a good

-- 
dh-make-font.git



More information about the Debian-in-commits mailing list