-
Notifications
You must be signed in to change notification settings - Fork 193
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add CLI, add version to hash for invalidation in case of new features (…
…#54) * Add CLI, add version to hash for invalidation in case of new features * Pay attention to py2
- Loading branch information
Showing
9 changed files
with
108 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#!/usr/bin/env python | ||
|
||
from slackviewer.cli import cli | ||
|
||
if __name__ == '__main__': | ||
cli() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import click | ||
import shutil | ||
|
||
from slackviewer.constants import SLACKVIEWER_TEMP_PATH | ||
from slackviewer.utils.click import envvar, flag_ennvar | ||
|
||
|
||
@click.group() | ||
def cli(): | ||
pass | ||
|
||
|
||
@cli.command(help="Cleans up any temporary files (including cached output by slack-export-viewer)") | ||
@click.option("--wet", "-w", is_flag=True, | ||
default=flag_ennvar("SEV_CLEAN_WET"), | ||
help="Actually performs file deletion") | ||
def clean(wet): | ||
if wet: | ||
print("Removing {}...".format(SLACKVIEWER_TEMP_PATH)) | ||
shutil.rmtree(SLACKVIEWER_TEMP_PATH) | ||
else: | ||
print("Run with -w to remove {}".format(SLACKVIEWER_TEMP_PATH)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import tempfile | ||
import os | ||
|
||
SLACKVIEWER_TEMP_PATH = os.path.join(tempfile.gettempdir(), "_slackviewer") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import os | ||
|
||
|
||
def envvar(name, default): | ||
"""Create callable environment variable getter | ||
:param str name: Name of environment variable | ||
:param default: Default value to return in case it isn't defined | ||
""" | ||
return lambda: os.environ.get(name, default) | ||
|
||
|
||
def flag_ennvar(name): | ||
return os.environ.get(name) == '1' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
"""Poor man's version Six""" | ||
|
||
import sys | ||
|
||
|
||
PY_VERSION = sys.version_info[0] | ||
|
||
|
||
def to_unicode(s): | ||
"""Convert str s to unicode | ||
:param str s: string | ||
:return: "unicode" version of s (unicode in py2, str in py3) | ||
""" | ||
if PY_VERSION == 2: | ||
s = unicode(s) | ||
|
||
return s | ||
|
||
|
||
def to_bytes(s, encoding="utf8"): | ||
"""Converts str s to bytes""" | ||
if PY_VERSION == 2: | ||
b = bytes(s) | ||
elif PY_VERSION == 3: | ||
b = bytes(s, encoding) | ||
else: | ||
raise ValueError("Is Python 4 out already?") | ||
|
||
return b |