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

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


The following commit has been merged in the master branch:
commit 1a963e146b6226850de666386409ddd27b93d0e8
Author: Vasudev Kamath <kamathvasudev at gmail.com>
Date:   Sun Jul 15 22:47:50 2012 +0530

    Split into multiple files to make code more readable

diff --git a/dh-make-font b/dh-make-font
index d1e24b9..ffdb543 100755
--- a/dh-make-font
+++ b/dh-make-font
@@ -1,143 +1,10 @@
 #!/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 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 = ""
-
-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
-
-GENERATES_TTF = False
-GENERATES_OTF = 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('-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)
+from variables import *
+from dhmakehelper import call_dh_make
 
 
 def update_control_file(args):
@@ -190,21 +57,6 @@ def update_control_file(args):
                                 
                 with open('control','wb') as fd:
                         fd.write(control_content)
-
-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
-                        
                 
 def create_install_and_links():
         """
diff --git a/dhmakehelper.py b/dhmakehelper.py
new file mode 100644
index 0000000..3ec2975
--- /dev/null
+++ b/dhmakehelper.py
@@ -0,0 +1,73 @@
+#!/usr/bin/python
+
+import os
+
+from variables import *
+
+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)
diff --git a/validations.py b/validations.py
new file mode 100644
index 0000000..e88eb94
--- /dev/null
+++ b/validations.py
@@ -0,0 +1,44 @@
+#!/usr/bin/python
+
+import os
+
+from variables import *
+
+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
+                        
+
+
diff --git a/variables.py b/variables.py
new file mode 100644
index 0000000..713ab57
--- /dev/null
+++ b/variables.py
@@ -0,0 +1,57 @@
+#!/usr/bin/python
+
+import os
+import re
+import argparse
+
+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''')
+

-- 
dh-make-font.git



More information about the Debian-in-commits mailing list