Skip to content

Commit

Permalink
Add BEP support table to readme
Browse files Browse the repository at this point in the history
Also adds `bin/bin/generate-bep-table.rs`, which generates and updates
the table from a collection of BEPs.

type: documentation
  • Loading branch information
casey committed Apr 8, 2020
1 parent d1f8f24 commit 66d4415
Show file tree
Hide file tree
Showing 5 changed files with 300 additions and 9 deletions.
21 changes: 14 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ categories = ["command-line-utilities"]
homepage = "https://github.com/casey/intermodal"
repository = "https://github.com/casey/intermodal"
edition = "2018"
default-run = "imdl"

[dependencies]
ansi_term = "0.12"
Expand All @@ -31,3 +32,14 @@ walkdir = "2"
[dependencies.serde]
version = "1"
features = ["derive"]

[dev-dependencies]
glob = "0.3.0"
regex = "1.3.3"

# generates the table of supported BEPs in README.md
# not an example, but included as an example and not
# a binary because examples can use dev dependencies
[[example]]
name = "generate-bep-table"
path = "bin/generate-bep-table.rs"
72 changes: 71 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,76 @@
# intermodal: a 40' shipping container for the Internet

## Colored Output
## Bittorrent

### BEP Support

| Symbol | Meaning |
|--------------------|----------------|
| :white_check_mark: | Supported |
| :x: | Unsupported |
| :heavy_minus_sign: | Not Applicable |

| BEP | Status | Title |
|:----------------------------------------------:|:------------------:|:-----------------------------------------------------------------|
| [00](http://bittorrent.org/beps/bep_0000.html) | :heavy_minus_sign: | Index of BitTorrent Enhancement Proposals |
| [01](http://bittorrent.org/beps/bep_0001.html) | :heavy_minus_sign: | The BitTorrent Enhancement Proposal Process |
| [02](http://bittorrent.org/beps/bep_0002.html) | :heavy_minus_sign: | Sample reStructured Text BEP Template |
| [03](http://bittorrent.org/beps/bep_0003.html) | :x: | The BitTorrent Protocol Specification |
| [04](http://bittorrent.org/beps/bep_0004.html) | :heavy_minus_sign: | Assigned Numbers |
| [05](http://bittorrent.org/beps/bep_0005.html) | :x: | DHT Protocol |
| [06](http://bittorrent.org/beps/bep_0006.html) | :heavy_minus_sign: | Fast Extension |
| [07](http://bittorrent.org/beps/bep_0007.html) | :heavy_minus_sign: | IPv6 Tracker Extension |
| [08](http://bittorrent.org/beps/bep_0008.html) | :heavy_minus_sign: | Tracker Peer Obfuscation |
| [09](http://bittorrent.org/beps/bep_0009.html) | :x: | Extension for Peers to Send Metadata Files |
| [10](http://bittorrent.org/beps/bep_0010.html) | :heavy_minus_sign: | Extension Protocol |
| [11](http://bittorrent.org/beps/bep_0011.html) | :heavy_minus_sign: | Peer Exchange (PEX) |
| [12](http://bittorrent.org/beps/bep_0012.html) | :white_check_mark: | Multitracker Metadata Extension |
| [14](http://bittorrent.org/beps/bep_0014.html) | :heavy_minus_sign: | Local Service Discovery |
| [15](http://bittorrent.org/beps/bep_0015.html) | :heavy_minus_sign: | UDP Tracker Protocol for BitTorrent |
| [16](http://bittorrent.org/beps/bep_0016.html) | :heavy_minus_sign: | Superseeding |
| [17](http://bittorrent.org/beps/bep_0017.html) | :x: | HTTP Seeding |
| [18](http://bittorrent.org/beps/bep_0018.html) | :heavy_minus_sign: | Search Engine Specificiation |
| [19](http://bittorrent.org/beps/bep_0019.html) | :x: | WebSeed - HTTP/FTP Seeding (GetRight style) |
| [20](http://bittorrent.org/beps/bep_0020.html) | :heavy_minus_sign: | Peer ID Conventions |
| [21](http://bittorrent.org/beps/bep_0021.html) | :heavy_minus_sign: | Extension for partial seeds |
| [22](http://bittorrent.org/beps/bep_0022.html) | :heavy_minus_sign: | BitTorrent Local Tracker Discovery Protocol |
| [23](http://bittorrent.org/beps/bep_0023.html) | :heavy_minus_sign: | Tracker Returns Compact Peer Lists |
| [24](http://bittorrent.org/beps/bep_0024.html) | :heavy_minus_sign: | Tracker Returns External IP |
| [25](http://bittorrent.org/beps/bep_0025.html) | :heavy_minus_sign: | An Alternate BitTorrent Cache Discovery Protocol |
| [26](http://bittorrent.org/beps/bep_0026.html) | :heavy_minus_sign: | Zeroconf Peer Advertising and Discovery |
| [27](http://bittorrent.org/beps/bep_0027.html) | :white_check_mark: | Private Torrents |
| [28](http://bittorrent.org/beps/bep_0028.html) | :heavy_minus_sign: | Tracker exchange extension |
| [29](http://bittorrent.org/beps/bep_0029.html) | :heavy_minus_sign: | uTorrent transport protocol |
| [30](http://bittorrent.org/beps/bep_0030.html) | :x: | Merkle hash torrent extension |
| [31](http://bittorrent.org/beps/bep_0031.html) | :heavy_minus_sign: | Failure Retry Extension |
| [32](http://bittorrent.org/beps/bep_0032.html) | :heavy_minus_sign: | BitTorrent DHT Extensions for IPv6 |
| [33](http://bittorrent.org/beps/bep_0033.html) | :heavy_minus_sign: | DHT Scrapes |
| [34](http://bittorrent.org/beps/bep_0034.html) | :x: | DNS Tracker Preferences |
| [35](http://bittorrent.org/beps/bep_0035.html) | :x: | Torrent Signing |
| [36](http://bittorrent.org/beps/bep_0036.html) | :x: | Torrent RSS feeds |
| [37](http://bittorrent.org/beps/bep_0037.html) | :heavy_minus_sign: | Anonymous BitTorrent over proxies |
| [38](http://bittorrent.org/beps/bep_0038.html) | :x: | Finding Local Data Via Torrent File Hints |
| [39](http://bittorrent.org/beps/bep_0039.html) | :x: | Updating Torrents Via Feed URL |
| [40](http://bittorrent.org/beps/bep_0040.html) | :heavy_minus_sign: | Canonical Peer Priority |
| [41](http://bittorrent.org/beps/bep_0041.html) | :x: | UDP Tracker Protocol Extensions |
| [42](http://bittorrent.org/beps/bep_0042.html) | :heavy_minus_sign: | DHT Security extension |
| [43](http://bittorrent.org/beps/bep_0043.html) | :heavy_minus_sign: | Read-only DHT Nodes |
| [44](http://bittorrent.org/beps/bep_0044.html) | :x: | Storing arbitrary data in the DHT |
| [45](http://bittorrent.org/beps/bep_0045.html) | :x: | Multiple-address operation for the BitTorrent DHT |
| [46](http://bittorrent.org/beps/bep_0046.html) | :x: | Updating Torrents Via DHT Mutable Items |
| [47](http://bittorrent.org/beps/bep_0047.html) | :x: | Padding files and extended file attributes |
| [48](http://bittorrent.org/beps/bep_0048.html) | :x: | Tracker Protocol Extension: Scrape |
| [49](http://bittorrent.org/beps/bep_0049.html) | :x: | Distributed Torrent Feeds |
| [50](http://bittorrent.org/beps/bep_0050.html) | :heavy_minus_sign: | Publish/Subscribe Protocol |
| [51](http://bittorrent.org/beps/bep_0051.html) | :heavy_minus_sign: | DHT Infohash Indexing |
| [52](http://bittorrent.org/beps/bep_0052.html) | :x: | The BitTorrent Protocol Specification v2 |
| [53](http://bittorrent.org/beps/bep_0053.html) | :x: | Magnet URI extension - Select specific file indices for download |
| [54](http://bittorrent.org/beps/bep_0054.html) | :heavy_minus_sign: | The lt_donthave extension |
| [55](http://bittorrent.org/beps/bep_0055.html) | :heavy_minus_sign: | Holepunch extension |

## General Functionality

### Colored Output

Intermodal features colored help, error, and informational output. Colored
output is disabled if Intermodal detects that it is not printing to a TTY.
Expand Down
190 changes: 190 additions & 0 deletions bin/generate-bep-table.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
use std::{
error::Error,
fmt::{self, Display, Formatter},
fs,
str::FromStr,
};

use glob::glob;
use regex::Regex;

const README: &str = "README.md";

struct Bep {
number: usize,
title: String,
status: Status,
}

enum Status {
Unknown,
NotApplicable,
Supported,
NotSupported,
}

impl FromStr for Status {
type Err = String;

fn from_str(text: &str) -> Result<Self, Self::Err> {
match text {
"x" => Ok(Self::NotSupported),
"+" => Ok(Self::Supported),
"-" => Ok(Self::NotApplicable),
"?" => Ok(Self::Unknown),
":x:" => Ok(Self::NotSupported),
":white_check_mark:" => Ok(Self::Supported),
":heavy_minus_sign:" => Ok(Self::NotApplicable),
":grey_question:" => Ok(Self::Unknown),
_ => Err(format!("invalid status: {}", text)),
}
}
}

impl Display for Status {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
match self {
Self::Unknown => write!(f, ":grey_question:"),
Self::NotApplicable => write!(f, ":heavy_minus_sign:"),
Self::Supported => write!(f, ":white_check_mark:"),
Self::NotSupported => write!(f, ":x:"),
}
}
}

fn main() -> Result<(), Box<dyn Error>> {
let title_re = Regex::new("(?m)^:Title: (?P<title>.*)$")?;

let mut beps = Vec::new();

for result in glob("tmp/bittorrent.org/beps/bep_*.rst")? {
let path = result?;

let number = path
.file_stem()
.unwrap()
.to_string_lossy()
.split('_')
.nth(1)
.unwrap()
.parse::<usize>()?;

if number == 1000 {
continue;
}

let rst = fs::read_to_string(path)?;

let title = title_re
.captures(&rst)
.unwrap()
.name("title")
.unwrap()
.as_str()
.trim()
.to_owned();

beps.push(Bep {
status: Status::Unknown,
number,
title,
});
}

beps.sort_by_key(|bep| bep.number);

let table_re = Regex::new(
r"(?mx)
^[|]\ BEP.*
(
\n
[|]
.*
)*
",
)?;

let readme = fs::read_to_string(README)?;

let parts = table_re.split(&readme).into_iter().collect::<Vec<&str>>();

assert_eq!(parts.len(), 2);

let before = parts[0];
let after = parts[1];
let original = table_re
.captures(&readme)
.unwrap()
.get(0)
.unwrap()
.as_str()
.trim();

let row_re = Regex::new(
r"(?x)
^
\|
\s*
\[
(?P<number>[0-9]+)
\]
.*
\s*
\|
(?P<status>.*)
\|
(?P<title>.*)
\|
$
",
)?;

let mut originals = Vec::new();

for row in original.lines().skip(2) {
let captures = row_re.captures(row).unwrap();
originals.push(Bep {
number: captures.name("number").unwrap().as_str().parse()?,
status: captures.name("status").unwrap().as_str().trim().parse()?,
title: captures.name("title").unwrap().as_str().to_owned(),
});
}

assert_eq!(originals.len(), beps.len());

let mut lines = Vec::new();

let width = beps.iter().map(|bep| bep.title.len()).max().unwrap_or(0);

lines.push(format!(
"| BEP | Status | {:width$} |",
"Title",
width = width
));

lines.push(format!(
"|:----------------------------------------------:|:------------------:|:{:-<width$}-|",
"",
width = width
));

for (bep, original) in beps.into_iter().zip(originals) {
assert_eq!(bep.number, original.number);
lines.push(format!(
"| [{:02}](http://bittorrent.org/beps/bep_{:04}.html) | {:18} | {:width$} |",
bep.number,
bep.number,
original.status.to_string(),
bep.title,
width = width
));
}

let table = lines.join("\n");

let readme = &[before.trim(), "", &table, "", after.trim(), ""].join("\n");

fs::write(README, readme)?;

Ok(())
}
Loading

0 comments on commit 66d4415

Please sign in to comment.