Comments (1)
Offering for fix to numeric file/directory names. Also, adds file_age function.
For README.md:
filesize :: Path → Int
file_size :: Path → Int
fileage :: Path → Int
file_age :: Path → Int
For ft/ft/functions.py:
@register("basename")
@typed(None, T_PATH)
def basename(inp):
if type(inp) == list:
panic("'{}' cannot take an array as input. Use the command's '--column' option.".format(inspect.stack()[0][3]))
if type(inp) not in (str, int):
panic("Incompatible input type to '{}': expected 'str', got '{}'".format(inspect.stack()[0][3], type(inp).__name__))
return os.path.basename(str(inp))
@register("abspath")
@typed(None, T_PATH)
def abspath(inp):
if type(inp) == list:
panic("'{}' cannot take an array as input. Use the command's '--column' option.".format(inspect.stack()[0][3]))
if type(inp) not in (str, int):
panic("Incompatible input type to '{}': expected 'str', got '{}'".format(inspect.stack()[0][3], type(inp).__name__))
return os.path.abspath(str(inp))
@register("filesize", "file_size")
@typed(None, T_INT)
def filesize(inp):
if type(inp) == list:
panic("'{}' cannot take an array as input. Use the command's '--column' option.".format(inspect.stack()[0][3]))
if type(inp) not in (str, int):
panic("Incompatible input type to '{}': expected 'str', got '{}'".format(inspect.stack()[0][3], type(inp).__name__))
return os.path.getsize(str(inp))
@register("fileage", "file_age")
@typed(None, T_INT)
def fileage(inp):
if type(inp) == list:
panic("'{}' cannot take an array as input. Use the command's '--column' option.".format(inspect.stack()[0][3]))
if type(inp) not in (str, int):
panic("Incompatible input type to '{}': expected 'str', got '{}'".format(inspect.stack()[0][3], type(inp).__name__))
return int(os.path.getmtime(str(inp)))
@register("file_ext")
@typed(None, T_STRING)
def file_ext(inp):
if type(inp) == list:
panic("'{}' cannot take an array as input. Use the command's '--column' option.".format(inspect.stack()[0][3]))
if type(inp) not in (str, int):
panic("Incompatible input type to '{}': expected 'str', got '{}'".format(inspect.stack()[0][3], type(inp).__name__))
return os.path.splitext(str(inp))[1]
@register("dirname")
@typed(None, T_PATH)
def dirname(inp):
if type(inp) == list:
panic("'{}' cannot take an array as input. Use the command's '--column' option.".format(inspect.stack()[0][3]))
if type(inp) not in (str, int):
panic("Incompatible input type to '{}': expected 'str', got '{}'".format(inspect.stack()[0][3], type(inp).__name__))
return os.path.dirname(str(inp))
@register("replace_ext")
@typed(None, T_PATH)
def replace_ext(new_ext, inp):
if type(inp) == list:
panic("'{}' cannot take an array as input. Use the command's '--column' option.".format(inspect.stack()[0][3]))
if type(inp) not in (str, int):
panic("Incompatible input type to '{}': expected 'str', got '{}'".format(inspect.stack()[0][3], type(inp).__name__))
new_ext = dynamic_cast(T_STRING, new_ext).value
(base, ext) = os.path.splitext(str(inp))
if ext != "":
return base + "." + new_ext
return inp
@register("strip_ext")
@typed(None, T_STRING)
def strip_ext(inp):
if type(inp) == list:
panic("'{}' cannot take an array as input. Use the command's '--column' option.".format(inspect.stack()[0][3]))
if type(inp) not in (str, int):
panic("Incompatible input type to '{}': expected 'str', got '{}'".format(inspect.stack()[0][3], type(inp).__name__))
return os.path.splitext(str(inp))[0]
@register("has_ext")
@typed(None, T_BOOL)
def has_ext(ext, inp):
if type(inp) == list:
panic("'{}' cannot take an array as input. Use the command's '--column' option.".format(inspect.stack()[0][3]))
if type(inp) not in (str, int):
panic("Incompatible input type to '{}': expected 'str', got '{}'".format(inspect.stack()[0][3], type(inp).__name__))
ext = dynamic_cast(T_STRING, ext).value
(_, file_ext) = os.path.splitext(str(inp))
file_ext = file_ext[1:] # strip leading dot
return file_ext == ext
@register("split_ext")
@typed(None, T_ARRAY)
def split_ext(inp):
if type(inp) == list:
panic("'{}' cannot take an array as input. Use the command's '--column' option.".format(inspect.stack()[0][3]))
if type(inp) not in (str, int):
panic("Incompatible input type to '{}': expected 'str', got '{}'".format(inspect.stack()[0][3], type(inp).__name__))
parts = os.path.splitext(str(inp))
return [TypedValue(parts[0], T_STRING), TypedValue(parts[1][1:], T_STRING)]
@register("exists")
@typed(None, T_BOOL)
def exists(inp):
if type(inp) == list:
panic("'{}' cannot take an array as input. Use the command's '--column' option.".format(inspect.stack()[0][3]))
if type(inp) not in (str, int):
panic("Incompatible input type to '{}': expected 'str', got '{}'".format(inspect.stack()[0][3], type(inp).__name__))
return os.path.exists(str(inp))
@register("is_dir")
@typed(None, T_BOOL)
def is_dir(inp):
if type(inp) == list:
panic("'{}' cannot take an array as input. Use the command's '--column' option.".format(inspect.stack()[0][3]))
if type(inp) not in (str, int):
panic("Incompatible input type to '{}': expected 'str', got '{}'".format(inspect.stack()[0][3], type(inp).__name__))
return os.path.isdir(str(inp))
@register("is_file")
@typed(None, T_BOOL)
def is_file(inp):
if type(inp) == list:
panic("'{}' cannot take an array as input. Use the command's '--column' option.".format(inspect.stack()[0][3]))
if type(inp) not in (str, int):
panic("Incompatible input type to '{}': expected 'str', got '{}'".format(inspect.stack()[0][3], type(inp).__name__))
return os.path.isfile(str(inp))
@register("is_link")
@typed(None, T_BOOL)
def is_link(inp):
if type(inp) == list:
panic("'{}' cannot take an array as input. Use the command's '--column' option.".format(inspect.stack()[0][3]))
if type(inp) not in (str, int):
panic("Incompatible input type to '{}': expected 'str', got '{}'".format(inspect.stack()[0][3], type(inp).__name__))
return os.path.islink(str(inp))
@register("is_executable")
@typed(None, T_BOOL)
def is_executable(inp):
if type(inp) == list:
panic("'{}' cannot take an array as input. Use the command's '--column' option.".format(inspect.stack()[0][3]))
if type(inp) not in (str, int):
panic("Incompatible input type to '{}': expected 'str', got '{}'".format(inspect.stack()[0][3], type(inp).__name__))
return os.path.isfile(str(inp)) and os.access(str(inp), os.X_OK)
from shell-functools.
Related Issues (20)
- Add take_while command
- Add shell-completion for available function names HOT 3
- Support for 'flip' HOT 2
- Commands not installed HOT 3
- Problem installing in Python3.6 env HOT 3
- Support for rename operations HOT 1
- Numeric file name HOT 1
- Custom functions HOT 3
- Installation error with pip3 HOT 6
- Predicates negation HOT 2
- filtering in a stream doesn't work as expected HOT 7
- Issues with filename consist of only numbers like '123' HOT 1
- is_link does not detect links HOT 4
- Arrays with ints is broken HOT 1
- Offering: Desending sort_by HOT 1
- Offering: Update the `run` function to allow for command line arguments HOT 1
- Offering: Add array support to `format` function HOT 1
- Offering: Allow `join` function to work on a single column HOT 1
- Maintenance status of this project HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from shell-functools.