<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>ZFB</title>
    <description>这是我的个人博客</description>
    <link>https://blog.whuzfb.cn/</link>
    <atom:link href="https://blog.whuzfb.cn/feed.xml" rel="self" type="application/rss+xml" />
    <pubDate>Mon, 21 Jul 2025 18:17:13 +0800</pubDate>
    <lastBuildDate>Mon, 21 Jul 2025 18:17:13 +0800</lastBuildDate>
    <generator>Jekyll v3.10.0</generator>
    
      <item>
        <title>在Linux下通过Docker运行Code Composer Studio</title>
        <description>&lt;h2 class=&quot;no_toc&quot; id=&quot;目录&quot;&gt;目录&lt;/h2&gt;

&lt;ul id=&quot;markdown-toc&quot;&gt;
  &lt;li&gt;&lt;a href=&quot;#1-ccstudio说明&quot; id=&quot;markdown-toc-1-ccstudio说明&quot;&gt;1. CCStudio说明&lt;/a&gt;    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;#11-软件配置情况&quot; id=&quot;markdown-toc-11-软件配置情况&quot;&gt;1.1 软件配置情况&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#2-构建镜像&quot; id=&quot;markdown-toc-2-构建镜像&quot;&gt;2. 构建镜像&lt;/a&gt;    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;#21-自动&quot; id=&quot;markdown-toc-21-自动&quot;&gt;2.1 自动&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#22-手动&quot; id=&quot;markdown-toc-22-手动&quot;&gt;2.2 手动&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#3-运行容器&quot; id=&quot;markdown-toc-3-运行容器&quot;&gt;3. 运行容器&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#4-ccstudio组件&quot; id=&quot;markdown-toc-4-ccstudio组件&quot;&gt;4. CCStudio组件&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#5-其他参考&quot; id=&quot;markdown-toc-5-其他参考&quot;&gt;5. 其他参考&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;1-ccstudio说明&quot;&gt;1. CCStudio说明&lt;/h2&gt;
&lt;p&gt;Docker镜像可在以下位置获取：&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://hub.docker.com/r/whuzfb/ccstudio&quot;&gt;Dockerhub: whuzfb/ccstudio&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/zfb132/ccstudio/pkgs/container/ccstudio&quot;&gt;GHCR: zfb132/ccstudio&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;11-软件配置情况&quot;&gt;1.1 软件配置情况&lt;/h3&gt;
&lt;ol&gt;
  &lt;li&gt;目前理论上支持的&lt;a href=&quot;https://www.ti.com/tool/CCSTUDIO&quot;&gt;CCStudio&lt;/a&gt;版本：
    &lt;ul&gt;
      &lt;li&gt;10.x（已测试版本&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;10.0.0.00010&lt;/code&gt;、&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;10.4.0.00006&lt;/code&gt;）&lt;/li&gt;
      &lt;li&gt;11.x（已测试版本&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;11.0.0.00012&lt;/code&gt;、&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;11.2.0.00007&lt;/code&gt;）&lt;/li&gt;
      &lt;li&gt;12.x（已测试版本&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;12.0.0.00009&lt;/code&gt;、&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;12.8.1.00005&lt;/code&gt;）&lt;/li&gt;
      &lt;li&gt;20.x（已测试版本&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;20.2.0.00012&lt;/code&gt;）&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;支持的Ubuntu版本： ubuntu 20.04及以上版本（已测试版本&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;20.04&lt;/code&gt;、&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;22.04&lt;/code&gt;、&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;24.04&lt;/code&gt;）&lt;/li&gt;
  &lt;li&gt;支持安装指定版本的&lt;a href=&quot;https://www.ti.com/tool/MMWAVE-SDK&quot;&gt;mmWave SDK&lt;/a&gt;，已测试版本&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;03.06.02.00-LTS&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;支持安装指定版本的&lt;a href=&quot;https://software-dl.ti.com/dsps/dsps_public_sw/sdo_sb/targetcontent/bios/sysbios/&quot;&gt;SYS/BIOS&lt;/a&gt;，已测试版本&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;6.73.01.01&lt;/code&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href=&quot;https://github.com/zfb132/ccstudio&quot;&gt;zfb132/ccstudio&lt;/a&gt;目的是提供一个在Linux系统上安装&lt;a href=&quot;https://www.ti.com/tool/CCSTUDIO&quot;&gt;Code Composer Studio&lt;/a&gt;的Docker镜像，方便在Linux系统（无桌面环境）上使用CCStudio进行TI芯片的开发，尤其是适用于CI/CD场景。用户也可以参考仓库的&lt;a href=&quot;https://github.com/zfb132/ccstudio/blob/main/configure.sh&quot;&gt;configure.sh&lt;/a&gt;脚本在自己的Linux系统上安装CCStudio&lt;/p&gt;

&lt;p&gt;容器内部最重要的三个目录：&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/ccs_projects&lt;/code&gt;：CCStudio项目目录（运行容器必须挂载本地目录到此目录，因为entrypoint.sh脚本会在此目录下查找项目文件）&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/workspaces&lt;/code&gt;：CCStudio工作空间目录（容器内部CCS的工作空间目录为/workspaces，编译结果也存放在此目录下）&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/opt/ti&lt;/code&gt;：TI系列产品的安装目录（容器内部CCStudio、mmwave SDK、SYS/BIOS的安装目录）&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;不同版本的CCStudio在Linux系统的安装说明：&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://software-dl.ti.com/ccs/esd/documents/ccs_linux_host_support.html&quot;&gt;CCS Linux Host Support&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://software-dl.ti.com/ccs/esd/documents/ccsv12_linux_host_support.html&quot;&gt;CCS Linux Host Support v12&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://software-dl.ti.com/ccs/esd/documents/users_guide/ccs_installation.html&quot;&gt;CCS Installation Guide v20&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;不同版本的CCStudio命令行程序的使用说明：&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://software-dl.ti.com/ccs/esd/documents/ccs_projects-command-line.html&quot;&gt;CCS Command Line Interface (v12 and below)&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://software-dl.ti.com/ccs/esd/documents/users_guide/ccs_project-command-line.html&quot;&gt;CCS Command Line Interface (v20 and above)&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;2-构建镜像&quot;&gt;2. 构建镜像&lt;/h2&gt;
&lt;h3 id=&quot;21-自动&quot;&gt;2.1 自动&lt;/h3&gt;
&lt;p&gt;使用&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;make&lt;/code&gt;命令自动构建镜像&lt;/p&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c&quot;&gt;# 查看可用的目标&lt;/span&gt;
make list

&lt;span class=&quot;c&quot;&gt;# 构建指定的镜像&lt;/span&gt;
make ubuntu24.04-20.2.0.00012-mmw

&lt;span class=&quot;c&quot;&gt;# 逐个构建镜像&lt;/span&gt;
make all

&lt;span class=&quot;c&quot;&gt;# 并行构建镜像（但是输出日志会混在一起）&lt;/span&gt;
make &lt;span class=&quot;nt&quot;&gt;-j&lt;/span&gt; &lt;span class=&quot;si&quot;&gt;$(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;nproc&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;)&lt;/span&gt; all

&lt;span class=&quot;c&quot;&gt;# 生成docker-compose.yaml文件用于并行构建镜像&lt;/span&gt;
make gen_compose

&lt;span class=&quot;c&quot;&gt;# 使用docker-compose构建镜像&lt;/span&gt;
docker compose &lt;span class=&quot;nt&quot;&gt;-f&lt;/span&gt; docker-compose.yaml &lt;span class=&quot;nt&quot;&gt;--parallel&lt;/span&gt; 2 build
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;22-手动&quot;&gt;2.2 手动&lt;/h3&gt;
&lt;p&gt;构建镜像的脚本如下：&lt;/p&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c&quot;&gt;#   --network host&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;#   --build-arg &quot;HTTP_PROXY=http://127.0.0.1:9900/&quot; \&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;#   --build-arg &quot;HTTPS_PROXY=http://127.0.0.1:9900/&quot; \&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;#   --progress=plain --no-cache&lt;/span&gt;

&lt;span class=&quot;c&quot;&gt;# MMWSDK_COMPONENTS或BIOS_VERSION参数若为空，表示不安装对应组件&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;export &lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;UBUNTU_VERSION&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;24.04
&lt;span class=&quot;nb&quot;&gt;export &lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;CCSTUDIO_VERSION&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;20.2.0.00012
&lt;span class=&quot;nb&quot;&gt;export &lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;CCS_COMPONENTS&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;PF_MMWAVE,PF_C6000SC,PF_TM4C&quot;&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;export &lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;MMWSDK_VERSION&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;03.06.02.00-LTS&quot;&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;export &lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;MMWSDK_COMPONENTS&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;ALL&quot;&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;export &lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;BIOS_VERSION&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;6.73.01.01&quot;&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;# 使用major.minor版本号作为ccstudio版本标识&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;export &lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;CCS_VERSION_SHORT&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;$(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;echo&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;CCSTUDIO_VERSION&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;}&lt;/span&gt; | &lt;span class=&quot;nb&quot;&gt;cut&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-d&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&apos;.&apos;&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-f&lt;/span&gt; 1-2&lt;span class=&quot;si&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;export &lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;tag&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;whuzfb/ccstudio:&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;CCS_VERSION_SHORT&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;-ubuntu&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;UBUNTU_VERSION&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;
docker build &lt;span class=&quot;nt&quot;&gt;-t&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;tag&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;.&lt;/span&gt; &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
  &lt;span class=&quot;nt&quot;&gt;--build-arg&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;OS_VERSION=&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;UBUNTU_VERSION&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
  &lt;span class=&quot;nt&quot;&gt;--build-arg&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;CCS_VERSION=&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;CCSTUDIO_VERSION&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
  &lt;span class=&quot;nt&quot;&gt;--build-arg&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;CCS_COMPONENTS=&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;CCS_COMPONENTS&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
  &lt;span class=&quot;nt&quot;&gt;--build-arg&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;MMWSDK_VERSION=&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;MMWSDK_VERSION&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
  &lt;span class=&quot;nt&quot;&gt;--build-arg&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;MMWSDK_COMPONENTS=&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;MMWSDK_COMPONENTS&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
  &lt;span class=&quot;nt&quot;&gt;--build-arg&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;BIOS_VERSION=&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;BIOS_VERSION&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;3-运行容器&quot;&gt;3. 运行容器&lt;/h2&gt;
&lt;p&gt;从Docker Hub拉取镜像&lt;a href=&quot;https://hub.docker.com/r/whuzfb/ccstudio&quot;&gt;whuzfb/ccstudio&lt;/a&gt;：&lt;/p&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c&quot;&gt;# 拉取最新版本的ccstudio镜像（20.2-ubuntu24.04-mmw）&lt;/span&gt;
docker pull whuzfb/ccstudio:latest
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;或者使用本地构建的镜像&lt;/p&gt;

&lt;p&gt;挂载本地的ccs项目目录到容器内的&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/ccs_projects&lt;/code&gt;目录下并启动构建：&lt;/p&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c&quot;&gt;# 假设本地项目目录为 ./mmw_oob&lt;/span&gt;
git clone &lt;span class=&quot;nt&quot;&gt;--recursive&lt;/span&gt; https://github.com/zfb132/mmw_oob.git ./mmw_oob
&lt;span class=&quot;c&quot;&gt;# 该目录下包含out_of_box_6843_isk_mss.projectspec文件，且包含Debug编译配置&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;# 运行以下命令可以在容器内编译该项目&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;# 如果需要保存结果，那么使用 -v ./results:/workspaces （容器内部CCS的工作目录为/workspaces）&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;# 默认时区为UTC，可以通过设置 -e TZ=... 来更改时区（例如 -e TZ=Asia/Shanghai）&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;mkdir&lt;/span&gt; ./results
docker run &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
  &lt;span class=&quot;nt&quot;&gt;-e&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;TZ&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;Asia/Shanghai &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
  &lt;span class=&quot;nt&quot;&gt;-v&lt;/span&gt; ./mmw_oob:/ccs_projects &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
  &lt;span class=&quot;nt&quot;&gt;-v&lt;/span&gt; ./results:/workspaces &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
  &lt;span class=&quot;nt&quot;&gt;-it&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;--rm&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;--name&lt;/span&gt; ccstudio whuzfb/ccstudio:latest &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
  &lt;span class=&quot;s2&quot;&gt;&quot;out_of_box_6843_isk_mss.projectspec&quot;&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;Debug&quot;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;4-ccstudio组件&quot;&gt;4. CCStudio组件&lt;/h2&gt;
&lt;p&gt;&lt;a href=&quot;https://software-dl.ti.com/ccs/esd/documents/ccs_installer-cli.html&quot;&gt;可安装的产品系列&lt;/a&gt;列表：&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th style=&quot;text-align: center&quot;&gt;Product family&lt;/th&gt;
      &lt;th style=&quot;text-align: center&quot;&gt;Description&lt;/th&gt;
      &lt;th style=&quot;text-align: center&quot;&gt;OS&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;PF_MSP430&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;MSP430 ultra-low power MCUs&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;windows-x64, linux-x64, osx&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;PF_MSP432&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;SimpleLink™ MSP432™ low power + performance MCUs&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;windows-x64, linux-x64, osx&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;PF_CC2X&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;SimpleLink™ CC13xx and CC26xx Wireless MCUs&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;windows-x64, linux-x64, osx&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;PF_CC3X&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;SimpleLink™ Wi-Fi® CC32xx Wireless MCUs&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;windows-x64, linux-x64, osx&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;PF_CC2538&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;CC2538 IEEE 802.15.4 Wireless MCUs&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;windows-x64, linux-x64, osx&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;PF_C28&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;C2000 real-time MCUs&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;windows-x64, linux-x64, osx&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;PF_TM4C&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;TM4C12x ARM® Cortex®-M4F core-based MCUs&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;windows-x64, linux-x64, osx&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;PF_PGA&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;PGA Sensor Signal Conditioners&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;windows-x64, linux-x64, osx&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;PF_HERCULES&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;Hercules™ Safety MCUs&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;windows-x64, linux-x64, osx&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;PF_SITARA&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;Sitara™ AM3x, AM4x, AM5x and AM6x MPUs (will also include AM2x for CCS 10.x)&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;windows-x64, linux-x64&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;PF_SITARA_MCU&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;Sitara™ AM2x MCUs (only supported in CCS 11.x and greater)&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;windows-x64, linux-x64&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;PF_OMAPL&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;OMAP-L1x DSP + ARM9® Processor&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;windows-x64, linux-x64&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;PF_DAVINCI&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;DaVinci (DM) Video Processors&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;windows-x64, linux-x64&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;PF_OMAP&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;OMAP Processors&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;windows-x64, linux-x64&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;PF_TDA_DRA&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;TDAx Driver Assistance SoCs &amp;amp; Jacinto DRAx Infotainment SoCs&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;windows-x64, linux-x64&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;PF_C55&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;C55x ultra-low-power DSP&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;windows-x64, linux-x64&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;PF_C6000SC&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;C6000 Power-Optimized DSP&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;windows-x64, linux-x64&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;PF_C66AK_KEYSTONE&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;66AK2x multicore DSP + ARM® Processors &amp;amp; C66x KeyStone™ multicore DSP&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;windows-x64, linux-x64&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;PF_MMWAVE&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;mmWave Sensors&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;windows-x64, linux-x64&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;PF_C64MC&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;C64x multicore DSP&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;windows-x64, linux-x64&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;PF_DIGITAL_POWER&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;UCD Digital Power Controllers&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;windows-x64, linux-x64&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h2 id=&quot;5-其他参考&quot;&gt;5. 其他参考&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/zfb132/ccstudio&quot;&gt;zfb132/ccstudio&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/zfb132/mmw_oob&quot;&gt;zfb132/mmw_oob&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/uoohyo/docker-ccstudio-ide&quot;&gt;uoohyo/ccstudio-ide&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/uoohyo/action-ccstudio-ide&quot;&gt;uoohyo/action-ccstudio-ide&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://e2e.ti.com/support/processors-group/processors/f/processors-forum/1412767/ccstudio-code-composer-studio-12-8-and-uniflash-8-7-on-ubuntu-24-04&quot;&gt;ccstudio code composer studio 12.8 and uniflash 8.7 on ubuntu 24.04&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://e2e.ti.com/support/tools/code-composer-studio-group/ccs/f/code-composer-studio-forum/1532443/codecomposer-installing-ccs-20-2-0-into-a-docker-container&quot;&gt;codecomposer installing ccs 20.2.0 into a docker container&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</description>
        <pubDate>Mon, 21 Jul 2025 18:00:31 +0800</pubDate>
        <link>https://blog.whuzfb.cn/blog/2025/07/21/docker-ccstudio/</link>
        <guid isPermaLink="true">https://blog.whuzfb.cn/blog/2025/07/21/docker-ccstudio/</guid>
        
        <category>Ubuntu</category>
        
        <category>Linux</category>
        
        <category>Docker</category>
        
        <category>CCStudio</category>
        
        <category>TI</category>
        
        
        <category>Ubuntu</category>
        
        <category>Linux</category>
        
        <category>Docker</category>
        
      </item>
    
      <item>
        <title>Windows电脑配置以太网口访问雷达</title>
        <description>&lt;h2 class=&quot;no_toc&quot; id=&quot;目录&quot;&gt;目录&lt;/h2&gt;

&lt;ul id=&quot;markdown-toc&quot;&gt;
  &lt;li&gt;&lt;a href=&quot;#1-总体说明&quot; id=&quot;markdown-toc-1-总体说明&quot;&gt;1. 总体说明&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#2-windows电脑配置以太网口&quot; id=&quot;markdown-toc-2-windows电脑配置以太网口&quot;&gt;2. windows电脑配置以太网口&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#3-雷达配置ip和网关和路由&quot; id=&quot;markdown-toc-3-雷达配置ip和网关和路由&quot;&gt;3. 雷达配置ip和网关和路由&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#4-windows开启路由转发功能&quot; id=&quot;markdown-toc-4-windows开启路由转发功能&quot;&gt;4. windows开启路由转发功能&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#5-windows配置以太网共享无线网络&quot; id=&quot;markdown-toc-5-windows配置以太网共享无线网络&quot;&gt;5. windows配置以太网共享无线网络&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;1-总体说明&quot;&gt;1. 总体说明&lt;/h2&gt;
&lt;p&gt;适用情况： 目的只是调试雷达，且当前没有配置好的交换机或路由器&lt;br /&gt;
主要功能： 把雷达的以太网口&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;eth1&lt;/code&gt;连接到windows电脑的以太网口（此时两者即可互相ping通，可以ssh），还可以通过windows电脑的无线网络让雷达连接到互联网&lt;/p&gt;

&lt;p&gt;其中雷达的&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;eth1&lt;/code&gt;口配置如下&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;IP地址示例： &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;192.168.19.241&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;子网掩码示例： &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;255.255.255.0&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;网关示例： &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;192.168.19.244&lt;/code&gt;（可以自行修改为其他ip，只要与windows电脑的以太网口IP地址一致即可，例如&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;192.168.19.254&lt;/code&gt;）&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;windows电脑的以太网口配置如下&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;IP地址示例： &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;192.168.19.244&lt;/code&gt;（只要与雷达网关一致即可，例如&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;192.168.19.254&lt;/code&gt;）&lt;/li&gt;
  &lt;li&gt;子网掩码示例： &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;255.255.255.0&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;网关： 留空&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;windows电脑可以替换为其他Linux电脑，配置方法类似&lt;/p&gt;

&lt;h2 id=&quot;2-windows电脑配置以太网口&quot;&gt;2. windows电脑配置以太网口&lt;/h2&gt;
&lt;ol&gt;
  &lt;li&gt;打开&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;控制面板&lt;/code&gt; -&amp;gt; &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;网络和Internet&lt;/code&gt; -&amp;gt; &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;网络和共享中心&lt;/code&gt; -&amp;gt; &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;更改适配器设置&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;然后再手动修改windows的以太网适配器的IP地址是&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;192.168.19.244&lt;/code&gt;（也可以是&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;192.168.19.254&lt;/code&gt;），子网掩码是&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;255.255.255.0&lt;/code&gt;，保存即可（该适配器可能会显示为&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;未识别的网络&lt;/code&gt;，属性信息里面IPv4和IPv6可能会提示无法获取Internet访问权限，这是正常的）&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;3-雷达配置ip和网关和路由&quot;&gt;3. 雷达配置ip和网关和路由&lt;/h2&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c&quot;&gt;# 查看当前网络信息(发现eth1的ip地址是192.168.19.241)&lt;/span&gt;
ip a
&lt;span class=&quot;c&quot;&gt;# 1: 1o:&amp;lt;L0OPBACK,UP,LOWER UP&amp;gt; mtu 16436 qdisc noqueue state UNKNOWN&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;#     link/loopback 00:00:00:00:00:00 brd60:00:00:00:00:00&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;#     inet 127.0.0.1/8 scope host lo&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;#     inet6 ::1/128 scope host&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;#         valid lft forever preferred lft forever&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;# 2: eth0: &amp;lt;NO-CARRIER,BROADCAST,MULTICAST,UP&amp;gt; mtu 1500 qdisc pfifo fast state DOWN qlen 1000&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;#     link/ether 00:0a:aa:aa:aa:aa brd ff:ff:ff:ff:ff:ff&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;#     inet 192.168.1.0/24 brd 192.168.1.255 scope global eth0&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;# 3: eth1: &amp;lt;BROADCAST,MULTICAST,UP,LOWER UP&amp;gt; mtu 1500 qdisc pfifo fast state UNKNOWN qlen 1000&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;#     link/ether 08:1f:ff:ff:ff:ff brd ff:ff:ff:ff:ff:ff&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;#     inet 192.168.19.241/24 brd 192.168.19.255 scope global eth1&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;#     inet6 fe80::alf:7lff:fe03:bbc/64 scope link&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;#         valid lft forever preferred lft forever&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;# 4: eth2: &amp;lt;BROADCAST,MULTICAST,UP,LOWER UP&amp;gt; mtu 1500 qdisc pfifo fast state UP qlen 1000&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;#     link/ether 00:0b:bb:bb:bb:bb brd ff:ff:ff:ff:ff:ff&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;#     inet 172.16.1.0/16 brd 172.16.255.255 scope global eth2&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;#     inet6 fe80::20b:abff:fed3:2b52/64 scope link&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;#         valid lft forever preferred lft forever&lt;/span&gt;

&lt;span class=&quot;c&quot;&gt;# 查看默认网关(发现eth1的网关是192.168.19.254)&lt;/span&gt;
route &lt;span class=&quot;nt&quot;&gt;-n&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;# Kernel Ip routing table&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;# Destination    Gateway          Genmask         Flags   Metric   Ref   User   Iface&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;# 192.168.19.0   0.0.0.0          255.255.255.0   U       0        0     0      eth1&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;# 192.168.1.0    0.0.0.0          255.255.255.0   U       0        0     0      eth0&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;# 172.16.0.0     0.0.0.0          255.255.0.0     U       0        0     0      eth2&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;# 127.0.0.0      0.0.0.0          255.0.0.0       U       0        0     0      lo&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;# 0.0.0.0        192.168.19.254   0.0.0.0         UG      0        0     0      eth1&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;如果不想对雷达进行任何修改，则直接把windows电脑的以太网口IP地址修改为&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;192.168.19.254&lt;/code&gt;，子网掩码是&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;255.255.255.0&lt;/code&gt;，保存即可。雷达会通过&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;eth1&lt;/code&gt;口（ip地址是&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;192.168.19.241&lt;/code&gt;）经由windows电脑的以太网口（ip地址是&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;192.168.19.254&lt;/code&gt;）互相访问。&lt;/p&gt;

&lt;p&gt;如果希望自定义雷达的IP和网关，则可以在雷达上执行以下命令：&lt;/p&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c&quot;&gt;# 切换到root用户（192.168.19.241是自己设置的eth1口IP地址，只要与windows电脑的以太网口IP地址在同一网段即可）&lt;/span&gt;
ifconfig eth1 192.168.19.241 netmask 255.255.255.0 up
&lt;span class=&quot;c&quot;&gt;# 删除默认网关&lt;/span&gt;
route del default
&lt;span class=&quot;c&quot;&gt;# 添加新的默认网关（这里的网关是windows电脑的以太网口IP地址）&lt;/span&gt;
route add default gw 192.168.19.244 eth1
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;此时在windows电脑上可以通过ssh连接到雷达：&lt;/p&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;ssh username@192.168.19.241
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;但是如果想让雷达访问互联网，则需要在windows电脑上开启网络转发功能，并配置以太网共享无线网络。&lt;/p&gt;

&lt;h2 id=&quot;4-windows开启路由转发功能&quot;&gt;4. windows开启路由转发功能&lt;/h2&gt;
&lt;ol&gt;
  &lt;li&gt;修改注册表：以管理员身份打开cmd，输入以下命令
    &lt;pre&gt;&lt;code class=&quot;language-regedit&quot;&gt; reg add HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters /v IPEnableRouter /D 1 /f
&lt;/code&gt;&lt;/pre&gt;
  &lt;/li&gt;
  &lt;li&gt;启动&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Routing and Remote Access&lt;/code&gt;服务：以管理员身份打开cmd，输入以下命令
    &lt;pre&gt;&lt;code class=&quot;language-pwsh&quot;&gt; # 如果报错，就手动去服务中启动
 sc config RemoteAccess start=auto
 sc start RemoteAccess
 sc query RemoteAccess
&lt;/code&gt;&lt;/pre&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;5-windows配置以太网共享无线网络&quot;&gt;5. windows配置以太网共享无线网络&lt;/h2&gt;
&lt;ol&gt;
  &lt;li&gt;配置共享地址段（防止在共享WLAN给ethernet时，弹出对话框提示以太网的ip地址只能是&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;192.168.137.1&lt;/code&gt;）
以管理员身份打开cmd，输入以下命令
    &lt;pre&gt;&lt;code class=&quot;language-reg&quot;&gt; reg add &quot;HKLM\SYSTEM\CurrentControlSet\Services\SharedAccess\Parameters&quot; -v ScopeAddress -d 192.168.19.142 -f
 reg add &quot;HKLM\SYSTEM\CurrentControlSet\Services\SharedAccess\Parameters&quot; -v ScopeAddressBackup -d 192.168.19.142 -f
&lt;/code&gt;&lt;/pre&gt;
    &lt;p&gt;此处只要&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ScopeAddress&lt;/code&gt;和&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ScopeAddressBackup&lt;/code&gt;的网段是&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;192.168.19.x&lt;/code&gt;即可&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;打开&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;控制面板&lt;/code&gt; -&amp;gt; &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;网络和Internet&lt;/code&gt; -&amp;gt; &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;网络和共享中心&lt;/code&gt; -&amp;gt; &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;更改适配器设置&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;右键点击&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;无线网络连接&lt;/code&gt; -&amp;gt; &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;属性&lt;/code&gt; -&amp;gt; &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;共享&lt;/code&gt;选项卡&lt;/li&gt;
  &lt;li&gt;勾选&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;允许其他网络用户通过此计算机的Internet连接来连接&lt;/code&gt;，在下拉框中选择&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;以太网&lt;/code&gt;（即windows与雷达连接网线后出现的网络适配器），点击&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;确定&lt;/code&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;此时雷达就可以通过windows电脑的无线网络访问互联网了，直接在雷达上执行以下命令测试：&lt;/p&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;ping baidu.com
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;关于如何使用frp配置远程访问，参考&lt;a href=&quot;https://blog.whuzfb.cn/blog/2020/07/05/remote_access_lan_gui/&quot;&gt;远程访问安装xfce4的内网服务器&lt;/a&gt;&lt;/p&gt;
</description>
        <pubDate>Mon, 26 May 2025 19:27:03 +0800</pubDate>
        <link>https://blog.whuzfb.cn/blog/2025/05/26/windows_access_radar_temporary/</link>
        <guid isPermaLink="true">https://blog.whuzfb.cn/blog/2025/05/26/windows_access_radar_temporary/</guid>
        
        <category>Linux</category>
        
        <category>Windows</category>
        
        
        <category>Linux</category>
        
        <category>Windows</category>
        
      </item>
    
      <item>
        <title>使用ffmpeg对视频和音频文件进行处理</title>
        <description>&lt;h2 class=&quot;no_toc&quot; id=&quot;目录&quot;&gt;目录&lt;/h2&gt;

&lt;ul id=&quot;markdown-toc&quot;&gt;
  &lt;li&gt;&lt;a href=&quot;#0-常用命令说明&quot; id=&quot;markdown-toc-0-常用命令说明&quot;&gt;0. 常用命令说明&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#1-倍速播放&quot; id=&quot;markdown-toc-1-倍速播放&quot;&gt;1. 倍速播放&lt;/a&gt;    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;#11-视频画面倍速播放&quot; id=&quot;markdown-toc-11-视频画面倍速播放&quot;&gt;1.1 视频画面倍速播放&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#12-音频倍速播放&quot; id=&quot;markdown-toc-12-音频倍速播放&quot;&gt;1.2 音频倍速播放&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#13-视频画面和音频倍速播放&quot; id=&quot;markdown-toc-13-视频画面和音频倍速播放&quot;&gt;1.3 视频画面和音频倍速播放&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#2-视频片段裁剪&quot; id=&quot;markdown-toc-2-视频片段裁剪&quot;&gt;2. 视频片段裁剪&lt;/a&gt;    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;#21-获取视频的分辨率&quot; id=&quot;markdown-toc-21-获取视频的分辨率&quot;&gt;2.1 获取视频的分辨率&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#22-截取指定时长的视频片段&quot; id=&quot;markdown-toc-22-截取指定时长的视频片段&quot;&gt;2.2 截取指定时长的视频片段&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#23-裁剪视频画面尺寸&quot; id=&quot;markdown-toc-23-裁剪视频画面尺寸&quot;&gt;2.3 裁剪视频画面尺寸&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#3-视频导出图片&quot; id=&quot;markdown-toc-3-视频导出图片&quot;&gt;3. 视频导出图片&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#4-从图片集创建gif文件&quot; id=&quot;markdown-toc-4-从图片集创建gif文件&quot;&gt;4. 从图片集创建GIF文件&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#5-提取视频文件的音频&quot; id=&quot;markdown-toc-5-提取视频文件的音频&quot;&gt;5. 提取视频文件的音频&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#6-把音频和画面合并为新的视频&quot; id=&quot;markdown-toc-6-把音频和画面合并为新的视频&quot;&gt;6. 把音频和画面合并为新的视频&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#7-下载m3u8文件为ts文件&quot; id=&quot;markdown-toc-7-下载m3u8文件为ts文件&quot;&gt;7. 下载m3u8文件为.ts文件&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#8-批量提取视频关键帧&quot; id=&quot;markdown-toc-8-批量提取视频关键帧&quot;&gt;8. 批量提取视频关键帧&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;0-常用命令说明&quot;&gt;0. 常用命令说明&lt;/h2&gt;
&lt;p&gt;ffmpeg是一个命令行工具，所有的操作都是通过命令行来完成的，下面是一些常用的命令说明&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-vcodec codec&lt;/code&gt;：强制使用&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;codec&lt;/code&gt;编解码方式（&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;copy&lt;/code&gt;代表不进行重新编码）&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-acodec copy&lt;/code&gt;：表示音频不做新的编码，直接把原来的复制过来&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-vcodec copy&lt;/code&gt;：表示视频不做新的编码，直接把原来的复制过来&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-threads 5&lt;/code&gt;：指定&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;5&lt;/code&gt;个线程同时转换&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-vn&lt;/code&gt;：取消视频的输出&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-an&lt;/code&gt;：取消音频轨&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-ab 160000&lt;/code&gt;：设置比特率（单位为&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;bit/s&lt;/code&gt;）&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-ar 8000&lt;/code&gt;：设置音频采样率（单位为&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Hz&lt;/code&gt;）&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-ac 1&lt;/code&gt;：设置声道数，&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;1&lt;/code&gt;就是单声道，&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;2&lt;/code&gt;就是立体声&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;1-倍速播放&quot;&gt;1. 倍速播放&lt;/h2&gt;
&lt;h3 id=&quot;11-视频画面倍速播放&quot;&gt;1.1 视频画面倍速播放&lt;/h3&gt;
&lt;p&gt;把输入的视频文件，画面播放速度快放到原来的2倍，保存为新的视频文件&lt;br /&gt;
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ffmpeg -i input.mp4 -filter:v &quot;setpts=0.5*PTS&quot; output.mp4&lt;/code&gt;&lt;/p&gt;
&lt;h3 id=&quot;12-音频倍速播放&quot;&gt;1.2 音频倍速播放&lt;/h3&gt;
&lt;p&gt;把输入的视频文件，音频播放速度快放到原来的2倍，保存为新的视频文件&lt;br /&gt;
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ffmpeg -i input.mp4 -filter:a &quot;atempo=2.0&quot; output.mp4&lt;/code&gt;&lt;/p&gt;
&lt;h3 id=&quot;13-视频画面和音频倍速播放&quot;&gt;1.3 视频画面和音频倍速播放&lt;/h3&gt;
&lt;p&gt;把输入的视频文件，画面播放速度快放到原来的2倍，音频播放速度快放到原来的2倍，保存为新的视频文件&lt;br /&gt;
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ffmpeg -i input.mp4 -filter_complex &quot;[0:v]setpts=0.5*PTS[v];[0:a]atempo=2.0[a]&quot; -map &quot;[v]&quot; -map &quot;[a]&quot; output.mp4&lt;/code&gt;&lt;/p&gt;

&lt;h2 id=&quot;2-视频片段裁剪&quot;&gt;2. 视频片段裁剪&lt;/h2&gt;
&lt;h3 id=&quot;21-获取视频的分辨率&quot;&gt;2.1 获取视频的分辨率&lt;/h3&gt;
&lt;p&gt;方法一：获取视频的分辨率，以默认分隔符分割&lt;br /&gt;
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ffprobe -v error -show_entries stream=width,height -of csv=p=0 demo.mp4&lt;/code&gt;&lt;br /&gt;
得到输出为： &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;1920,1080&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;方法二：获取视频的分辨率，以&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;x&lt;/code&gt;分隔符分割&lt;br /&gt;
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ffprobe -v error -show_entries stream=width,height -of csv=p=0:s=x output2.mp4&lt;/code&gt;&lt;br /&gt;
得到输出为： &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;1920x1080&lt;/code&gt;&lt;/p&gt;

&lt;h3 id=&quot;22-截取指定时长的视频片段&quot;&gt;2.2 截取指定时长的视频片段&lt;/h3&gt;
&lt;p&gt;从视频文件中，截取时间从&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;00:00:00&lt;/code&gt;开始到&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;00:00:11&lt;/code&gt;之间的片段，输出为新的视频文件&lt;br /&gt;
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ffmpeg -ss 00:00:00 -to 00:00:11 -i input.mp4 -vcodec copy -acodec copy output.mp4&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;从视频文件中，截取时间从&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;00:01:00&lt;/code&gt;开始，时长&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;00:00:21&lt;/code&gt;的片段，输出为新的视频文件&lt;br /&gt;
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ffmpeg -ss 00:01:00 -t 00:00:21 -i input.mp4 -vcodec copy -acodec copy output2.mp4&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;从视频文件中，截取时间从&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;00:00:00&lt;/code&gt;到&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;00:00:11&lt;/code&gt;之间的片段，分辨率为&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;1920x1080&lt;/code&gt;，输出为新的视频文件&lt;br /&gt;
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ffmpeg -ss 00:00:00 -to 00:00:11 -i input.mp4 -vcodec copy -acodec copy -s 1920,1080 output.mp4&lt;/code&gt;&lt;/p&gt;

&lt;h3 id=&quot;23-裁剪视频画面尺寸&quot;&gt;2.3 裁剪视频画面尺寸&lt;/h3&gt;
&lt;p&gt;参数示例：&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;crop=new_width:new_height:start_x:start_y&lt;/code&gt;&lt;br /&gt;
把原视频画面裁剪成宽高为&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;400x200&lt;/code&gt;的新视频，&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;x&lt;/code&gt;的起始位置是&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;0&lt;/code&gt;（表示从该位置开始，向右&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;400&lt;/code&gt;的像素留下），&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;y&lt;/code&gt;的起始位置是&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;0&lt;/code&gt;（表示从该位置开始，向下&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;200&lt;/code&gt;的像素留下）。也就是说，最后留下的视频画面为原视频画面的一部分（以原视频画面的左上顶点为原点）&lt;br /&gt;
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ffmpeg -i input.mp4 -vf crop=400:200:0:0 -threads 5 -preset ultrafast -strict -2 output.mp4&lt;/code&gt;&lt;/p&gt;

&lt;h2 id=&quot;3-视频导出图片&quot;&gt;3. 视频导出图片&lt;/h2&gt;
&lt;p&gt;从视频文件中，以每秒&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;3&lt;/code&gt;帧的速率抽取图片，并更改为指定长、宽，最后按照指定命名格式保存&lt;br /&gt;
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ffmpeg -i demo.mp4 -r 3 -s 1920x1080 -f image2 ./demo-%03d.jpeg&lt;/code&gt;&lt;/p&gt;

&lt;h2 id=&quot;4-从图片集创建gif文件&quot;&gt;4. 从图片集创建GIF文件&lt;/h2&gt;
&lt;p&gt;从图片集创建帧率为&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;5&lt;/code&gt;的&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;GIF&lt;/code&gt;文件&lt;br /&gt;
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ffmpeg -f image2 -framerate 5 -i ./demo-%03d.jpeg out.gif&lt;/code&gt;&lt;/p&gt;

&lt;h2 id=&quot;5-提取视频文件的音频&quot;&gt;5. 提取视频文件的音频&lt;/h2&gt;
&lt;p&gt;提取视频文件的音频内容保存为&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;mp3&lt;/code&gt;格式&lt;br /&gt;
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ffmpeg -i demo.mp4 -f mp3 -vn -ar 16000 -ac 1 demo.mp3&lt;/code&gt;&lt;/p&gt;

&lt;h2 id=&quot;6-把音频和画面合并为新的视频&quot;&gt;6. 把音频和画面合并为新的视频&lt;/h2&gt;
&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ffmpeg -loglevel quiet -i video.m4s -i audio.m4s -c copy -y out.mp4&lt;/code&gt;&lt;/p&gt;

&lt;h2 id=&quot;7-下载m3u8文件为ts文件&quot;&gt;7. 下载m3u8文件为.ts文件&lt;/h2&gt;
&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ffmpeg -protocol_whitelist file,http,https,tcp,tls -i https://t.cn/a.m3u8 -c copy my_movie.ts&lt;/code&gt;&lt;/p&gt;

&lt;h2 id=&quot;8-批量提取视频关键帧&quot;&gt;8. 批量提取视频关键帧&lt;/h2&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c&quot;&gt;#!/bin/bash&lt;/span&gt;

&lt;span class=&quot;nb&quot;&gt;shopt&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-s&lt;/span&gt; nullglob

&lt;span class=&quot;nb&quot;&gt;export &lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;video_path&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$1&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;export &lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;out_path&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$2&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;export &lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;files&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;video_path&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;}&lt;/span&gt;/&lt;span class=&quot;k&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;# echo ${files[@]}&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;# echo ${#files[@]}&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;for &lt;/span&gt;filename &lt;span class=&quot;k&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;files&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[@]&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;do
    &lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;filename&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;filename&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;
    &lt;span class=&quot;nb&quot;&gt;export &lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;$(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;basename&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;filename&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;nv&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;%.*&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;nb&quot;&gt;echo &lt;/span&gt;Converting &lt;span class=&quot;k&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;filename&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;nb&quot;&gt;export &lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;file_dir&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;out_path&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;
    &lt;span class=&quot;nb&quot;&gt;mkdir&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;file_dir&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;
    &lt;span class=&quot;c&quot;&gt;# 获取视频分辨率（宽，高）&lt;/span&gt;
    &lt;span class=&quot;c&quot;&gt;# 例如： 1920,1080&lt;/span&gt;
    &lt;span class=&quot;c&quot;&gt;# export wh=ffprobe -v error -show_entries stream=width,height -of csv=p=0 &quot;${filename}&quot;&lt;/span&gt;
    &lt;span class=&quot;c&quot;&gt;# 视频提取语音，方便识别&lt;/span&gt;
    ffmpeg &lt;span class=&quot;nt&quot;&gt;-y&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-i&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;filename&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-f&lt;/span&gt; mp3 &lt;span class=&quot;nt&quot;&gt;-vn&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-ar&lt;/span&gt; 16000 &lt;span class=&quot;nt&quot;&gt;-ac&lt;/span&gt; 1 &lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;file_dir&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;/audio.mp3&quot;&lt;/span&gt;
    &lt;span class=&quot;c&quot;&gt;# 视频关键帧提取，方便导出PPT&lt;/span&gt;
    ffmpeg &lt;span class=&quot;nt&quot;&gt;-y&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-i&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;filename&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-vf&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;select&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&apos;eq(pict_type\,I)&apos;&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-vsync&lt;/span&gt; 2 &lt;span class=&quot;nt&quot;&gt;-s&lt;/span&gt; 1920,1080 &lt;span class=&quot;nt&quot;&gt;-f&lt;/span&gt; image2 &lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;file_dir&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;/keyframe-%03d.png&quot;&lt;/span&gt;
    &lt;span class=&quot;nb&quot;&gt;echo &lt;/span&gt;Convert &lt;span class=&quot;k&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;filename&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;}&lt;/span&gt; successfully!
&lt;span class=&quot;k&quot;&gt;done&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
</description>
        <pubDate>Fri, 30 Dec 2022 22:59:00 +0800</pubDate>
        <link>https://blog.whuzfb.cn/blog/2022/12/30/ffmpeg-usage/</link>
        <guid isPermaLink="true">https://blog.whuzfb.cn/blog/2022/12/30/ffmpeg-usage/</guid>
        
        <category>Windows</category>
        
        <category>Ubuntu</category>
        
        <category>Linux</category>
        
        
        <category>Windows</category>
        
        <category>Ubuntu</category>
        
        <category>Linux</category>
        
      </item>
    
      <item>
        <title>修复Adobe Acrobat打开发票字体显示不全的问题</title>
        <description>&lt;h2 class=&quot;no_toc&quot; id=&quot;目录&quot;&gt;目录&lt;/h2&gt;

&lt;ul id=&quot;markdown-toc&quot;&gt;
  &lt;li&gt;&lt;a href=&quot;#0-问题描述&quot; id=&quot;markdown-toc-0-问题描述&quot;&gt;0. 问题描述&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#1-复制系统楷体字体文件&quot; id=&quot;markdown-toc-1-复制系统楷体字体文件&quot;&gt;1. 复制系统楷体字体文件&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#2-修改字体名称&quot; id=&quot;markdown-toc-2-修改字体名称&quot;&gt;2. 修改字体名称&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#3-复制字体文件到acrobat字体目录&quot; id=&quot;markdown-toc-3-复制字体文件到acrobat字体目录&quot;&gt;3. 复制字体文件到Acrobat字体目录&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;0-问题描述&quot;&gt;0. 问题描述&lt;/h2&gt;
&lt;p&gt;Acrobat在2021.005.20060以后的新版本有bug，无法读取楷体GB2312字体，导致打开发票时，发票上的部分中文显示为方框或不显示&lt;/p&gt;

&lt;h2 id=&quot;1-复制系统楷体字体文件&quot;&gt;1. 复制系统楷体字体文件&lt;/h2&gt;
&lt;p&gt;文件资源管理器打开&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;C:\Windows\Fonts&lt;/code&gt;目录，找到&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;楷体 常规&lt;/code&gt;字体文件，即文件&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;C:\Windows\Fonts\simkai.ttf&lt;/code&gt;，复制到其他目录，这样不会影响系统正常使用&lt;/p&gt;

&lt;h2 id=&quot;2-修改字体名称&quot;&gt;2. 修改字体名称&lt;/h2&gt;
&lt;p&gt;使用字体编辑工具FontCreator打开&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;simkai.ttf&lt;/code&gt;字体文件，选择&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Font-Properties&lt;/code&gt;打开属性修改，将&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Family Name&lt;/code&gt;修改为&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;KaiTi_GB2312&lt;/code&gt;，选择&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;File – Export Font – Export – Export Desktop Font&lt;/code&gt;导出字体，可以命名为&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;simkai-new.otf&lt;/code&gt;，等待几分钟完成&lt;/p&gt;

&lt;h2 id=&quot;3-复制字体文件到acrobat字体目录&quot;&gt;3. 复制字体文件到Acrobat字体目录&lt;/h2&gt;
&lt;p&gt;将修改后的字体文件&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;simkai-new.otf&lt;/code&gt;复制到&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;C:\Program Files\Adobe\Acrobat DC\Resource\Font&lt;/code&gt;目录，重启Acrobat即可&lt;/p&gt;
</description>
        <pubDate>Wed, 28 Dec 2022 20:03:15 +0800</pubDate>
        <link>https://blog.whuzfb.cn/blog/2022/12/28/adobe-acrobat-cn-char/</link>
        <guid isPermaLink="true">https://blog.whuzfb.cn/blog/2022/12/28/adobe-acrobat-cn-char/</guid>
        
        <category>Windows</category>
        
        
        <category>Windows</category>
        
      </item>
    
      <item>
        <title>使用Python代码在Windows资源管理器中定位文件</title>
        <description>&lt;h2 class=&quot;no_toc&quot; id=&quot;目录&quot;&gt;目录&lt;/h2&gt;

&lt;ul id=&quot;markdown-toc&quot;&gt;
  &lt;li&gt;&lt;a href=&quot;#1-安装pywin32&quot; id=&quot;markdown-toc-1-安装pywin32&quot;&gt;1. 安装pywin32&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#2-脚本文件内容&quot; id=&quot;markdown-toc-2-脚本文件内容&quot;&gt;2. 脚本文件内容&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;1-安装pywin32&quot;&gt;1. 安装pywin32&lt;/h2&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;pip &lt;span class=&quot;nb&quot;&gt;install &lt;/span&gt;pywin32
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;2-脚本文件内容&quot;&gt;2. 脚本文件内容&lt;/h2&gt;
&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;#!/usr/bin/env python
# -*- coding: utf-8 -*-
# author: &apos;zfb&apos;
# time: 2021-01-06 13:33
&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;os&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;pathlib&lt;/span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Path&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;win32com.shell.shell&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;shell&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;launch_file_explorer&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;file_with_abs_path&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;s&quot;&gt;&apos;&apos;&apos;
    每次弹出文件资源管理器，只能打开一个文件夹，然后（定位）选择一个文件（夹）
    &apos;&apos;&apos;&lt;/span&gt;
    &lt;span class=&quot;nb&quot;&gt;file&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Path&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;file_with_abs_path&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;# 对于Linux系统来说
&lt;/span&gt;    &lt;span class=&quot;c1&quot;&gt;#    如果使用Unity/Gnome桌面，可以使用命令
&lt;/span&gt;    &lt;span class=&quot;c1&quot;&gt;#        nautilus ~/Documents/foo.txt
&lt;/span&gt;    &lt;span class=&quot;c1&quot;&gt;#    对于其他桌面系统，可参考 xdg-open 命令
&lt;/span&gt;    &lt;span class=&quot;c1&quot;&gt;# 严格按照此格式，不能自己加空格
&lt;/span&gt;    &lt;span class=&quot;n&quot;&gt;os&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;system&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;explorer.exe /e,/select,&quot;{}&quot;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;format&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;file&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;


&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;launch_files_explorer&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;path&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;files&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;s&quot;&gt;&apos;&apos;&apos;
    每次弹出文件资源管理器，只能打开一个文件夹，可以选择多个文件（夹）
    &apos;&apos;&apos;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;len&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;files&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;path&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;str&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Path&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;path&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;folder_pidl&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;shell&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;SHILCreateFromPath&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;path&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;desktop&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;shell&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;SHGetDesktopFolder&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;shell_folder&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;desktop&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;BindToObject&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;folder_pidl&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;bp&quot;&gt;None&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;shell&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;IID_IShellFolder&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;name_to_item_mapping&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;dict&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;([(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;desktop&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;GetDisplayNameOf&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;item&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;item&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;item&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;shell_folder&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;to_show&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[]&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;file&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;files&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;not&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;file&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;name_to_item_mapping&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;raise&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;Exception&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;目录{}下找不到文件{}&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;format&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;path&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;file&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;to_show&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;append&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;name_to_item_mapping&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;file&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;shell&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;SHOpenFolderAndSelectItems&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;folder_pidl&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;to_show&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;


&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;__name__&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;__main__&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;name&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;os&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;path&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;abspath&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;__file__&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;path&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;D:/github/zfb132.github.com/&quot;&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;names&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;index.html&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;README.md&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;robots.txt&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;launch_file_explorer&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;launch_files_explorer&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;path&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;names&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
</description>
        <pubDate>Tue, 27 Dec 2022 21:51:00 +0800</pubDate>
        <link>https://blog.whuzfb.cn/blog/2022/12/27/reveal-in-explorer/</link>
        <guid isPermaLink="true">https://blog.whuzfb.cn/blog/2022/12/27/reveal-in-explorer/</guid>
        
        <category>Python</category>
        
        <category>Windows</category>
        
        
        <category>Python</category>
        
        <category>Windows</category>
        
      </item>
    
      <item>
        <title>使用git diff查看不同文件或者不同commit之间的区别</title>
        <description>&lt;h2 class=&quot;no_toc&quot; id=&quot;目录&quot;&gt;目录&lt;/h2&gt;

&lt;ul id=&quot;markdown-toc&quot;&gt;
  &lt;li&gt;&lt;a href=&quot;#1-查看不同文件的区别&quot; id=&quot;markdown-toc-1-查看不同文件的区别&quot;&gt;1. 查看不同文件的区别&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#2-查看不同commit之间的修改&quot; id=&quot;markdown-toc-2-查看不同commit之间的修改&quot;&gt;2. 查看不同commit之间的修改&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#3-把diff的转换为html保存&quot; id=&quot;markdown-toc-3-把diff的转换为html保存&quot;&gt;3. 把diff的转换为html保存&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#4-ansi2htmlsh文件内容&quot; id=&quot;markdown-toc-4-ansi2htmlsh文件内容&quot;&gt;4. ansi2html.sh文件内容&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;1-查看不同文件的区别&quot;&gt;1. 查看不同文件的区别&lt;/h2&gt;
&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;a.txt&lt;/code&gt;和&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;b.txt&lt;/code&gt;不在版本控制系统中：&lt;/p&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;git diff &lt;span class=&quot;nt&quot;&gt;--color-words&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;--no-index&lt;/span&gt; a.txt b.txt
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;2-查看不同commit之间的修改&quot;&gt;2. 查看不同commit之间的修改&lt;/h2&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;git diff &lt;span class=&quot;nt&quot;&gt;--color-words&lt;/span&gt; HEAD~4 HEAD~3
git diff &lt;span class=&quot;nt&quot;&gt;--color-words&lt;/span&gt; ac238c26 5d449a61
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;3-把diff的转换为html保存&quot;&gt;3. 把diff的转换为html保存&lt;/h2&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c&quot;&gt;# 首先安装ansi2html&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;# https://github.com/pixelb/scripts/blob/master/scripts/ansi2html.sh&lt;/span&gt;
wget &lt;span class=&quot;s2&quot;&gt;&quot;http://www.pixelbeat.org/scripts/ansi2html.sh&quot;&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-O&lt;/span&gt; ansi2html.sh
&lt;span class=&quot;nb&quot;&gt;chmod&lt;/span&gt; +x ansi2html.sh
git diff &lt;span class=&quot;nt&quot;&gt;--color-words&lt;/span&gt; HEAD~4 HEAD~3 | ansi2html.sh &lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; docs/diff.html
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;然后可以用浏览器打开&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;docs/diff.html&lt;/code&gt;查看，打印成pdf文件也可以&lt;/p&gt;

&lt;h2 id=&quot;4-ansi2htmlsh文件内容&quot;&gt;4. ansi2html.sh文件内容&lt;/h2&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c&quot;&gt;#!/bin/sh&lt;/span&gt;

&lt;span class=&quot;c&quot;&gt;# Convert ANSI (terminal) colours and attributes to HTML&lt;/span&gt;

&lt;span class=&quot;c&quot;&gt;# Licence: LGPLv2&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;# Author:&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;#    http://www.pixelbeat.org/docs/terminal_colours/&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;# Examples:&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;#    ls -l --color=always | ansi2html.sh &amp;gt; ls.html&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;#    git show --color | ansi2html.sh &amp;gt; last_change.html&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;#    Generally one can use the `script` util to capture full terminal output.&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;# Changes:&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;#    V0.1, 24 Apr 2008, Initial release&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;#    V0.2, 01 Jan 2009, Phil Harnish &amp;lt;philharnish@gmail.com&amp;gt;&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;#                         Support `git diff --color` output by&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;#                         matching ANSI codes that specify only&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;#                         bold or background colour.&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;#                       P@draigBrady.com&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;#                         Support `ls --color` output by stripping&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;#                         redundant leading 0s from ANSI codes.&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;#                         Support `grep --color=always` by stripping&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;#                         unhandled ANSI codes (specifically ^[[K).&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;#    V0.3, 20 Mar 2009, http://eexpress.blog.ubuntu.org.cn/&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;#                         Remove cat -v usage which mangled non ascii input.&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;#                         Cleanup regular expressions used.&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;#                         Support other attributes like reverse, ...&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;#                       P@draigBrady.com&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;#                         Correctly nest &amp;lt;span&amp;gt; tags (even across lines).&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;#                         Add a command line option to use a dark background.&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;#                         Strip more terminal control codes.&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;#    V0.4, 17 Sep 2009, P@draigBrady.com&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;#                         Handle codes with combined attributes and color.&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;#                         Handle isolated &amp;lt;bold&amp;gt; attributes with css.&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;#                         Strip more terminal control codes.&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;#    V0.26, 16 Nov 2019&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;#      http://github.com/pixelb/scripts/commits/master/scripts/ansi2html.sh&lt;/span&gt;

gawk &lt;span class=&quot;nt&quot;&gt;--version&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;/dev/null &lt;span class=&quot;o&quot;&gt;||&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;exit &lt;/span&gt;1

&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$1&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;--version&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;then
    &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;printf&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&apos;0.26\n&apos;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;exit
&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;fi

&lt;/span&gt;usage&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;printf&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&apos;%s\n&apos;&lt;/span&gt; &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
&lt;span class=&quot;s1&quot;&gt;&apos;This utility converts ANSI codes in data passed to stdin
It has 4 optional parameters:
--bg=dark --palette=linux|solarized|tango|xterm --css-only|--body-only
E.g.: ls -l --color=always | ansi2html.sh --bg=dark &amp;gt; ls.html&apos;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;&amp;amp;2
    &lt;span class=&quot;nb&quot;&gt;exit&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$1&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;--help&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;then
    &lt;/span&gt;usage
&lt;span class=&quot;k&quot;&gt;fi

&lt;/span&gt;processArg&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$1&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;--bg=dark&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;dark_bg&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;yes&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$1&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;--css-only&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;css_only&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;yes&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$1&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;--body-only&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;body_only&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;yes&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$1&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;--palette=solarized&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;then&lt;/span&gt;
       &lt;span class=&quot;c&quot;&gt;# See http://ethanschoonover.com/solarized&lt;/span&gt;
       &lt;span class=&quot;nv&quot;&gt;P0&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;073642&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;  &lt;span class=&quot;nv&quot;&gt;P1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;D30102&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;  &lt;span class=&quot;nv&quot;&gt;P2&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;859900&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;  &lt;span class=&quot;nv&quot;&gt;P3&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;B58900&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
       &lt;span class=&quot;nv&quot;&gt;P4&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;268BD2&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;  &lt;span class=&quot;nv&quot;&gt;P5&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;D33682&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;  &lt;span class=&quot;nv&quot;&gt;P6&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;2AA198&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;  &lt;span class=&quot;nv&quot;&gt;P7&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;EEE8D5&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
       &lt;span class=&quot;nv&quot;&gt;P8&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;002B36&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;  &lt;span class=&quot;nv&quot;&gt;P9&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;CB4B16&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;P10&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;586E75&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;P11&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;657B83&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
      &lt;span class=&quot;nv&quot;&gt;P12&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;839496&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;P13&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;6C71C4&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;P14&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;93A1A1&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;P15&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;FDF6E3&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
      &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;elif&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$1&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;--palette=solarized-xterm&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;then&lt;/span&gt;
       &lt;span class=&quot;c&quot;&gt;# Above mapped onto the xterm 256 color palette&lt;/span&gt;
       &lt;span class=&quot;nv&quot;&gt;P0&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;262626&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;  &lt;span class=&quot;nv&quot;&gt;P1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;AF0000&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;  &lt;span class=&quot;nv&quot;&gt;P2&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;5F8700&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;  &lt;span class=&quot;nv&quot;&gt;P3&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;AF8700&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
       &lt;span class=&quot;nv&quot;&gt;P4&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;0087FF&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;  &lt;span class=&quot;nv&quot;&gt;P5&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;AF005F&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;  &lt;span class=&quot;nv&quot;&gt;P6&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;00AFAF&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;  &lt;span class=&quot;nv&quot;&gt;P7&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;E4E4E4&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
       &lt;span class=&quot;nv&quot;&gt;P8&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;1C1C1C&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;  &lt;span class=&quot;nv&quot;&gt;P9&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;D75F00&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;P10&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;585858&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;P11&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;626262&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
      &lt;span class=&quot;nv&quot;&gt;P12&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;808080&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;P13&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;5F5FAF&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;P14&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;8A8A8A&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;P15&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;FFFFD7&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
      &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;elif&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$1&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;--palette=tango&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;then&lt;/span&gt;
       &lt;span class=&quot;c&quot;&gt;# Gnome default&lt;/span&gt;
       &lt;span class=&quot;nv&quot;&gt;P0&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;000000&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;  &lt;span class=&quot;nv&quot;&gt;P1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;CC0000&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;  &lt;span class=&quot;nv&quot;&gt;P2&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;4E9A06&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;  &lt;span class=&quot;nv&quot;&gt;P3&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;C4A000&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
       &lt;span class=&quot;nv&quot;&gt;P4&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;3465A4&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;  &lt;span class=&quot;nv&quot;&gt;P5&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;75507B&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;  &lt;span class=&quot;nv&quot;&gt;P6&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;06989A&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;  &lt;span class=&quot;nv&quot;&gt;P7&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;D3D7CF&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
       &lt;span class=&quot;nv&quot;&gt;P8&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;555753&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;  &lt;span class=&quot;nv&quot;&gt;P9&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;EF2929&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;P10&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;8AE234&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;P11&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;FCE94F&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
      &lt;span class=&quot;nv&quot;&gt;P12&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;729FCF&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;P13&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;AD7FA8&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;P14&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;34E2E2&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;P15&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;EEEEEC&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
      &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;elif&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$1&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;--palette=xterm&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;then
       &lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;P0&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;000000&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;  &lt;span class=&quot;nv&quot;&gt;P1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;CD0000&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;  &lt;span class=&quot;nv&quot;&gt;P2&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;00CD00&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;  &lt;span class=&quot;nv&quot;&gt;P3&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;CDCD00&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
       &lt;span class=&quot;nv&quot;&gt;P4&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;0000EE&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;  &lt;span class=&quot;nv&quot;&gt;P5&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;CD00CD&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;  &lt;span class=&quot;nv&quot;&gt;P6&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;00CDCD&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;  &lt;span class=&quot;nv&quot;&gt;P7&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;E5E5E5&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
       &lt;span class=&quot;nv&quot;&gt;P8&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;7F7F7F&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;  &lt;span class=&quot;nv&quot;&gt;P9&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;FF0000&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;P10&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;00FF00&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;P11&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;FFFF00&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
      &lt;span class=&quot;nv&quot;&gt;P12&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;5C5CFF&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;P13&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;FF00FF&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;P14&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;00FFFF&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;P15&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;FFFFFF&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
      &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;c&quot;&gt;# linux console&lt;/span&gt;
       &lt;span class=&quot;nv&quot;&gt;P0&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;000000&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;  &lt;span class=&quot;nv&quot;&gt;P1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;AA0000&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;  &lt;span class=&quot;nv&quot;&gt;P2&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;00AA00&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;  &lt;span class=&quot;nv&quot;&gt;P3&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;AA5500&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
       &lt;span class=&quot;nv&quot;&gt;P4&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;0000AA&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;  &lt;span class=&quot;nv&quot;&gt;P5&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;AA00AA&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;  &lt;span class=&quot;nv&quot;&gt;P6&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;00AAAA&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;  &lt;span class=&quot;nv&quot;&gt;P7&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;AAAAAA&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
       &lt;span class=&quot;nv&quot;&gt;P8&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;555555&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;  &lt;span class=&quot;nv&quot;&gt;P9&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;FF5555&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;P10&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;55FF55&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;P11&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;FFFF55&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
      &lt;span class=&quot;nv&quot;&gt;P12&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;5555FF&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;P13&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;FF55FF&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;P14&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;55FFFF&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;P15&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;FFFFFF&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
      &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$1&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;--palette=linux&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;fi&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;

processArg &lt;span class=&quot;c&quot;&gt;#defaults&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;for &lt;/span&gt;var &lt;span class=&quot;k&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$@&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;do &lt;/span&gt;processArg &lt;span class=&quot;nv&quot;&gt;$var&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;done&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$css_only&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$body_only&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; usage

&lt;span class=&quot;c&quot;&gt;# Mac OSX&apos;s GNU sed is installed as gsed&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;# use e.g. homebrew &apos;gnu-sed&apos; to get it&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;!&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;sed&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;--version&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;/dev/null 2&amp;gt;&amp;amp;1&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;then
  if &lt;/span&gt;gsed &lt;span class=&quot;nt&quot;&gt;--version&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;/dev/null 2&amp;gt;&amp;amp;1&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;then
    &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;alias sed&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;gsed
  &lt;span class=&quot;k&quot;&gt;else
    &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;echo&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;Error, can&apos;t find an acceptable GNU sed.&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;&amp;amp;2
    &lt;span class=&quot;nb&quot;&gt;exit &lt;/span&gt;1
  &lt;span class=&quot;k&quot;&gt;fi
fi&lt;/span&gt;

&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$css_only&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;||&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$body_only&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;||&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;printf&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&apos;%s&apos;&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;&amp;lt;html&amp;gt;
&amp;lt;head&amp;gt;
&amp;lt;meta http-equiv=&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;Content-Type&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt; content=&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;text/html; charset=utf-8&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;/&amp;gt;
&amp;lt;style type=&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;text/css&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;gt;
pre { white-space: pre-wrap; }
&quot;&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$body_only&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;||&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;printf&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;.ef0,.f0 { color: #&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$P0&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;; } .eb0,.b0 { background-color: #&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$P0&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;; }
.ef1,.f1 { color: #&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$P1&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;; } .eb1,.b1 { background-color: #&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$P1&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;; }
.ef2,.f2 { color: #&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$P2&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;; } .eb2,.b2 { background-color: #&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$P2&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;; }
.ef3,.f3 { color: #&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$P3&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;; } .eb3,.b3 { background-color: #&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$P3&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;; }
.ef4,.f4 { color: #&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$P4&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;; } .eb4,.b4 { background-color: #&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$P4&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;; }
.ef5,.f5 { color: #&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$P5&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;; } .eb5,.b5 { background-color: #&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$P5&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;; }
.ef6,.f6 { color: #&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$P6&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;; } .eb6,.b6 { background-color: #&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$P6&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;; }
.ef7,.f7 { color: #&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$P7&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;; } .eb7,.b7 { background-color: #&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$P7&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;; }
.ef8, .f0 &amp;gt; .bold,.bold &amp;gt; .f0 { color: #&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$P8&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;; font-weight: normal; }
.ef9, .f1 &amp;gt; .bold,.bold &amp;gt; .f1 { color: #&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$P9&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;; font-weight: normal; }
.ef10,.f2 &amp;gt; .bold,.bold &amp;gt; .f2 { color: #&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$P10&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;; font-weight: normal; }
.ef11,.f3 &amp;gt; .bold,.bold &amp;gt; .f3 { color: #&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$P11&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;; font-weight: normal; }
.ef12,.f4 &amp;gt; .bold,.bold &amp;gt; .f4 { color: #&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$P12&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;; font-weight: normal; }
.ef13,.f5 &amp;gt; .bold,.bold &amp;gt; .f5 { color: #&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$P13&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;; font-weight: normal; }
.ef14,.f6 &amp;gt; .bold,.bold &amp;gt; .f6 { color: #&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$P14&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;; font-weight: normal; }
.ef15,.f7 &amp;gt; .bold,.bold &amp;gt; .f7 { color: #&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$P15&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;; font-weight: normal; }
.eb8  { background-color: #&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$P8&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;; }
.eb9  { background-color: #&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$P9&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;; }
.eb10 { background-color: #&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$P10&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;; }
.eb11 { background-color: #&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$P11&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;; }
.eb12 { background-color: #&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$P12&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;; }
.eb13 { background-color: #&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$P13&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;; }
.eb14 { background-color: #&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$P14&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;; }
.eb15 { background-color: #&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$P15&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;; }
&quot;&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;# The default xterm 256 colour palette&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;for &lt;/span&gt;red &lt;span class=&quot;k&quot;&gt;in &lt;/span&gt;0 1 2 3 4 5 &lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;do
  for &lt;/span&gt;green &lt;span class=&quot;k&quot;&gt;in &lt;/span&gt;0 1 2 3 4 5 &lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;do
    for &lt;/span&gt;blue &lt;span class=&quot;k&quot;&gt;in &lt;/span&gt;0 1 2 3 4 5 &lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;do
      &lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;$((&lt;/span&gt;&lt;span class=&quot;m&quot;&gt;16&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$red&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;36&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$green&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;6&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$blue&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;))&lt;/span&gt;
      &lt;span class=&quot;nv&quot;&gt;r&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;$((&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$red&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;40&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;55&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$red&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;))&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
      &lt;span class=&quot;nv&quot;&gt;g&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;$((&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$green&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;40&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;55&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$green&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;))&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
      &lt;span class=&quot;nv&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;$((&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$blue&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;40&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;55&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$blue&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;))&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
      &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$body_only&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;||&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;printf&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;.ef%d { color: #%2.2x%2.2x%2.2x; } &quot;&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$c&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$r&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$g&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$b&lt;/span&gt;
      &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$body_only&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;||&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;printf&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;.eb%d { background-color: #%2.2x%2.2x%2.2x; }&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$c&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$r&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$g&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$b&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;done
  done
done
for &lt;/span&gt;gray &lt;span class=&quot;k&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;si&quot;&gt;$(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;seq &lt;/span&gt;0 23&lt;span class=&quot;si&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;do
  &lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;$((&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$gray&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;m&quot;&gt;232&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;))&lt;/span&gt;
  &lt;span class=&quot;nv&quot;&gt;l&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;$((&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$gray&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;m&quot;&gt;10&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;8&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;))&lt;/span&gt;
  &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$body_only&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;||&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;printf&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;.ef%d { color: #%2.2x%2.2x%2.2x; } &quot;&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$c&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$l&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$l&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$l&lt;/span&gt;
  &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$body_only&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;||&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;printf&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;.eb%d { background-color: #%2.2x%2.2x%2.2x; }&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$c&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$l&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$l&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$l&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;done&lt;/span&gt;

&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$body_only&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;||&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;printf&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&apos;%s&apos;&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&apos;
.f9 { color: &apos;&lt;/span&gt;&lt;span class=&quot;sb&quot;&gt;`&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$dark_bg&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;printf&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;#&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$P7&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;;&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;||&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;printf&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;#&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$P0&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;;&quot;&lt;/span&gt;&lt;span class=&quot;sb&quot;&gt;`&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&apos; }
.b9 { background-color: #&apos;&lt;/span&gt;&lt;span class=&quot;sb&quot;&gt;`&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$dark_bg&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;printf&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$P0&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;||&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;printf&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$P15&lt;/span&gt;&lt;span class=&quot;sb&quot;&gt;`&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&apos;; }
.f9 &amp;gt; .bold,.bold &amp;gt; .f9, body.f9 &amp;gt; pre &amp;gt; .bold {
  /* Bold is heavy black on white, or bright white
     depending on the default background */
  color: &apos;&lt;/span&gt;&lt;span class=&quot;sb&quot;&gt;`&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$dark_bg&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;printf&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;#&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$P15&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;;&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;||&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;printf&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;#&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$P0&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;;&quot;&lt;/span&gt;&lt;span class=&quot;sb&quot;&gt;`&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&apos;
  font-weight: &apos;&lt;/span&gt;&lt;span class=&quot;sb&quot;&gt;`&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$dark_bg&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;printf&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&apos;normal;&apos;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;||&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;printf&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&apos;bold;&apos;&lt;/span&gt;&lt;span class=&quot;sb&quot;&gt;`&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&apos;
}
.reverse {
  /* CSS does not support swapping fg and bg colours unfortunately,
     so just hardcode something that will look OK on all backgrounds. */
  &apos;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;color: #&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$P0&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;; background-color: #&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$P7&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;;&quot;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&apos;
}
.underline { text-decoration: underline; }
.line-through { text-decoration: line-through; }
.blink { text-decoration: blink; }
/* Avoid pixels between adjacent span elements.
   Note this only works for lines less than 80 chars
   where we close span elements on the same line.
span { display: inline-block; }
*/
&apos;&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$body_only&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;||&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$css_only&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;printf&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&apos;%s\n&apos;&lt;/span&gt; &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
&lt;span class=&quot;s1&quot;&gt;&apos;To use the css generated from --css-only, do: &apos;&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
&lt;span class=&quot;s1&quot;&gt;&apos;&amp;lt;head&amp;gt;&amp;lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;style.css&quot;&amp;gt;&amp;lt;/head&amp;gt;&apos;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;&amp;amp;2
&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$css_only&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;exit&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$body_only&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;||&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;printf&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&apos;%s&apos;&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&apos;&amp;lt;/style&amp;gt;
&amp;lt;/head&amp;gt;
&amp;lt;body class=&quot;f9 b9&quot;&amp;gt;
&amp;lt;pre&amp;gt;
&apos;&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$body_only&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;printf&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&apos;%s\n&apos;&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&apos;Be sure to use &amp;lt;body class=&quot;f9 b9&quot;&amp;gt; and &amp;lt;pre&amp;gt;&apos;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;&amp;amp;2

&lt;span class=&quot;nv&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&apos;\x1b\[&apos;&lt;/span&gt;        &lt;span class=&quot;c&quot;&gt;#shortcut to match escape codes&lt;/span&gt;

&lt;span class=&quot;c&quot;&gt;# Handle various xterm control sequences.&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;# See /usr/share/doc/xterm-*/ctlseqs.txt&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;sed&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;
# escape ampersand and quote
s#&amp;amp;#&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\&amp;amp;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;amp;#g; s#&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;#&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\&amp;amp;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;quot;#g;
s#&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\x&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;1b[^&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\x&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;1b]*&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\x&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;1b&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\\\#&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;#g  # strip anything between &lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\e&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt; and ST
s#&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\x&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;1b][0-9]*;[^&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\a&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;]*&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\a&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;##g # strip any OSC (xterm title etc.)
s#&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\r\$&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;## # strip trailing &lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\r&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;
# strip other non SGR escape sequences
s#[&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\x&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;07]##g
s#&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\x&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;1b[]&amp;gt;=&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\]&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;[0-9;]*##g
s#&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\x&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;1bP+.&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\{&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;##g
# Mark cursor positioning codes &lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;Jr;c;
s#&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;[0-9]&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\{&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;1,2&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\}\)&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;G#&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;J;&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\1&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;;#g
s#&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;[0-9]&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\{&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;1,2&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\}\)&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;[0-9]&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\{&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;1,2&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\}\)&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;H#&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;J&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\1&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\2&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;;#g
# Mark clear as &lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;Cn where n=1 is screen and n=0 is to end-of-line
s#&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;H#&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;C1;#g
s#&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;K#&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;C0;#g
# Mark Cursor move columns as &lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;Mn where n is +ve for right, -ve for left
s#&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;C#&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;M1;#g
s#&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;[0-9]&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\{&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;1,&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\}\)&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;C#&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;M&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\1&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;;#g
s#&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;[0-9]&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\{&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;1,&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\}\)&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;D#&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;M-&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\1&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;;#g
s#&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;[0-9]&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\{&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;1,&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\}\)&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;P#&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;X&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\1&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;;#g
s#&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;[0-9;?]*[^0-9;?m]##g
&quot;&lt;/span&gt; |

&lt;span class=&quot;c&quot;&gt;# Normalize the input before transformation&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;sed&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;
# escape HTML (ampersand and quote done above)
s#&amp;gt;#&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\&amp;amp;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;gt;#g; s#&amp;lt;#&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\&amp;amp;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;lt;#g;
# handle truecolor
s#&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;38;2;&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;[0-9]&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\{&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;1,3&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\}\)&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;[0-9]&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\{&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;1,3&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\}\)&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;[0-9]&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\{&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;1,3&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\}\)&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;m#&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;
&amp;lt;span style=&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;color:rgb(&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\1\,\2\,\3\)\&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;gt;#g
s#&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;48;2;&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;[0-9]&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\{&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;1,3&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\}\)&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;[0-9]&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\{&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;1,3&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\}\)&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;[0-9]&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\{&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;1,3&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\}\)&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;m#&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;
&amp;lt;span style=&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;background-color:rgb(&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\1\,\2\,\3\)\&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;gt;#g
# normalize SGR codes a little
# split 256 colors out and mark so that they&apos;re not
# recognised by the following &apos;split combined&apos; line
:e
s#&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;[0-9;]&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\{&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;1,&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\}\)&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;[34]8;5;[0-9]&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\{&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;1,3&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\}\)&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;m#&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\1&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;m&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;¬&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\2&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;m#g; t e
s#&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;[34]8;5;[0-9]&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\{&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;1,3&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\}\)&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;m#&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;¬&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\1&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;m#g;
:c
s#&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;[0-9]&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\{&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;1,&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\}\)&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;[0-9;]&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\{&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;1,&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\}\)&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;m#&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\1&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;m&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\2&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;m#g; t c   # split combined
s#&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;[0-7]&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\)&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;#&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\1&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;#g                                 #strip leading 0
s#&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;1m&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\(\(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;[4579]m&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\)&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\)&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;#&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\1&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;1m#g                   #bold last (with clr)
s#&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;m#&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;0m#g                                          #add leading 0 to norm
# undo any 256 color marking
s#&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;¬&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;[34]8;5;[0-9]&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\{&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;1,3&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\}\)&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;m#&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\1&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;m#g;
# map 16 color codes to color + bold
s#&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;9&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;[0-7]&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\)&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;m#&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\1&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;m&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;1m#g;
s#&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;[0-7]&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\)&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;m#&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\1&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;m&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;1m#g;
# change &apos;reset&apos; code to &lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;R
s#&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;0m#&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;R;#g
&quot;&lt;/span&gt; |

&lt;span class=&quot;c&quot;&gt;# Convert SGR sequences to HTML&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;sed&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;
# common combinations to minimise html (optional)
:f
s#&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;3[0-7]m&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;[0-7]&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\)&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;m#&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\1&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;m#g; t f
:b
s#&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;4[0-7]m&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;[0-7]&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\)&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;m#&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\1&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;m#g; t b
s#&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;[0-7]&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\)&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;m&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;[0-7]&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\)&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;m#&amp;lt;span class=&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\1&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt; b&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\2\&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;gt;#g
s#&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;[0-7]&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\)&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;m&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;[0-7]&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\)&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;m#&amp;lt;span class=&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\2&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt; b&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\1\&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;gt;#g
s#&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;1m#&amp;lt;span class=&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;bold&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;gt;#g
s#&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;4m#&amp;lt;span class=&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;underline&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;gt;#g
s#&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;5m#&amp;lt;span class=&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;blink&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;gt;#g
s#&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;7m#&amp;lt;span class=&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;reverse&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;gt;#g
s#&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;9m#&amp;lt;span class=&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;line-through&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;gt;#g
s#&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;[0-9]&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\)&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;m#&amp;lt;span class=&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\1\&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;gt;#g
s#&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;[0-9]&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\)&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;m#&amp;lt;span class=&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\1\&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;gt;#g
s#&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;38;5;&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;[0-9]&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\{&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;1,3&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\}\)&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;m#&amp;lt;span class=&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;ef&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\1\&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;gt;#g
s#&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;48;5;&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;[0-9]&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\{&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;1,3&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\}\)&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;m#&amp;lt;span class=&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;eb&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\1\&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;gt;#g
s#&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;[0-9;]*m##g # strip unhandled codes
&quot;&lt;/span&gt; |

&lt;span class=&quot;c&quot;&gt;# Convert alternative character set and handle cursor movement codes&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;# Note we convert here, as if we do at start we have to worry about avoiding&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;# conversion of SGR codes etc., whereas doing here we only have to&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;# avoid conversions of stuff between &amp;amp;...; or &amp;lt;...&amp;gt;&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;#&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;# Note we could use sed to do this based around:&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;#   sed &apos;y/abcdefghijklmnopqrstuvwxyz{}`~/▒␉␌␍␊°±␤␋┘┐┌└┼⎺⎻─⎼⎽├┤┴┬│≤≥π£◆·/&apos;&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;# However that would be very awkward as we need to only conv some input.&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;# The basic scheme that we do in the awk script below is:&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;#  1. enable transliterate once &quot;T1; is seen&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;#  2. disable once &quot;T0; is seen (may be on diff line)&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;#  3. never transliterate between &amp;amp;; or &amp;lt;&amp;gt; chars&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;#  4. track x,y movements and active display mode at each position&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;#  5. buffer line/screen and dump when required&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;sed&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;
# change &apos;smacs&apos; and &apos;rmacs&apos; to &lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;T1 and &lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;T0 to simplify matching.
s#&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\x&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;1b(0#&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;T1;#g;
s#&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\x&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;0E#&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;T1;#g;
s#&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\x&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;1b(B#&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;T0;#g
s#&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\x&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;0F#&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;T0;#g
&quot;&lt;/span&gt; |
&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;
gawk &lt;span class=&quot;s1&quot;&gt;&apos;
function dump_line(l,del,c,blanks,ret) {
  for(c=1;c&amp;lt;maxX;c++) {
    if ((c SUBSEP l) in attr || alength(cur)) {
      ret = ret blanks fixas(cur,attr[c,l])
      if(del) delete attr[c,l]
      blanks=&quot;&quot;
    }
    if ((c SUBSEP l) in dump) {
      ret=ret blanks dump[c,l]
      if(del) delete dump[c,l]
      blanks=&quot;&quot;
    } else blanks=blanks &quot; &quot;
  }
  if(alength(cur)) ret=ret blanks
  return ret
}
function dump_screen(l,ret) {
  for(l=1;l&amp;lt;=maxY;l++)
    ret=ret dump_line(l,0) &quot;\n&quot;
  return ret fixas(cur, &quot;&quot;)
}
function atos(a,i,ret) {
  for(i=1;i&amp;lt;=alength(a);i++) if(i in a) ret=ret a[i]
  return ret
}
function alength(a, i, k) {
    k = 0
    for(i in a) k++
    return k
}
function fixas(a,s,spc,i,attr,rm,ret) {
  spc=alength(a)
  l=split(s,attr,&quot;&amp;gt;&quot;)
  for(i=1;i&amp;lt;=spc;i++) {
    rm=rm?rm:(a[i]!=attr[i]&quot;&amp;gt;&quot;)
    if(rm) {
      ret=ret &quot;&amp;lt;/span&amp;gt;&quot;
      delete a[i];
    }
  }
  for(i=1;i&amp;lt;l;i++) {
    attr[i]=attr[i]&quot;&amp;gt;&quot;
    if(a[i]!=attr[i]) {
      a[i]=attr[i]
      ret = ret attr[i]
    }
  }
  return ret
}
function encode(string,start,end,i,ret,pos,sc,buf) {
   if(!end) end=length(string);
   if(!start) start=1;
   state=3
   for(i=1;i&amp;lt;=length(string);i++) {
     c=substr(string,i,1)
     if(state==2) {
       sc=sc c
       if(c==&quot;;&quot;) {
          c=sc
          state=last_mode
       } else continue
     } else {
       if(c==&quot;\r&quot;) { x=1; continue }
       if(c==&quot;&amp;lt;&quot;) {
         # Change attributes - store current active
         # attributes in span array
         split(substr(string,i),cord,&quot;&amp;gt;&quot;);
         i+=length(cord[1])
         span[++spc]=cord[1] &quot;&amp;gt;&quot;
         continue
       }
       else if(c==&quot;&amp;amp;&quot;) {
         # All goes to single position till we see a semicolon
         sc=c
         state=2
         continue
       }
       else if(c==&quot;\b&quot;) {
          # backspace move insertion point back 1
          if(spc) attr[x,y]=atos(span)
          x=x&amp;gt;1?x-1:1
          continue
       }
       else if(c==&quot;\&quot;&quot;) {
          split(substr(string,i+2),cord,&quot;;&quot;)
          cc=substr(string,i+1,1);
          if(cc==&quot;T&quot;) {
              # Transliterate on/off
              if(cord[1]==1&amp;amp;&amp;amp;state==3) last_mode=state=4
              if(cord[1]==0&amp;amp;&amp;amp;state==4) last_mode=state=3
          }
          else if(cc==&quot;C&quot;) {
              # Clear
              if(cord[1]+0) {
                # Screen - if Recording dump screen
                if(dumpStatus==dsActive) ret=ret dump_screen()
                dumpStatus=dsActive
                delete dump
                delete attr
                x=y=1
              } else {
                # To end of line
                for(pos=x;pos&amp;lt;maxX;pos++) {
                  dump[pos,y]=&quot; &quot;
                  if (!spc) delete attr[pos,y]
                  else attr[pos,y]=atos(span)
                }
              }
          }
          else if(cc==&quot;J&quot;) {
              # Jump to x,y
              i+=length(cord[2])+1
              # If line is higher - dump previous screen
              if(dumpStatus==dsActive&amp;amp;&amp;amp;cord[1]&amp;lt;y) {
                ret=ret dump_screen();
                dumpStatus=dsNew;
              }
              x=cord[2]
              if(length(cord[1]) &amp;amp;&amp;amp; y!=cord[1]){
                y=cord[1]
                if(y&amp;gt;maxY) maxY=y
                # Change y - start recording
                dumpStatus=dumpStatus?dumpStatus:dsReset
              }
          }
          else if(cc==&quot;M&quot;) {
              # Move left/right on current line
              x+=cord[1]
          }
          else if(cc==&quot;X&quot;) {
              # delete on right
              for(pos=x;pos&amp;lt;=maxX;pos++) {
                nx=pos+cord[1]
                if(nx&amp;lt;maxX) {
                  if((nx SUBSEP y) in attr) attr[pos,y] = attr[nx,y]
                  else delete attr[pos,y]
                  if((nx SUBSEP y) in dump) dump[pos,y] = dump[nx,y]
                  else delete dump[pos,y]
                } else if(spc) {
                  attr[pos,y]=atos(span)
                  dump[pos,y]=&quot; &quot;
                }
              }
          }
          else if(cc==&quot;R&quot;) {
              # Reset attributes
              while(spc) delete span[spc--]
          }
          i+=length(cord[1])+2
          continue
       }
       else if(state==4&amp;amp;&amp;amp;i&amp;gt;=start&amp;amp;&amp;amp;i&amp;lt;=end&amp;amp;&amp;amp;c in Trans) c=Trans[c]
     }
     if(dumpStatus==dsReset) {
       delete dump
       delete attr
       ret=ret&quot;\n&quot;
       dumpStatus=dsActive
     }
     if(dumpStatus==dsNew) {
       # After moving/clearing we are now ready to write
       # somthing to the screen so start recording now
       ret=ret&quot;\n&quot;
       dumpStatus=dsActive
     }
     if(dumpStatus==dsActive||dumpStatus==dsOff) {
       dump[x,y] = c
       if(!spc) delete attr[x,y]
       else attr[x,y] = atos(span)
       if(++x&amp;gt;maxX) maxX=x;
     }
    }
    # End of line if dumping increment y and set x back to first col
    x=1
    if(!dumpStatus) return ret dump_line(y,1);
    else if(++y&amp;gt;maxY) maxY=y;
    return ret
}
BEGIN{
  OFS=FS
  # dump screen status
  dsOff=0    # Not dumping screen contents just write output direct
  dsNew=1    # Just after move/clear waiting for activity to start recording
  dsReset=2  # Screen cleared build new empty buffer and record
  dsActive=3 # Currently recording
  F=&quot;abcdefghijklmnopqrstuvwxyz{}`~&quot;
  T=&quot;▒␉␌␍␊°±␤␋┘┐┌└┼⎺⎻─⎼⎽├┤┴┬│≤≥π£◆·&quot;
  maxX=80
  delete cur;
  x=y=1
  for(i=1;i&amp;lt;=length(F);i++)Trans[substr(F,i,1)]=substr(T,i,1);
}
{ $0=encode($0) }
1
END {
  if(dumpStatus) {
    print dump_screen();
  }
}&apos;&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$body_only&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;||&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;printf&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&apos;&amp;lt;/pre&amp;gt;
&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;\n&apos;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
</description>
        <pubDate>Tue, 27 Dec 2022 20:20:52 +0800</pubDate>
        <link>https://blog.whuzfb.cn/blog/2022/12/27/git-diff/</link>
        <guid isPermaLink="true">https://blog.whuzfb.cn/blog/2022/12/27/git-diff/</guid>
        
        <category>Git</category>
        
        <category>Windows</category>
        
        <category>Ubuntu</category>
        
        <category>Linux</category>
        
        
        <category>Git</category>
        
        <category>Windows</category>
        
        <category>Ubuntu</category>
        
        <category>Linux</category>
        
      </item>
    
      <item>
        <title>SRT字幕文件转文本文件</title>
        <description>&lt;h2 class=&quot;no_toc&quot; id=&quot;目录&quot;&gt;目录&lt;/h2&gt;

&lt;ul id=&quot;markdown-toc&quot;&gt;
  &lt;li&gt;&lt;a href=&quot;#1-获取字幕文件&quot; id=&quot;markdown-toc-1-获取字幕文件&quot;&gt;1. 获取字幕文件&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#2-python脚本&quot; id=&quot;markdown-toc-2-python脚本&quot;&gt;2. python脚本&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;1-获取字幕文件&quot;&gt;1. 获取字幕文件&lt;/h2&gt;
&lt;p&gt;一般来说，很多视频网站都会提供视频的字幕文件。有的可以直接下载，有的需要先下载视频，然后再使用字幕软件提取字幕文件。还有一些可以在Chrome浏览器中安装字幕插件，然后在视频播放页面中直接下载字幕文件。总而言之，需要先获取到字幕文件，然后才能进行下一步操作。&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;SRT&lt;/code&gt;格式的字幕文件是最常见的，其格式如下所示：&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-txt&quot; data-lang=&quot;txt&quot;&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
2
3
4
5
6
7
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;code&quot;&gt;&lt;pre&gt;1
00:00:00,000 --&amp;gt; 00:00:02,000
Life is short

2
00:00:02,205 --&amp;gt; 00:00:04,000
You need Python
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;可以看到，字幕文件由多个字幕组成，每个字幕由两行组成，第一行是字幕的序号，第二行是字幕的时间轴，第三行是字幕的内容。字幕之间用空行分隔。所以，只需要先删除所有空行，然后对&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;line_num%3==0&lt;/code&gt;的行进行处理，即可得到字幕的内容&lt;/p&gt;

&lt;h2 id=&quot;2-python脚本&quot;&gt;2. python脚本&lt;/h2&gt;
&lt;p&gt;文件内容如下：&lt;/p&gt;
&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;#!/usr/bin/env python
# -*- coding: utf-8 -*-
# author: &apos;zfb&apos;
# time: 2019-10-26 17:17
&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;argparse&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;glob&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;os&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;# 输出文件的头部信息，可以为空
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;header&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;zfb 2019-10-26 17:17&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n\n&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;# 段落开始符号
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;begin_para_symbol&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;  &quot;&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;# 拼接句子的符号
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;split_line_symbol&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;，&quot;&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;# 拼接字幕文件的符号
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;split_file_symbol&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n\n\n&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;read_toc&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;file_name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;with&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;open&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;file_name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;r&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;encoding&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;utf8&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;file&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;lines&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;file&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;readlines&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;# 去除所有空行
&lt;/span&gt;        &lt;span class=&quot;n&quot;&gt;strip_lines&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;line&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;strip&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;line&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;lines&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;len&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;line&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;strip&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;())]&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;strip_lines&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;read_srt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;file_name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;with&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;open&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;file_name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;r&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;encoding&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;utf8&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;file&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;lines&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;file&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;readlines&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;# 去除所有空行
&lt;/span&gt;        &lt;span class=&quot;n&quot;&gt;strip_lines&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;line&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;strip&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;line&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;lines&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;len&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;line&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;strip&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;())]&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;# 根据文件格式，字幕文字所在行是3的倍数，从起始位置，到结束位置，间隔为3
&lt;/span&gt;        &lt;span class=&quot;n&quot;&gt;text_lines&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;strip_lines&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;# 按照逗号拼接全文
&lt;/span&gt;        &lt;span class=&quot;n&quot;&gt;text&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;split_line_symbol&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;join&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;text_lines&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;text&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;get_files&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;directory&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;# 按文件名排序
&lt;/span&gt;    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;sorted&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;glob&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;glob&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;os&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;path&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;join&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;directory&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;*.srt&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)))&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;convert&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;srt_files&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;toc_lines&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;txt_name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;content&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;header&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;range&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;len&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;srt_files&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)):&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;content&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;content&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;toc_lines&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;begin_para_symbol&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;read_srt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;srt_files&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;split_file_symbol&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;with&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;open&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;txt_name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;w&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;file&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;nb&quot;&gt;file&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;write&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;content&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;


&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;__name__&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;__main__&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;parser&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;argparse&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ArgumentParser&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;description&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;SRT字幕文件转TXT文件&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;formatter_class&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;argparse&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;RawDescriptionHelpFormatter&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;epilog&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;
&lt;span class=&quot;s&quot;&gt;&apos;&apos;&apos;&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\
&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;用法示例：
    python srt2txt.py ./srt/ ./content.txt -t ./toc.txt
    python srt2txt.py ./srt/ ./content.txt
    python srt2txt.py
&apos;&apos;&apos;&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;# 可选参数
&lt;/span&gt;    &lt;span class=&quot;n&quot;&gt;parser&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;add_argument&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
        &lt;span class=&quot;s&quot;&gt;&quot;-s&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;--srt_dir&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;str&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;default&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;./srt/&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;help&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;*.srt字幕文件所在目录，默认为当前目录下的srt文件夹&quot;&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;parser&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;add_argument&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
        &lt;span class=&quot;s&quot;&gt;&quot;-o&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;--output_name&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;str&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;default&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;./content.txt&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;help&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;输出文件名，默认为content.txt&quot;&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;parser&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;add_argument&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
        &lt;span class=&quot;s&quot;&gt;&quot;-t&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;--toc&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;str&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;default&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;./toc.txt&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;help&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;目录文件名，默认为toc.txt, 如果没有，会根据字幕文件名生成&quot;&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;args&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;parser&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;parse_args&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;# 字幕文件所在目录
&lt;/span&gt;    &lt;span class=&quot;n&quot;&gt;srt_file_path&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;args&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;srt_dir&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;# 目录文件，如果没有，会根据字幕文件名生成
&lt;/span&gt;    &lt;span class=&quot;n&quot;&gt;toc_file&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;args&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;toc&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;# 输出文件
&lt;/span&gt;    &lt;span class=&quot;n&quot;&gt;txt_file&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;args&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;output_name&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;files&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;get_files&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;srt_file_path&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;os&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;path&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;exists&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;toc_file&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;# 读取目录文件
&lt;/span&gt;        &lt;span class=&quot;n&quot;&gt;toc_lines&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;read_toc&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;toc_file&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;# 根据srt文件名，生成目录文件
&lt;/span&gt;        &lt;span class=&quot;n&quot;&gt;toc_lines&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;os&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;path&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;basename&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;file&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;file&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;files&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;convert&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;files&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;toc_lines&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;txt_file&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
</description>
        <pubDate>Tue, 27 Dec 2022 19:35:11 +0800</pubDate>
        <link>https://blog.whuzfb.cn/blog/2022/12/27/convert-srt-to-txt/</link>
        <guid isPermaLink="true">https://blog.whuzfb.cn/blog/2022/12/27/convert-srt-to-txt/</guid>
        
        <category>Python</category>
        
        <category>Linux</category>
        
        <category>Ubuntu</category>
        
        <category>Windows</category>
        
        
        <category>Python</category>
        
        <category>Linux</category>
        
        <category>Ubuntu</category>
        
        <category>Windows</category>
        
      </item>
    
      <item>
        <title>在ubuntu系统安装配置heatererp软件</title>
        <description>&lt;h2 class=&quot;no_toc&quot; id=&quot;目录&quot;&gt;目录&lt;/h2&gt;

&lt;ul id=&quot;markdown-toc&quot;&gt;
  &lt;li&gt;&lt;a href=&quot;#1-下载软件包并安装依赖&quot; id=&quot;markdown-toc-1-下载软件包并安装依赖&quot;&gt;1. 下载软件包并安装依赖&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#2-配置heatererp&quot; id=&quot;markdown-toc-2-配置heatererp&quot;&gt;2. 配置heatererp&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#3-创建文件夹保存运算结果&quot; id=&quot;markdown-toc-3-创建文件夹保存运算结果&quot;&gt;3. 创建文件夹保存运算结果&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#4-运行测试&quot; id=&quot;markdown-toc-4-运行测试&quot;&gt;4. 运行测试&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#5-注意&quot; id=&quot;markdown-toc-5-注意&quot;&gt;5. 注意&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;1-下载软件包并安装依赖&quot;&gt;1. 下载软件包并安装依赖&lt;/h2&gt;
&lt;p&gt;安装需要依赖的软件，使用&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;nec2c&lt;/code&gt;虽然运行慢，但是配置简单&lt;br /&gt;
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sudo apt-get install zip nec2c octave&lt;/code&gt;&lt;br /&gt;
本项目代码仓库网址： &lt;a href=&quot;https://gitlab.com/andrewsenior/heatererp&quot; title=&quot;&amp;quot;)  
项目介绍网址： [https://www.eiscat.uit.no/DataBases/heating_logs/htr-log-index-2015.html](https://www.eiscat.uit.no/DataBases/heating_logs/htr-log-index-2015.html &amp;quot;&quot;&gt;https://gitlab.com/andrewsenior/heatererp&lt;/a&gt;&lt;/p&gt;
&lt;h2 id=&quot;2-配置heatererp&quot;&gt;2. 配置heatererp&lt;/h2&gt;
&lt;p&gt;启动heatererp，步骤如下：&lt;br /&gt;
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cd ~/heatererp-master/bin&lt;/code&gt;&lt;br /&gt;
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;chmod +x ./erpmodel.sh&lt;/code&gt;&lt;br /&gt;
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;./erpmodel.sh&lt;/code&gt;&lt;br /&gt;
然后会提示设置各种路径，可以随便弄，然后再修改&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;~/.config/heatererp/conf.m&lt;/code&gt;文件中的路径&lt;br /&gt;
设置完以后保证&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;conf.m&lt;/code&gt;的内容如下，注意&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;model_engine&lt;/code&gt;设置为&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;nec2c&lt;/code&gt;&lt;/p&gt;
&lt;div class=&quot;language-matlab highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;% Configuration script for Heater ERP model&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;model_dir&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&apos;/home/zfb/heatererp-master/models&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;nec2_bin&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&apos;/the/real/path/to/nec2&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;nec2c_bin&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&apos;nec2c&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;model_engine&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&apos;nec2c&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;log_dir&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&apos;/home/zfb/heatererp/logs&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;results_dir&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&apos;/home/zfb/heatererp/results&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;plots_dir&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&apos;/home/zfb/heatererp/plots&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;h2 id=&quot;3-创建文件夹保存运算结果&quot;&gt;3. 创建文件夹保存运算结果&lt;/h2&gt;
&lt;p&gt;创建的文件夹要与&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;conf.m&lt;/code&gt;文件中设置的相对应&lt;br /&gt;
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cd ~ &amp;amp;&amp;amp; mkdir heatererp &amp;amp;&amp;amp; cd heatererp&lt;/code&gt;&lt;br /&gt;
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;mkdir logs plots results&lt;/code&gt;&lt;/p&gt;
&lt;h2 id=&quot;4-运行测试&quot;&gt;4. 运行测试&lt;/h2&gt;
&lt;p&gt;放置log文件，执行sh脚本运行模型&lt;br /&gt;
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cp ~/heatererp-master/testing/1970-01-01_tx.log ~/heatererp/logs/&lt;/code&gt;&lt;br /&gt;
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cd ~/heatererp-master/bin &amp;amp;&amp;amp; ./erpmodel.sh&lt;/code&gt;&lt;br /&gt;
在打开的octave软件的提示符里面输入以下内容即可计算&lt;br /&gt;
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;erpmodel(&apos;01-Jan-1970 00:00:00&apos;);erpmodel(&apos;01-Jan-1970 01:28:00&apos;);&lt;/code&gt;
等待运行结束，在&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/home/zfb/heatererp/&lt;/code&gt;对应文件夹寻找结果&lt;/p&gt;
&lt;h2 id=&quot;5-注意&quot;&gt;5. 注意&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;在Ubuntu 18.04系统测试通过（Ubuntu 20.04好像不太行）&lt;/li&gt;
  &lt;li&gt;如果系统有GUI，还会同时显示图片&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.log&lt;/code&gt;文件的第一行是实验开始时间，&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;erpmodel()&lt;/code&gt;的参数可以是那个时刻及以后的时刻&lt;/li&gt;
&lt;/ul&gt;
</description>
        <pubDate>Sat, 27 Feb 2021 15:37:56 +0800</pubDate>
        <link>https://blog.whuzfb.cn/blog/2021/02/27/ubuntu_config_heatererp/</link>
        <guid isPermaLink="true">https://blog.whuzfb.cn/blog/2021/02/27/ubuntu_config_heatererp/</guid>
        
        <category>Ubuntu</category>
        
        <category>Linux</category>
        
        
        <category>Ubuntu</category>
        
        <category>Linux</category>
        
      </item>
    
      <item>
        <title>在linux系统监控某个程序的执行情况并通知用户</title>
        <description>&lt;h2 class=&quot;no_toc&quot; id=&quot;目录&quot;&gt;目录&lt;/h2&gt;

&lt;ul id=&quot;markdown-toc&quot;&gt;
  &lt;li&gt;&lt;a href=&quot;#介绍&quot; id=&quot;markdown-toc-介绍&quot;&gt;介绍&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#代码&quot; id=&quot;markdown-toc-代码&quot;&gt;代码&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#运行监控代码文件&quot; id=&quot;markdown-toc-运行监控代码文件&quot;&gt;运行监控代码文件&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;介绍&quot;&gt;介绍&lt;/h2&gt;
&lt;p&gt;如果有一个下载任务需要执行（&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;python3 download.py&lt;/code&gt;），该任务会下载许多文件，一般将其放在后台执行。但是又需要知道它是否在某个时刻退出，可能是因为：&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;任务执行完毕，正常结束运行&lt;/li&gt;
  &lt;li&gt;任务异常退出，可能由于下载的网站爬虫策略限制，也可能是其他原因&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;无论由于哪个原因，一旦程序停止，都需要立刻用户，所以编写以下代码来实现该功能&lt;/p&gt;
&lt;h2 id=&quot;代码&quot;&gt;代码&lt;/h2&gt;
&lt;p&gt;使用python语言编写监控程序&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;detect.py&lt;/code&gt;文件：&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;如果需要使用腾讯云发送短信通知，则安装库&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;qcloudsms_py&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;如果需要使用twilio发送短信通知，则安装库&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;twilio&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;文件内容如下：&lt;/p&gt;
&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;#!/usr/bin/env python
# -*- coding: utf-8 -*-
# author: &apos;zfb&apos;
# time: 19-06-29 09:52
&lt;/span&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;datetime&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;json&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;os&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;requests&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;socket&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;logging&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;logging.handlers&lt;/span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;RotatingFileHandler&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;qcloudsms_py&lt;/span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;SmsSingleSender&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;qcloudsms_py.httpclient&lt;/span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;HTTPError&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;LOG_FORMAT&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;%(asctime)s [%(funcName)s: %(filename)s,%(lineno)d] - %(levelname)s : %(message)s&quot;&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;DATE_FORMAT&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;%m/%d/%Y %H:%M:%S&quot;&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;LOG_PATH&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;./log/&quot;&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;# 初始化日志文件配置
&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;initLog&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;fileName&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;logger&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;# 创建日志文件夹
&lt;/span&gt;    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;not&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;os&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;path&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;exists&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;LOG_PATH&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;os&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;mkdir&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;LOG_PATH&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;myapp&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;logging&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;getLogger&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;logger&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;myapp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;setLevel&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;logging&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;DEBUG&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;# 切割日志文件
&lt;/span&gt;    &lt;span class=&quot;n&quot;&gt;handler&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;RotatingFileHandler&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;LOG_PATH&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;fileName&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;maxBytes&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;128&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1024&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;backupCount&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;60&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;handler&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;setFormatter&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;logging&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Formatter&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;LOG_FORMAT&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;DATE_FORMAT&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;myapp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;addHandler&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;handler&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;myapp&lt;/span&gt;


&lt;span class=&quot;n&quot;&gt;logging&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;initLog&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;detect.log&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&apos;detect&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;# ------------  使用腾讯云发送短信通知用户  -----------
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;APP_ID&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1412345678&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;APP_KEY&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;3998d59614123456789b72dd5961405c&quot;&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;TEMPLATE_ID&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;101234&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;SMS_SIGN&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;签名A&quot;&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;# ------------  使用腾讯云发送短信通知用户  -----------
&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;# ------------  使用twilio发送短信  ------------------
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;SMS_SID&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&apos;ACb770c5f63aac91c44d97891234567890&apos;&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;SMS_TOKEN&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&apos;42b1294966799e965883181234567890&apos;&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;SMS_FROM_NUMBER&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&apos;+12512123456&apos;&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;# ------------  使用twilio发送短信  ------------------
&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;# ------------  使用邮箱发信  ------------------------
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;EMAIL_FROM&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&apos;example@qq.com&apos;&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;EMAIL_PWD&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&apos;123demo&apos;&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;# ------------  使用邮箱发信  ------------------------
&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;sendSMS&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;number&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;params&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;app_id&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;APP_ID&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;key&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;APP_KEY&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;template_id&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;TEMPLATE_ID&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;sms_sign&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;SMS_SIGN&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;ssender&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;SmsSingleSender&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;app_id&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;key&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;try&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;result&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ssender&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;send_with_param&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;86&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;number&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;template_id&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; 
                &lt;span class=&quot;n&quot;&gt;params&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;sign&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;sms_sign&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;extend&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ext&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;except&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;HTTPError&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;e&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;log&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;json&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;dumps&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;e&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ensure_ascii&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;False&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;logging&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;error&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;except&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;Exception&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;e&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;log&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;json&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;dumps&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;e&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ensure_ascii&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;False&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;logging&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;error&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;log&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;json&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;dumps&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;result&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ensure_ascii&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;False&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;logging&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;debug&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;


&lt;span class=&quot;c1&quot;&gt;# 使用twilio的使用账户发送短信
&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;send_sms&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;phone&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;content&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;twilio.rest&lt;/span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Client&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;# 账户信息： twilio.com/console
&lt;/span&gt;    &lt;span class=&quot;n&quot;&gt;account_sid&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;SMS_SID&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;auth_token&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;SMS_TOKEN&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;from_phone_num&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;SMS_FROM_NUMBER&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;client&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Client&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;account_sid&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;auth_token&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;message&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;messages&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;create&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;body&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;content&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;from_&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;from_phone_num&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;to&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;phone&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;message&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;sid&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;


&lt;span class=&quot;c1&quot;&gt;# 使用139邮箱的短信通知功能
&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;send_email&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;email&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;subject&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;msg&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;smtplib&lt;/span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;SMTPException&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;SMTP_SSL&lt;/span&gt;
    &lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;email.mime.text&lt;/span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;MIMEText&lt;/span&gt;
    &lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;email.header&lt;/span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Header&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;# 发件人
&lt;/span&gt;    &lt;span class=&quot;n&quot;&gt;sender&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;EMAIL_FROM&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;pwd&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;EMAIL_PWD&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;# 三个参数：第一个为文本内容，第二个为plain设置文本格式，第三个为utf-8设置编码
&lt;/span&gt;    &lt;span class=&quot;n&quot;&gt;message&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;MIMEText&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;msg&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;plain&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;utf-8&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;message&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;From&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Header&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;sender&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;utf-8&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;message&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;To&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Header&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;email&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;utf-8&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;message&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Subject&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Header&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;subject&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;utf-8&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;try&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;# 使用非本地服务器，需要建立ssl连接
&lt;/span&gt;        &lt;span class=&quot;n&quot;&gt;smtpObj&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;SMTP_SSL&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;smtp.exmail.qq.com&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;465&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;smtpObj&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;login&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;sender&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;pwd&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;smtpObj&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;sendmail&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;sender&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;email&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;message&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;as_string&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;())&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;邮件发送成功&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;except&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;SMTPException&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;e&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Error：无法发送邮件.Case:%s&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;%&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;e&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;


&lt;span class=&quot;c1&quot;&gt;# 检测下载进程是否正在运行
&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;isRunning&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;search_param&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;output&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;os&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;popen&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;ps -ef | grep {}&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;format&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;search_param&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;length&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;line&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;output&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;# print(line)
&lt;/span&gt;        &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;/bin/sh&quot;&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;line&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;or&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;grep&quot;&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;line&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;or&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;Terminated&quot;&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;line&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;continue&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;length&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;length&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;# print(length)
&lt;/span&gt;    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;bp&quot;&gt;True&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;length&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;bp&quot;&gt;False&lt;/span&gt;


&lt;span class=&quot;c1&quot;&gt;# 获取系统用户名和ip
&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;getInfomation&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;():&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;user&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;socket&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;gethostname&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;# 创建socket访问DNS来获取本机的IP，如果是NAT的话，则是局域网IP
&lt;/span&gt;    &lt;span class=&quot;n&quot;&gt;local_ip&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;127.0.0.1&quot;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;try&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;socket&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;socket&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;socket&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;AF_INET&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;socket&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;SOCK_DGRAM&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;connect&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;((&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;1.1.1.1&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;80&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;local_ip&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;getsockname&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;finally&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;close&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;# 访问www.ip.cn网站获取公网IP
&lt;/span&gt;    &lt;span class=&quot;n&quot;&gt;net_ip&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;127.0.0.1&quot;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;try&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;net_ip&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;requests&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;https://api.ipify.org&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;text&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;finally&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;pass&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;user&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;local_ip&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;net_ip&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;


&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;__name__&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;__main__&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;status&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;isRunning&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;download.py&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;flag_file&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;/home/ubuntu/flag&quot;&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;# now = datetime.datetime.now().strftime(&quot;%Y-%m-%d %H:%M:%S&quot;)
&lt;/span&gt;    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;status&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;logging&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;debug&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;program is running&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;os&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;path&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;isfile&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;flag_file&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;logging&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;error&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;program stopped, nobody fixed it.&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;info&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;getInfomation&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;msg&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;您的主机{}，公网IP地址为{}，局域网IP为{}，下载进程已中断&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;format&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;info&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;info&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;info&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;phone&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;13612345678&quot;&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;sendSMS&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;phone&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;spy&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;msg&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;send_sms&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;phone&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;msg&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;send_email&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;user@qq.com&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;spy&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;msg&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;with&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;open&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;flag_file&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;w+&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;file&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
                &lt;span class=&quot;nb&quot;&gt;file&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;write&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Please delete me after restarting the download program.&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;logging&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;error&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;program stopped&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;h2 id=&quot;运行监控代码文件&quot;&gt;运行监控代码文件&lt;/h2&gt;
&lt;p&gt;在终端输入&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;crontab -e&lt;/code&gt;打开定时管理任务，然后在文件中最后添加一行，内容如下：&lt;br /&gt;
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;*/30 * * * * python3 /home/ubuntu/detect.py&lt;/code&gt;&lt;br /&gt;
此代码表示每隔30min运行一次&lt;br /&gt;
&lt;strong&gt;注意&lt;/strong&gt;：每次重新启动下载进程之后，务必删除&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;flag&lt;/code&gt;文件（为了防止因为没有及时重启下载进程而浪费短信资源，在主目录&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;~&lt;/code&gt;下输入&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;rm flag&lt;/code&gt;即可删除此文件）&lt;/p&gt;
</description>
        <pubDate>Thu, 11 Feb 2021 13:30:21 +0800</pubDate>
        <link>https://blog.whuzfb.cn/blog/2021/02/11/linux_monitor_program/</link>
        <guid isPermaLink="true">https://blog.whuzfb.cn/blog/2021/02/11/linux_monitor_program/</guid>
        
        <category>Ubuntu</category>
        
        <category>Linux</category>
        
        <category>Python</category>
        
        
        <category>Ubuntu</category>
        
        <category>Linux</category>
        
        <category>Python</category>
        
      </item>
    
      <item>
        <title>在linux系统使用expect命令自动填充ssh或scp等命令的密码</title>
        <description>&lt;h2 class=&quot;no_toc&quot; id=&quot;目录&quot;&gt;目录&lt;/h2&gt;

&lt;ul id=&quot;markdown-toc&quot;&gt;
  &lt;li&gt;&lt;a href=&quot;#expect命令使用范例&quot; id=&quot;markdown-toc-expect命令使用范例&quot;&gt;expect命令使用范例&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;expect命令使用范例&quot;&gt;expect命令使用范例&lt;/h2&gt;
&lt;p&gt;shell脚本文件的名称为&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;download.sh&lt;/code&gt;，内容如下：&lt;/p&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c&quot;&gt;#!/usr/bin/env bash&lt;/span&gt;

&lt;span class=&quot;c&quot;&gt;# 任何一句命令执行出错，都会终止该脚本&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;set&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-e&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;# 设置为调试模式，在执行过程中会同时输出各变量的值&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;# set -x&lt;/span&gt;

&lt;span class=&quot;c&quot;&gt;# 连接scp&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;#######################&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;# expect {&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;#   -re &quot;.*es.*o.*&quot; {&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;#     exp_send &quot;yes\r&quot;&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;#     exp_continue&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;#   }&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;#   -re &quot;.*sword.*&quot; {&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;#     exp_send &quot;mypwd12345\r&quot;&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;#   }&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;# }&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;# 把远程机器上的文件下载到本地机器&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;# 参数1: 远程机器上的文件（或文件夹）的绝对路径&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;# 参数2: 存放位置，即本地机器上的文件夹&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;# 当scp下载大文件时，需要耗费更多时间，设置timeout&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;function &lt;/span&gt;scp_download&lt;span class=&quot;o&quot;&gt;(){&lt;/span&gt;
&lt;span class=&quot;nv&quot;&gt;src&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$1&lt;/span&gt;
&lt;span class=&quot;nv&quot;&gt;dst&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$2&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$# &lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;-eq&lt;/span&gt; 2 &lt;span class=&quot;o&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;then
    &lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;need_ssh&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;0
&lt;span class=&quot;k&quot;&gt;else
    &lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;need_ssh&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$3&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;fi
&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;zfb
&lt;span class=&quot;nv&quot;&gt;host&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;192.168.1.56&quot;&lt;/span&gt;
&lt;span class=&quot;nv&quot;&gt;passwd&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;1234567890pwd&quot;&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$3&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-eq&lt;/span&gt; 1 &lt;span class=&quot;o&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;then&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;# ssh登录远程机器，为目标文件添加读写执行权限&lt;/span&gt;
/usr/bin/expect&lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;EOF&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;
    spawn ssh &lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$name&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;@&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$host&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;
    expect {
        -timeout -1
        &quot;*yes/no&quot; {
            send &quot;yes&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\r&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;;exp_continue
        }
        &quot;*password:&quot; {
            send &quot;&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$passwd&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\r&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;
            # zfb@my-Server:~$
            expect &quot;~.*&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$&quot;&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;
            send &quot;sudo chmod 777 &lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$src&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\r&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;
            expect &quot;*assword:&quot;
            send &quot;&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$passwd&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\r&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;
            expect &quot;~.*&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$&quot;&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;
            send &quot;exit&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\r&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;
            expect eof
        }
    }
&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;EOF
&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;fi&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;# 使用scp自动下载文件&lt;/span&gt;
/usr/bin/expect&lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;EOF&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;
    set timeout 600
    spawn scp -r &lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$name&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;@&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$host&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$src&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$dst&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;
    expect {
        &quot;*yes/no&quot; {
            send &quot;yes&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\r&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;;exp_continue
        }
        &quot;*password:&quot; {
            send &quot;&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$passwd&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\r&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;
            expect eof
        }
    }
&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;EOF
&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;


&lt;span class=&quot;c&quot;&gt;# 脚本运行参数&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;# 参数1: 远程机器的文件（夹）绝对路径， 例如 /media/data/test/a.txt&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;# 参数2：保存位置，即本地路径&lt;/span&gt;

&lt;span class=&quot;c&quot;&gt;# 若本地不存在，则创建目录&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;!&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-d&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$2&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;then
    &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;echo&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$2&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot; does not exist, ready to mkdir &quot;&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$2&lt;/span&gt;
    &lt;span class=&quot;nb&quot;&gt;mkdir&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-p&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$2&lt;/span&gt;
    &lt;span class=&quot;nb&quot;&gt;echo&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;mkdir successfully!&quot;&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;fi
&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$2&lt;/span&gt;/opendata
&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;!&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-d&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$data&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;then
    &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;echo&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$data&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot; does not exist, ready to mkdir &quot;&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$data&lt;/span&gt;
    &lt;span class=&quot;nb&quot;&gt;mkdir&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-p&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$data&lt;/span&gt;
    &lt;span class=&quot;nb&quot;&gt;echo&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;mkdir successfully!&quot;&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;fi

&lt;/span&gt;scp_download &lt;span class=&quot;nv&quot;&gt;$1&lt;/span&gt;/test.txt &lt;span class=&quot;nv&quot;&gt;$2&lt;/span&gt;
scp_download &lt;span class=&quot;nv&quot;&gt;$1&lt;/span&gt;/test/testaa.py &lt;span class=&quot;nv&quot;&gt;$2&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;mv&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$2&lt;/span&gt;/testaa.py &lt;span class=&quot;nv&quot;&gt;$2&lt;/span&gt;/testbb.py
scp_download &lt;span class=&quot;nv&quot;&gt;$1&lt;/span&gt;/test/opendata/testcc.txt &lt;span class=&quot;nv&quot;&gt;$data&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;# testdd.txt在远程机器上，无读取权限，需要ssh进行chmod添加权限&lt;/span&gt;
scp_download &lt;span class=&quot;nv&quot;&gt;$1&lt;/span&gt;/test/opendata/testdd.txt &lt;span class=&quot;nv&quot;&gt;$data&lt;/span&gt; 1
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;使用方法示例：&lt;br /&gt;
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;./download.sh /media/data/test ./&lt;/code&gt;&lt;/p&gt;
</description>
        <pubDate>Sat, 16 Jan 2021 14:13:22 +0800</pubDate>
        <link>https://blog.whuzfb.cn/blog/2021/01/16/linux_expect/</link>
        <guid isPermaLink="true">https://blog.whuzfb.cn/blog/2021/01/16/linux_expect/</guid>
        
        <category>Ubuntu</category>
        
        <category>Linux</category>
        
        
        <category>Ubuntu</category>
        
        <category>Linux</category>
        
      </item>
    
  </channel>
</rss>