Added documentation

This commit is contained in:
Gnarwhal 2024-08-01 06:01:23 +00:00
parent 86a75c4755
commit 11740120ac
Signed by: Gnarwhal
GPG key ID: 0989A73D8C421174
2 changed files with 132 additions and 13 deletions

126
README.md
View file

@ -2,7 +2,130 @@
Upload files to a server via ssh
### Hmmm
## Documentation
### Arguments
#### `-h` `--help`
Show the help message and exit
#### `-v` `--version`
Show the program's version number and exit
#### `-l` `--latest`
Upload the most recently modified file in `source_directory`
#### `-p` `--paste`
Upload the contents of the clipboard as a `.txt` file
#### `-f FILE` `--file FILE`
Upload a file
#### `-c` `--copy`
Copy the resultant URL to the clipboard
### Configuration File
The configuration file is located at `$XDG_CONFIG_DIR/sshare/config.toml`.
If `XDG_CONFIG_DIR` is not set, then it will read from `$HOME/.config/sshare/config.toml` instead.
#### `source_directory`
The directory from which `--latest` reads.
- [x] Optional - Cannot use `--latest` if it is not set
#### `host`
```
https://example.com:4430/path/to/files/*
^---^ ^---------^ ^--^^------------^
| | | |
| | | +- `host.path` = "/path/to/files"
| | +----- `host.port` = 4430
| +----------------- `host.name` = "example.com"
+------------------------- `host.protocol` = "https"
https://example.com/*
^---------^
|
| `host.path` Not set
| `host.port` Not set
+----------------- `host.name` = "example.com"
`host.protocol` Not set (Defaults to `https`)
```
#### `host.protocol`
The protocol by which the file is served
- [x] Optional - Default: `https`
#### `host.name`
The name of the host (e.g. `example.com`, `1.1.1.1`)
- [ ] Not optional
#### `host.port`
The port from which the host is serving files
- [x] Optional - Default: `None` (which means the default port for the protocol)
#### `host.path`
The subpath from which the host is serving files. If set, `host.path` must start
with and **NOT** end with a `/` (e.g. `/path/to/files` not `path/to/files/`)
- [x] Optional - If the host is serving from the root
#### `ssh`
```
ssh -p 1234 example@example.com:/srv/static
^--^ ^-----^ ^---------^ ^---------^
| | | |
| | | +- `ssh.path` = "/srv/static"
| | +------------- Uses `host.name`
| +--------------------- `ssh.user` = "example"
+-------------------------- `ssh.port` = 1234"
ssh example@example.com:/srv/static
^-----^ ^---------^ ^---------^
| | |
| | +- `ssh.path` = "/srv/static"
| +------------- Uses `host.name`
+--------------------- `ssh.user` Doesn't need to be set if `example` is
the name of the user running `sshare`
`ssh.part` Not set (Defaults to 22)
```
#### `ssh.port`
The port the server is listening for ssh connections on
- [x] Optional - Default: 22
#### `ssh.user`
The user to connect to the host with
- [x] Optional - Default: The user that ran `sshare`
#### `ssh.path`
The directory on the host from which static files are being hosted. If set,
`ssh.path` must **NOT** end with a path (e.g. `/srv/static` not `/srv/static/`)
- [ ] Not optional
#### Example Configuration File
```toml
# config.toml
source_directory = "/home/example/Pictures/Screenshots"
# Host is serving static files at https://example.com:443/sshare/*
# Note: both protocol and port would be optional here as https is
# the default protocol and port 443 is the default https port
[host]
protocol = "https"
name = "example.com"
port = 443
path = "/sshare"
# Host is listening for ssh connections on port 1234 and
# serving files from the `/srv/sshare` directory
[ssh]
port = 1234
user = "exampleuser2"
path = "/srv/sshare"
```
## Hmmm
Apparently GNOME 42 screenshot utility is called via dbus
@ -22,4 +145,3 @@ I would not expect it to be too hard. But unfortunately I want to use
GNOME 42 screenshot ;-;
What to do...

View file

@ -58,15 +58,12 @@ class Config:
sys.exit(1)
self.ssh_port = ssh.get("port")
self.ssh_user = ssh.get("user")
self.ssh_host = ssh.get("host")
self.ssh_directory = ssh.get("directory")
self.ssh_path = ssh.get("directory")
if self.ssh_port == None:
self.ssh_port = 22
if self.ssh_user == None:
self.ssh_user = getpass.getuser()
if self.ssh_host == None:
self.ssh_host = self.host_name;
if self.ssh_directory == None:
if self.ssh_path == None:
print("Error: 'ssh.directory' cannot be 'None'")
sys.exit(1)
@ -106,8 +103,8 @@ def main():
target_id = time.time_ns()
target_file_name = f"{target_id}{target_file_extension}"
target_file = f"{config.ssh_directory}/{target_file_name}"
target_destination = f"{config.ssh_user}@{config.ssh_host}"
target_file = f"{config.ssh_path}/{target_file_name}"
target_destination = f"{config.ssh_user}@{config.host_name}"
print(f"Uploading to host: {target_destination}, port: {config.ssh_port}, file: {target_file}")
process = subprocess.run([
"ssh",
@ -155,7 +152,7 @@ def parse_arguments():
"--paste",
action="store_const",
const=True,
help="Upload the contents of the clipboard as a txt",
help="Upload the contents of the clipboard as a .txt file",
)
parser.add_argument(
"-f",
@ -167,7 +164,7 @@ def parse_arguments():
"--copy",
action="store_const",
const=True,
help="Copy the resultant url to the clipboard",
help="Copy the resultant URL to the clipboard",
)
arguments = parser.parse_args()