This commit is contained in:
kendfss 2021-08-12 20:12:42 +01:00
parent b6dce7d47b
commit 65d9244cab
3 changed files with 131 additions and 38 deletions

View File

@ -1,35 +1,74 @@
from subprocess import run, Popen
from time import sleep
from typing import Dict, List, Callable
import inspect, os, platform, re, sys, warnings
from itertools import permutations
import inspect, os, platform, re, sys, warnings, math
from pyperclip import copy, paste
from sl4ng import show, getsource, pop, unzip, main, join, regenerator, kill, kbd
from filey import Thing, Place, File, Scanner, Library, mcd, search_iter, ffplay, convert
import sl4ng
from sl4ng import show, getsource, pop, unzip, main, join, regenerator, kill, kbd, splitall
from filey import Thing, Place, File, Scanner, Library, mcd, search_iter, ffplay, convert, forbiddens
import sl4ng, filey
arch = platform.architecture()
this = __file__
here = os.path.dirname(__file__)
pwd = Place(os.getcwd())
ff = lambda: ffplay(paste(), loop=0)
rm = lambda: os.remove(paste())
smp = lambda: os.rename(paste(), os.path.join("samples", paste()))
unix = lambda path: copy(f"/mnt/{path}".replace(':','').replace('\\','/').lower())
def unix(path=None):
path = path if isinstance(path, str) and os.path.exists(path) else paste()
path = (f"/mnt/{path}").replace(':','').replace('\\','/').lower()
copy(path)
print(path)
architecture = platform.architecture()
def clear():
def pp():
[*map(pop, paste().splitlines())]
def pt():
pop(this)
def rp():
[*map(os.remove, paste().splitlines())]
def fname():
copy("".join(splitall(forbiddens+'.', paste())).strip().replace(' ', '_'))
def diffs(adjacent:bool=False):
unix = lambda path: f"/mnt/{path}".replace(':','').replace('\\','/').lower()
lines = paste().splitlines()
cmd = 'diff --text %s {} | aplay' % ("-y " if adjacent else "")
for i, (one, two) in enumerate(permutations(lines, 2)):
args = f'"{unix(one)}" "{unix(two)}"'
print(cmd.format(args))
copy(cmd.format(args))
if i < math.factorial(len(lines)):
input("press enter to continue")
def qmap(func, itr, ex=lambda *args: None):
for i in itr:
try:
yield func(i)
except:
yield ex(i)
def clear() -> None:
Popen('clear')
sleep(.2)
def cls():
def cls() -> None:
clear()
show(map(repr, cd), head=False, tail=False)
def cd(path):
def cd(path:str=None) -> None:
global pwd
if isinstance(path, type(None)):
path = os.getcwd()
os.chdir(path)
pwd.path = path
def killfl():
def killfl() -> None:
kill('fl64')
kill('ilbridge')
def exp(power, base=2):
return f"{pow(base, power):,}"
escaped = tuple(i for i in kbd() if re.escape(i) != i)
def functions(module):
@ -47,8 +86,8 @@ root = c if c.exists else None
appdata = user/'appdata'
downs = downloads = user / 'Downloads'
tools = downs / 'tools'
langs = downs / 'tools/languages' # need library class
tools = Place('f:/tools')
langs = tools / 'languages' # need library class
gosrc = Place(r'C:\Program Files\Go\src')
web = Library(
langs['css'],
@ -57,47 +96,61 @@ web = Library(
langs.up['web'],
r"E:\Projects\web\jayess",
)
golang = langs / "golang"
python = langs / "python"
dev = Place(r"e:/")
sp = dev / 'shellpower'
gitting = dev / 'gitting'
git = downs / "tools/git"
git = tools / "git"
clones = gitting/'gitclone/clones'
ignore = clones / 'github/gitignore'
mdn = gitting / r'gitclone\clones\mdn\content\files\en-us'
brython = gitting / r'gitclone\clones\brython-dev\brython\www\doc\en'
kendfss = clones['kendfss']
# processing = clones / "processing" Library(
processing = Library(
clones/"processing/processing-docs",
clones/"processing/processing-doclet",
langs/"processing",
langs/"java",
)
processes = Place(r"F:\Visuals\processes")
def igpy(path):
def igpy(path:str=None) -> None:
"""
Add a python .gitignore file to the given path
"""
home = pwd.path
mode = "a" if '.gitignore' in os.listdir(path) else "w"
os.chdir(path)
origin = pwd.path
os.chdir(paste() if isinstance(path, type(None)) else path)
mode = "a" if '.gitignore' in os.listdir() else "w"
with open('.gitignore', mode) as fob:
pig = File(r"E:\gitting\gitclone\clones\github\gitignore\Python.gitignore").cat()
fob.write(f'\n{pig}')
os.chdir(home)
header = "# Python\n"*3
header = "\n" + header if mode=="a" else header
fob.write(f'{header}\n{pig}')
os.chdir(origin)
def iggo(path):
def iggo(path:str=None) -> None:
"""
Add a golang .gitignore file to the given path
"""
home = pwd.path
mode = "a" if '.gitignore' in os.listdir(path) else "w"
os.chdir(path)
origin = pwd.path
os.chdir(paste() if isinstance(path, type(None)) else path)
mode = "a" if '.gitignore' in os.listdir() else "w"
with open('.gitignore', mode) as fob:
pig = File(r"E:\gitting\gitclone\clones\github\gitignore\Go.gitignore").cat()
fob.write(f'\n{pig}')
os.chdir(home)
header = "# Golang\n"*3
header = "\n" + header if mode=="a" else header
fob.write(f'{header}\n{pig}')
os.chdir(origin)
projects = dev / 'projects'
monties = projects / 'monties'
site = dev / 'Languages\Python38-64\lib'
site = dev / 'Languages/Python38-64/lib'
docs = monties / 'docs'
prod = Place(r'f:/')

View File

@ -2,16 +2,18 @@
<!-- ![](https://live.staticflickr.com/6049/6323682453_f58f16b56b_w_d.jpg "credit to Nick Shillingford") -->
<!-- <center><img src="https://live.staticflickr.com/6049/6323682453_f58f16b56b_w_d.jpg" ...></center> -->
CNS (Central Nervous System) is REPL for pythonic file system management and navigation.
It essentially bundles relevant aspects of [filey](https://github.com/kendfss/filey) and [sl4ng](https://github.com/kendfss/sl4ng) into a shell-like environment.
CNS (Central Nervous System) is a productivity oriented python environment which offers a REPL for file system management and navigation.
<!-- It essentially bundles relevant aspects of [filey](https://github.com/kendfss/filey) and [sl4ng](https://github.com/kendfss/sl4ng) into a shell-like environment with some additional offerings built on the standard library. -->
It essentially bundles relevant aspects of [filey](../filey) and [sl4ng](../sl4ng) into a shell-like environment with some additional offerings built on the standard library.
You can customize it to fit your system/workflow by editing the [env](./cns/env.py) file.
**why?** because you're worth it. It's usually faster than searching with windows on my miserably old setup. having everything handy makes it faster to control search specificity
**why?** because you're worth it. But also, I don't have internet access from my main station so I tend to use a lot of offline documentation/screencaps as reference material. But also, as cool as Pathlib is, the lack of search-ability (excluding grep - which isn't ideal for newbs, or particularly thorough) makes it a sub-optimal tool for the use cases laid out below.
[**how?**](#usage)
### Usage
##### Start
This starts the REPL which *-imports all of the contents from the [env](./cns/env.py) file.
```shell
$ cns
```
@ -22,17 +24,55 @@ $ cns
Place(name=System32, dir=Windows)
>>> cd(os.path.expanduser('~'))
>>> pwd
Place(name=Me, dir=User)
Place(name=Me, dir=Users)
>>> downloads = Place('~') / "downloads" # accesible as "downs" in the REPL
```
##### Linear Search
By default, searches only look for files, but you can see the techniques for directory finding [here](#directory)
```python
>>> show(downloads("name of that documentation file i seem to have misplaced/lost the will to look for manually", exts='pdf md htm'))
search result #1.pdf
search result #2.pdf
>>> show(downloads("term1 term2 term3 ... termN", exts='pdf md htm'))
search_result_1.md
search_result_2.htm
...
search result #n
search_result_n.pdf
```
##### Threaded Search
```python
>>> show(downloads("term1 term2 term3 ... termN", threads=3)) # defaults to zero
search_result_1.ext
search_result_2.ext
...
search_result_n.ext
```
##### Depth-restricted Search
This constrains the search to a given depth of directory. Any argument lower than zero goes as deeply as possible.
The following indicates how only look in space corresponding to `os.listdir(downloads.path)`
```python
>>> show(downloads("term1 term2 term3 ... termN", depth=0)) # defaults to zero
```
### Examples
##### Scanning Source Files for useful info
```python
>>> show(filter(filey.Scanner("File) Read(", case=True), filey.files(r"C:\Program Files\Go\src")))
C:\Program Files\Go\src\cmd\pack\pack_test.go
C:\Program Files\Go\src\net\http\fs.go
C:\Program Files\Go\src\os\file.go
C:\Program Files\Go\src\runtime\race\testdata\mop_test.go
C:\Program Files\Go\src\testing\fstest\mapfs.go
```
- First one did the trick :wink:
### Change Log
**v 1.0.1**
- Adds
- threaded searching
- depth-controlled searching
- globbing to Places
- filey.files to repl

View File

@ -6,12 +6,12 @@ with open('requirements.txt', 'r') as fob:
requirements = fob.readlines()
setup(
name='cns',
name='ff',
version='1.0.0',
author='Kenneth Sabalo',
author_email='kennethsantanasablo@gmail.com',
url='https://github.com/kendfss/cns',
description="REPL for pythonic file system management and navigation",
description="A repl interface to FFMPEG's FFPlay",
packages=find_packages(),
classifiers=[
"Programming Language :: Python :: 3",
@ -25,7 +25,7 @@ setup(
requires=requirements,
entry_points={
'console_scripts': [
'cns = cns.cli:main'
'ff = ff.cli:main'
]
},
python_requires='>=3.10',