[V3 Downloader] Use shlex for subprocesses #2421

Merged
Zephyrkul merged 2 commits from V3/git-space into V3/develop 2019-02-14 23:32:12 +01:00
Zephyrkul commented 2019-02-05 20:17:04 +01:00 (Migrated from github.com)

Type

  • Bugfix
  • Enhancement
  • New feature

Description of the changes

This allows for spaces in the bot's data dir without breaking the cloning process.
{noquote_arg} can be used if splitting normally is still necessary (see the PIP_INSTALL value). Edit: See below comment.

### Type - [X] Bugfix - [ ] Enhancement - [ ] New feature ### Description of the changes This allows for spaces in the bot's data dir without breaking the cloning process. ~~`{noquote_arg}` can be used if splitting normally is still necessary (see the `PIP_INSTALL` value).~~ Edit: See below comment.
tekulvw (Migrated from github.com) reviewed 2019-02-05 20:17:04 +01:00
Zephyrkul commented 2019-02-08 05:26:12 +01:00 (Migrated from github.com)

I've pushed a different approach to this. My original approach I disliked due to the fact that it:

  1. required undocumented syntax ("{noquote_arg}");
  2. forbade any positional formatting args; and
  3. just generally looked weird and turned a simple format call into half a dozen or more.

I instead decided to implement a ProcessFormatter class, which properly shlex-quotes all formatting args, including positional if that ends up being used, and returns a shlex-split list that can be used for subprocesses. Non-string iterables passed into the formatter will be considered seperate arguments for the command, so {noquote_arg} is no longer necessary (just pass a tuple or list, e.g. L488). I'd be willing to move this class somewhere into utils if it'd be useful elsewhere, but it's a very small class so it should be fine where it is.

I've pushed a different approach to this. My original approach I disliked due to the fact that it: 1. required undocumented syntax (`"{noquote_arg}"`); 2. forbade any positional formatting args; and 3. just generally looked weird and turned a simple format call into half a dozen or more. I instead decided to implement a [`ProcessFormatter`](https://github.com/zephyrkul/Red-DiscordBot/blob/V3/git-space/redbot/cogs/downloader/repo_manager.py#L27) class, which properly shlex-quotes all formatting args, including positional if that ends up being used, and returns a shlex-split list that can be used for subprocesses. Non-string iterables passed into the formatter will be considered seperate arguments for the command, so `{noquote_arg}` is no longer necessary (just pass a tuple or list, e.g. [L488](https://github.com/zephyrkul/Red-DiscordBot/blob/V3/git-space/redbot/cogs/downloader/repo_manager.py#L488)). I'd be willing to move this class somewhere into utils if it'd be useful elsewhere, but it's a very small class so it should be fine where it is.
Zephyrkul commented 2019-02-14 06:04:59 +01:00 (Migrated from github.com)

I hate to bother, but this is the second most common but with Downloader, yet it's been six days since the last commit and eight days since this PR opened. Am I missing something? Is this PR being put aside for a later, larger fix? Is this a duplicate? Is there something wrong with the code that should be addressed?

I hate to bother, but this is the second most common but with Downloader, yet it's been six days since the last commit and eight days since this PR opened. Am I missing something? Is this PR being put aside for a later, larger fix? Is this a duplicate? Is there something wrong with the code that should be addressed?
Twentysix26 commented 2019-02-14 09:43:41 +01:00 (Migrated from github.com)

@zephyrkul I don't see anything particularly wrong with it, just nobody got around reviewing the PR yet. Time permitting, I'll try to review it tonight myself

@zephyrkul I don't see anything particularly wrong with it, just nobody got around reviewing the PR yet. Time permitting, I'll try to review it tonight myself
Twentysix26 (Migrated from github.com) approved these changes 2019-02-14 23:31:24 +01:00
Sign in to join this conversation.
No labels
Automated PR
Blocked
Blocked By: Damage Control
Blocked By: Dependency
Blocked By: Other PR
Breaking Change
Category: CI
Category: Cogs - Admin
Category: Cogs - Alias
Category: Cogs - Audio
Category: Cogs - Bank
Category: Cogs - Cleanup
Category: Cogs - CustomCommands
Category: Cogs - Dev
Category: Cogs - Downloader
Category: Cogs - Economy
Category: Cogs - Filter
Category: Cogs - General
Category: Cogs - Image
Category: Cogs - Mod
Category: Cogs - Modlog
Category: Cogs - Mutes
Category: Cogs - Permissions
Category: Cogs - Reports
Category: Cogs - Streams
Category: Cogs - Trivia
Category: Cogs - Trivia - Lists
Category: Cogs - Warnings
Category: Core - API - App Commands Package
Category: Core - API - Audio
Category: Core - API - Bank
Category: Core - API - Commands Package
Category: Core - API - Config
Category: Core - API - Other
Category: Core - API - Utils Package
Category: Core - Bot Class
Category: Core - Bot Commands
Category: Core - Command-line Interfaces
Category: Core - Downloader
Category: Core - Help
Category: Core - i18n
Category: Core - Modlog
Category: Core - Other Internals
Category: Core - RPC/ZMQ
Category: Docker
Category: Docs - Changelogs
Category: Docs - For Developers
Category: Docs - Install Guides
Category: Docs - Other
Category: Docs - User Guides
Category: Meta
Category: RPC/ZMQ methods
Category: Vendored Packages
Changelog Entry: Added
Changelog Entry: Pending
Changelog Entry: Skipped
Closed: Duplicate
Closed: External
Closed: Invalid
Closed: User Error
Closed: Won't Fix
Complex Issue
Docs-only
Feature Branch
Good First Issue
Help Wanted
High Priority
Needs Backport To stable-docs
No Activity
No Repro
QA: Bypassed
QA: Changes Requested
QA: Passed
Release Blocker
Status: Accepted
Status: Frozen
Status: In Progress
Status: Needs Discussion
Status: Needs Info
Status: Needs Triage
Status: PRs Welcome
Type: Bug
Type: Dependency Update
Type: Deprecation
Type: Enhancement
Type: Feature
Type: Informational
Type: Merge
Type: Optimisation
Type: Question
Type: Removal
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
Mrcoolgamer11/Red-DiscordBot!2421
No description provided.