def build_dsc(debinfo,<EOL>dist_dir,<EOL>repackaged_dirname,<EOL>orig_sdist=None,<EOL>patch_posix=<NUM_LIT:0>,<EOL>remove_expanded_source_dir=<NUM_LIT:0>,<EOL>debian_dir_only=False,<EOL>sign_dsc=False,<EOL>):
<EOL>if debian_dir_only:<EOL><INDENT>fullpath_repackaged_dirname = os.path.abspath(os.curdir)<EOL><DEDENT>else:<EOL><INDENT>fullpath_repackaged_dirname = os.path.join(dist_dir,repackaged_dirname)<EOL><DEDENT>if not debian_dir_only:<EOL><INDENT>repackaged_orig_tarball = ('<STR_LIT>'%<EOL>debinfo.__dict__)<EOL>repackaged_orig_tarball_path = os.path.join(dist_dir,<EOL>repackaged_orig_tarball)<EOL>if orig_sdist is not None:<EOL><INDENT>if os.path.exists(repackaged_orig_tarball_path):<EOL><INDENT>os.unlink(repackaged_orig_tarball_path)<EOL><DEDENT>link_func(orig_sdist,repackaged_orig_tarball_path)<EOL><DEDENT>else:<EOL><INDENT>make_tarball(repackaged_orig_tarball,<EOL>repackaged_dirname,<EOL>cwd=dist_dir)<EOL><DEDENT>if debinfo.patch_file != '<STR_LIT>':<EOL><INDENT>apply_patch(debinfo.patch_file,<EOL>posix=patch_posix,<EOL>level=debinfo.patch_level,<EOL>cwd=fullpath_repackaged_dirname)<EOL><DEDENT><DEDENT>for fname in ['<STR_LIT>','<STR_LIT>']:<EOL><INDENT>if os.path.exists(os.path.join(fullpath_repackaged_dirname,fname)):<EOL><INDENT>sys.stderr.write('<STR_LIT:*>'*<NUM_LIT:1000> + '<STR_LIT:\n>')<EOL>sys.stderr.write('<STR_LIT>'<EOL>'<STR_LIT>'<EOL>'<STR_LIT>'<EOL>'<STR_LIT>')<EOL>sys.stderr.write('<STR_LIT:*>'*<NUM_LIT:1000> + '<STR_LIT:\n>')<EOL><DEDENT><DEDENT>debian_dir = os.path.join(fullpath_repackaged_dirname,'<STR_LIT>')<EOL>if not os.path.exists(debian_dir):<EOL><INDENT>os.mkdir(debian_dir)<EOL><DEDENT>changelog = CHANGELOG_FILE%debinfo.__dict__<EOL>with codecs.open( os.path.join(debian_dir,'<STR_LIT>'),<EOL>mode='<STR_LIT:w>', encoding='<STR_LIT:utf-8>') as fd:<EOL><INDENT>fd.write(changelog)<EOL><DEDENT>if debinfo.uploaders:<EOL><INDENT>debinfo.uploaders = '<STR_LIT>' % '<STR_LIT:U+002CU+0020>'.join(debinfo.uploaders)<EOL><DEDENT>else:<EOL><INDENT>debinfo.uploaders = '<STR_LIT>'<EOL><DEDENT>control = CONTROL_FILE%debinfo.__dict__<EOL>with codecs.open( os.path.join(debian_dir,'<STR_LIT>'),<EOL>mode='<STR_LIT:w>', encoding='<STR_LIT:utf-8>') as fd:<EOL><INDENT>fd.write(control)<EOL><DEDENT>debinfo.percent_symbol = '<STR_LIT:%>'<EOL>rules = RULES_MAIN%debinfo.__dict__<EOL>rules = rules.replace('<STR_LIT:U+0020>','<STR_LIT:\t>')<EOL>rules_fname = os.path.join(debian_dir,'<STR_LIT>')<EOL>with codecs.open( rules_fname,<EOL>mode='<STR_LIT:w>', encoding='<STR_LIT:utf-8>') as fd:<EOL><INDENT>fd.write(rules)<EOL><DEDENT>os.chmod(rules_fname,<NUM_LIT>)<EOL>fd = open( os.path.join(debian_dir,'<STR_LIT>'), mode='<STR_LIT:w>')<EOL>fd.write('<STR_LIT>')<EOL>fd.close()<EOL>if debinfo.mime_file != '<STR_LIT>':<EOL><INDENT>if not os.path.exists(debinfo.mime_file):<EOL><INDENT>raise ValueError(<EOL>'<STR_LIT>'%(<EOL>debinfo.mime_file,))<EOL><DEDENT>link_func( debinfo.mime_file,<EOL>os.path.join(debian_dir,debinfo.package+'<STR_LIT>'))<EOL><DEDENT>if debinfo.shared_mime_file != '<STR_LIT>':<EOL><INDENT>if not os.path.exists(debinfo.shared_mime_file):<EOL><INDENT>raise ValueError(<EOL>'<STR_LIT>'%(<EOL>debinfo.shared_mime_file,))<EOL><DEDENT>link_func( debinfo.shared_mime_file,<EOL>os.path.join(debian_dir,<EOL>debinfo.package+'<STR_LIT>'))<EOL><DEDENT>if debinfo.copyright_file != '<STR_LIT>':<EOL><INDENT>link_func( debinfo.copyright_file,<EOL>os.path.join(debian_dir,'<STR_LIT>'))<EOL><DEDENT>if len(debinfo.install_file_lines):<EOL><INDENT>fd = open( os.path.join(debian_dir,'<STR_LIT>'%debinfo.package), mode='<STR_LIT:w>')<EOL>fd.write('<STR_LIT:\n>'.join(debinfo.install_file_lines)+'<STR_LIT:\n>')<EOL>fd.close()<EOL><DEDENT>if debinfo.udev_rules != '<STR_LIT>':<EOL><INDENT>fname = debinfo.udev_rules<EOL>if not os.path.exists(fname):<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>link_func(fname,<EOL>os.path.join(debian_dir,'<STR_LIT>'%debinfo.package))<EOL><DEDENT>os.mkdir(os.path.join(debian_dir,'<STR_LIT:source>'))<EOL>fd = open( os.path.join(debian_dir,'<STR_LIT:source>','<STR_LIT>'), mode='<STR_LIT:w>')<EOL>fd.write('<STR_LIT>')<EOL>fd.close()<EOL>fd = open( os.path.join(debian_dir,'<STR_LIT:source>','<STR_LIT>'), mode='<STR_LIT:w>')<EOL>fd.write('<STR_LIT>')<EOL>fd.close()<EOL>if debian_dir_only:<EOL><INDENT>return<EOL><DEDENT>debianized_package_dirname = fullpath_repackaged_dirname+'<STR_LIT>'<EOL>if os.path.exists(debianized_package_dirname):<EOL><INDENT>raise RuntimeError('<STR_LIT>' %<EOL>debianized_package_dirname)<EOL><DEDENT>os.rename(fullpath_repackaged_dirname, debianized_package_dirname )<EOL>if orig_sdist is not None:<EOL><INDENT>tmp_dir = os.path.join(dist_dir,'<STR_LIT>')<EOL>os.mkdir(tmp_dir)<EOL>try:<EOL><INDENT>expand_tarball(orig_sdist,cwd=tmp_dir)<EOL>orig_tarball_top_contents = os.listdir(tmp_dir)<EOL>assert len(orig_tarball_top_contents)==<NUM_LIT:1><EOL>orig_dirname = orig_tarball_top_contents[<NUM_LIT:0>]<EOL>fullpath_orig_dirname = os.path.join(tmp_dir,orig_dirname)<EOL>shutil.rmtree(fullpath_orig_dirname)<EOL><DEDENT>finally:<EOL><INDENT>shutil.rmtree(tmp_dir)<EOL><DEDENT><DEDENT>if <NUM_LIT:1>:<EOL><INDENT>debhelper_version_str = get_version_str('<STR_LIT>')<EOL>if len(debhelper_version_str)==<NUM_LIT:0>:<EOL><INDENT>log.warn('<STR_LIT>'<EOL>'<STR_LIT>'<EOL>'<STR_LIT>'%DH_MIN_VERS)<EOL><DEDENT>else:<EOL><INDENT>if not dpkg_compare_versions(<EOL>debhelper_version_str, '<STR_LIT>', DH_MIN_VERS ):<EOL><INDENT>log.warn('<STR_LIT>'<EOL>'<STR_LIT>'<EOL>'<STR_LIT>'%(<EOL>DH_MIN_VERS,))<EOL><DEDENT><DEDENT>python_defaults_version_str = get_version_str('<STR_LIT>')<EOL>if len(python_defaults_version_str)==<NUM_LIT:0>:<EOL><INDENT>log.warn('<STR_LIT>'<EOL>'<STR_LIT>'<EOL>'<STR_LIT>'%PYTHON_ALL_MIN_VERS)<EOL><DEDENT>else:<EOL><INDENT>if not dpkg_compare_versions(<EOL>python_defaults_version_str, '<STR_LIT>', PYTHON_ALL_MIN_VERS):<EOL><INDENT>log.warn('<STR_LIT>'<EOL>'<STR_LIT>'<EOL>'<STR_LIT>'%(<EOL>PYTHON_ALL_MIN_VERS,))<EOL><DEDENT><DEDENT><DEDENT>os.rename(fullpath_repackaged_dirname+'<STR_LIT>',<EOL>fullpath_repackaged_dirname)<EOL>if sign_dsc:<EOL><INDENT>args = ()<EOL><DEDENT>else:<EOL><INDENT>args = ('<STR_LIT>','<STR_LIT>')<EOL><DEDENT>dpkg_buildpackage('<STR_LIT>','<STR_LIT>',*args,cwd=fullpath_repackaged_dirname)<EOL>if <NUM_LIT:1>:<EOL><INDENT>shutil.rmtree(fullpath_repackaged_dirname)<EOL><DEDENT>if not remove_expanded_source_dir:<EOL><INDENT>dsc_name = debinfo.source + '<STR_LIT:_>' + debinfo.dsc_version + '<STR_LIT>'<EOL>dpkg_source('<STR_LIT>',dsc_name,<EOL>cwd=dist_dir)<EOL><DEDENT>
make debian source package