[Debian-in-commits] [SCM] dh-make-font.git branch, vasudev, updated. d2268aa8ac1f01c19c624cbd14485a83530f5c15
Vasudev Kamath
kamathvasudev at gmail.com
Sun Dec 18 14:39:18 UTC 2011
The following commit has been merged in the vasudev branch:
commit d2268aa8ac1f01c19c624cbd14485a83530f5c15
Author: Vasudev Kamath <kamathvasudev at gmail.com>
Date: Sun Dec 18 19:42:16 2011 +0530
Added comments and reorganized the code
diff --git a/dh-make-font b/dh-make-font
index 155385f..64eacdf 100755
--- a/dh-make-font
+++ b/dh-make-font
@@ -9,7 +9,8 @@ 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"
+UPLOADERS = (os.environ.get('DEBFULLNAME') + " " + os.environ.get('DEBEMAIL'))\
+ if os.environ.has_key('DEBEMAIL') else "#Please fill in your name and email"
font_reg_exp = re.compile("((.)*\.ttf|sfd|otf)") # RE to check
@@ -18,6 +19,7 @@ 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')
@@ -36,10 +38,17 @@ arguments.add_argument('foldername',
help='Extracted folder containing fonts')
-# Function which checks if the necessary files are there in the directory.
-# Returns a 0 If the required files are found.
-# Else returns a non zero value
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
+
+ """
+
# 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('.'):
@@ -49,18 +58,44 @@ def check_files():
return -1 # No need to go into sub directories
return -1
-# Failure : Non 0 value
-# Sucess : 0
-def call_dh_make(args):
+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 against the dh_make command
+
+ """
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
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 :)
+
+ """
+ if args.foldername.find('-'):
+ args.foldername = args.foldername.replace('-','_')
+
if not args.foldername.startswith('fonts-'):
- if args.foldername.find('-'):
- args.foldername = args.foldername.replace('-','_')
args_string += " -p fonts-" + args.foldername
else:
args_string += " -p " + args.foldername
@@ -69,51 +104,81 @@ def call_dh_make(args):
return os.system("dh_make"+args_string)
-if __name__ == "__main__":
- args = arguments.parse_args()
- os.chdir(os.path.abspath(args.foldername))
- # Main flow to call the functions.
- if(check_files()!=0):
- print("I could not find .ttf, .sfd, .otf. Atleast one should be there. Dying.")
+def update_control_file():
+ """
+
+ 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:'):
+ control_content += line +"#,fontforge"
+ 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 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()!=0):
+ print("I could not find .ttf, .sfd, .otf. Atleast one should be there. Dying.")
exit(256)
- if(call_dh_make(args)):
- print("dh_make_font: dh_make died so I dye.")
+ if(call_dh_make(args)):
+ print("dh_make_font: dh_make died so I dye.")
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)
-
- 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:'):
- control_content += line +"#,fontforge"
- 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)
+ 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()
+
+if __name__ == "__main__":
+ main()
--
dh-make-font.git
More information about the Debian-in-commits
mailing list