Skip to main content

A tool to extract source code for China Software Copyright application.

Project description

Copyright Code Extractor

A tool to automatically extract source code from a project into the source-program identification material (程序鉴别材料) required for a China Software Copyright (软著) registration.

It scans a project directory, finds source files by extension, strips comments and blank lines, and writes an A4 DOCX with exactly 50 code lines per page, a header carrying the software name + version, and an automatic page number — matching the CPCC (中国版权保护中心) filing requirements.

Compliance checklist

Official basis: Article 10 of the Measures for the Registration of Computer Software Copyright (《计算机软件著作权登记办法》第十条, NCAC Order No. 1) — a copy is included at docs/计算机软件著作权登记办法.pdf (source).

CPCC requirement How it is handled
First 30 + last 30 consecutive pages (60 pages total); submit everything if shorter --all keeps the first/last 1500 lines automatically
At least 50 lines per page Exactly 50 lines per page; long lines are hard-wrapped so pagination never drifts
Header shows software name + version, identical to the application form --name / --soft-version (or config); centred in the page header
Page number at the top right Word PAGE field, numbered continuously from 1
No large blank areas / blank lines Blank lines and comments are stripped
PDF upload Built-in: --pdf exports a PDF next to the DOCX, or -o file.pdf for PDF only

The header text must match the registration form character-for-character. If --name is omitted the project directory name is used and a warning is logged.

Installation

Quick run — no install, no clone (recommended for AI agents):

# uv downloads, caches and runs the published CLI in one step
uvx copyright-code-extractor /path/to/project --all --name "某某系统" --soft-version V1.0 --pdf -o 源代码.docx

# pipx works the same way
pipx run copyright-code-extractor --help

Standalone binaries (no Python required): download from GitHub Releaseslinux-x86_64 / linux-arm64 / macos-arm64 / macos-x86_64 / windows-x86_64.

curl -LO https://github.com/kirklin/copyright-code-extractor/releases/latest/download/copyright-code-extractor-macos-arm64
chmod +x copyright-code-extractor-macos-arm64 && ./copyright-code-extractor-macos-arm64 --help

From source:

uv sync            # development
pip install -e .   # or any environment

Usage

# Typical filing: first 30 + last 30 pages, proper header, DOCX + PDF
uv run copyright-code-extractor /path/to/your/project \
  --all \
  --name "某某管理系统" \
  --soft-version V1.0 \
  --pdf \
  -o 源代码.docx

Options:

  • -n, --name TEXT: Software name for the page header (must match the application form).
  • --soft-version TEXT: Software version for the page header (default: V1.0).
  • --all: Extract everything, then apply the first 30 + last 30 pages rule.
  • --pdf: Also export a PDF next to the DOCX (embeds a system CJK font, auto-detected; override with pdf_font_path in the config).
  • -o, --output FILE_PATH: Output DOCX path.
  • -l, --lines NUM_LINES: Total number of lines to extract when not using --all (default: 3000).
  • -c, --config CONFIG_FILE: Path to a custom configuration file.
  • -v, --verbose: Verbose logging.
  • --version: Show the tool version and exit.

Configuration

Create a .copyright-extractor.json in the root of the project being analyzed. Command-line options override the config file.

{
  "software_name": "某某管理系统",
  "software_version": "V1.0",
  "output_file": "源代码.docx",
  "extract_all": true,
  "source_root": "src",
  "ignore_patterns": ["tests", "docs", "*.min.js"],
  "include_extensions": [".py", ".ts", ".tsx", ".vue", ".go"]
}

Useful defaults you can override:

  • lines_per_page (50), keep_pages_head / keep_pages_tail (30 / 30)
  • max_line_width (90) — wrap display width (CJK counts as 2) that keeps one code line = one printed line
  • pdf_font_path — TTF/TTC with CJK glyphs to embed in the PDF when auto-detection fails
  • ignore_patterns — already covers .git, node_modules, dist, build, .next, .nuxt, .output, .turbo, coverage, minified assets, etc.

See src/copyright_code_extractor/config.py for the full list.

Notes

  • ~100 source extensions are extracted by default, covering every major language family — C/C++/Java/Kotlin/Go/Rust/Swift/JS/TS/Python/C#/F#/VB/PHP/Ruby/Lua/ SQL/Haskell/OCaml/Erlang/Elixir/Fortran/Pascal/PowerShell/assembly/Verilog/VHDL and more — each with its own comment syntax (e.g. -- for SQL, {- -} for Haskell, <# #> for PowerShell). Unknown extensions can be added via include_extensions and fall back to string-aware //, #, /* */ stripping.
  • Comment stripping is string-aware: URLs or #fff inside string literals survive. Known limitation: an unescaped // inside a JS regex literal is treated as a comment.
  • The generated DOCX uses Consolas 9pt (SimSun for CJK), single spacing, A4 with 2 cm margins, widow/orphan control disabled — so 50 lines per page is exact.

License

This project is licensed under the GNU General Public License v3.0.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

copyright_code_extractor-0.2.1.tar.gz (300.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

copyright_code_extractor-0.2.1-py3-none-any.whl (27.8 kB view details)

Uploaded Python 3

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page