Skip to main content

Primitive Batch - Multiplatform Python script for batch execution of prim-ctrl and prim-sync commands.

Project description

Primitive Batch

Multiplatform Python script for batch execution of prim-ctrl and prim-sync commands.

With the help of this script you can sync multiple phones (Primitive FTPd SFTP servers) and multiple folders on them in a preconfigured way.

It basically concatenates command lines for prim-ctrl and prim-sync based on the config. So depending on your system, Windows or Unix, use the appropriate single or double quotation marks and proper escaping in the config file.

See my other project, https://github.com/lmagyar/prim-sync, for bidirectional and unidirectional sync over SFTP (multiplatform Python script optimized for the Primitive FTPd SFTP server).

See my other project, https://github.com/lmagyar/prim-ctrl, for remote control of your phone's Primitive FTPd SFTP server and optionally Tailscale VPN.

Note: These are my first ever Python projects, any comments on how to make them better are appreciated.

Features

  • Optionally select only 1 server and/or folder to sync from the configuration, this is useful for a manually started sync
  • Optionally select a scheduled run, that tests networking, syncs without pause and with less log messages, but with some extra log lines that are practical when the output is appended to a log file
  • Optionally select a test run and only print out the commands that are configured to run

Installation

You need to install:

Optionally, if you want to edit or even contribute to the source, you also need to install:

Configuration

It uses TOML file for configuration. Instead of specification, here is an example config:

Unix
ctrl-args = "--funnel your-laptop 12345 /prim-ctrl 8443"
sync-args = "-rs '/fs/storage/emulated/0' --ignore-locks 60 -sh"

[configs]
in  = { sync-args = "-ui -m --overwrite-destination" }
out = { sync-args = "-uo -m --overwrite-destination" }

[servers.your-phone]
ctrl-args = "Automate youraccount@gmail.com 'SOME MANUFACTURER XXX' automate your-phone-pftpd --tailscale tailxxxx.ts.net your-phone 2222"
sync-args = "your-phone-pftpd id_ed25519_sftp"
sync-args-vpn = "-a your-phone.tailxxxx.ts.net 2222"

[servers.your-phone.configs]
int = { sync-args = "'~/Mobile' '/fs/storage/emulated/0' '*'" }
ext = { sync-args = "'~/Mobile' '/fs/storage/XXXX-XXXX'  '/saf'" }

[servers.your-phone.folders]
Camera        = { configs = [ "ext" ],        sync-args = "'Camera' 'DCIM/Camera'" }
Music         = { configs = [ "ext", "out" ], sync-args = "'Music' '*'" }
Screenshots   = { configs = [ "int" ],        sync-args = "'Screenshots' 'DCIM/Screenshots'" }
Windows
ctrl-args = '--funnel your-laptop 12345 /prim-ctrl 8443'
sync-args = '-rs "/fs/storage/emulated/0" --ignore-locks 60 -sh'

[configs]
in  = { sync-args = '-ui -m --overwrite-destination' }
out = { sync-args = '-uo -m --overwrite-destination' }

[servers.your-phone]
ctrl-args = 'Automate youraccount@gmail.com "SOME MANUFACTURER XXX" automate your-phone-pftpd --tailscale tailxxxx.ts.net your-phone 2222'
sync-args = 'your-phone-pftpd id_ed25519_sftp'
sync-args-vpn = '-a your-phone.tailxxxx.ts.net 2222'

[servers.your-phone.configs]
int = { sync-args = '"D:\Mobile" "/fs/storage/emulated/0" "*"' }
ext = { sync-args = '"D:\Mobile" "/fs/storage/XXXX-XXXX"  "/saf"' }

[servers.your-phone.folders]
Camera        = { configs = [ 'ext' ],        sync-args = '"Camera" "DCIM/Camera"' }
Music         = { configs = [ 'ext', 'out' ], sync-args = '"Music" "*"' }
Screenshots   = { configs = [ 'int' ],        sync-args = '"Screenshots" "DCIM/Screenshots"' }

Usage

Some example

prim-batch config.toml -t
prim-batch config.toml -t --servers your-phone --folders Camera
prim-batch config.toml -t --scheduled

Options

usage: prim-batch [-h] [--scheduled] [--no-pause] [--servers SERVER [SERVER ...]] [--folders FOLDER [FOLDER ...]] [--skip-ctrl] [--use-vpn] [--ctrl-only {test,start,stop}] [--test] [-t] [-s] [--debug]
                  [--ctrl-args ARGS] [-d] [--sync-args ARGS]
                  config-file

Multiplatform Python script for batch execution of prim-ctrl and prim-sync commands, for more details see https://github.com/lmagyar/prim-batch

positional arguments:
  config-file                    TOML config file

options:
  -h, --help                     show this help message and exit
  --scheduled                    tests networking, syncs without pause and with less log messages, but with some extra log lines that are practical when the output is appended to a log file
  --no-pause                     syncs without pause
  --servers SERVER [SERVER ...]  syncs only the specified SERVERs (all, or only the specified --folders FOLDERs on them)
  --folders FOLDER [FOLDER ...]  syncs only the specified FOLDERs (on all, or only on the specified --servers SERVERs)
  --skip-ctrl                    use only prim-sync, you have to start/stop the server manually
  --use-vpn                      use vpn config (not zeroconf) to access the server (can be used only when --skip-ctrl is used)
  --ctrl-only {test,start,stop}  use only prim-ctrl, you can sync the server manually (this is the equivalent of prim-ctrl's -i option)
  --test                         do not execute any prim-ctrl or prim-sync commands, just log them ("dry" option for prim-batch), enables the --no-pause and --debug options

logging:
  Note: prim-sync and prim-ctrl commands will receive these options also

  -t, --timestamp                prefix each message with a timestamp
  -s, --silent                   only errors printed
  --debug                        use debug level logging and add stack trace for exceptions, disables the --silent and enables the --timestamp options

prim-ctrl:
  --ctrl-args ARGS               any prim-ctrl arguments to pass on - between quotation marks, using equal sign, like --ctrl-args='--accept-cellular'

prim-sync:
  -d, --dry                      no files changed in the synchronized folder(s), only internal state gets updated and temporary files get cleaned up
  --sync-args ARGS               any prim-sync arguments to pass on - between quotation marks, using equal sign, like --sync-args='--ignore-locks'

Project details


Download files

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

Source Distribution

prim_batch-0.4.0.tar.gz (11.8 kB view details)

Uploaded Source

Built Distribution

prim_batch-0.4.0-py3-none-any.whl (12.9 kB view details)

Uploaded Python 3

File details

Details for the file prim_batch-0.4.0.tar.gz.

File metadata

  • Download URL: prim_batch-0.4.0.tar.gz
  • Upload date:
  • Size: 11.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.6 Windows/11

File hashes

Hashes for prim_batch-0.4.0.tar.gz
Algorithm Hash digest
SHA256 95cc9159f1b28477e522c9f460aeccce3ce3c768575e14d696ebb4bd7da8ddbd
MD5 d118d96d153191dfb2fad3e90e0e6c29
BLAKE2b-256 ca061951ea43c5d4c7e79a9abbcb48ad2be9aa3fd91369d4d7863e3a648e8d47

See more details on using hashes here.

File details

Details for the file prim_batch-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: prim_batch-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 12.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.6 Windows/11

File hashes

Hashes for prim_batch-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 35886d7295cb248d7d607c5c5840a789a5dc1838ab449d6f6048dc44e375f69f
MD5 c1967a5e0ca85c69bc5b2650e372bf14
BLAKE2b-256 b6f792341cfbaa8f7ccaf9427c1e641a00f480abba91db66616b13653387709a

See more details on using hashes here.

Supported by

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