fancytools.os package

Submodules

fancytools.os.PathStr module

class fancytools.os.PathStr.PathStr[source]

Bases: str

easy path-string handling and manipulation using os.path and shutil

Windows only: there is no need of transforming to - it will be done automatically when a PathStr instance is created

>>> p = PathStr.home()
>>> print p.isdir()
True
>>> print p.exists()
True
>>> d_list = [p.join(x) for x in p.listdir()]
abspath()[source]
all()[source]

Return a list of all files within this folder

basename()[source]
copy(dst)[source]
dirname()[source]
exists()[source]

return whether PathStr instance exists as a file/folder

files(ftype=None)[source]

return a first of path to all files within that folder

filetype()[source]
static getcwd(moduleName=None)[source]

get current path either from the temp folder used by pyinstaller:

  • apps ‘sys._MEIPASS’ if packed with –onefile option

or

  • os.getcwd()
static home()[source]

return the home/user directory

isdir()[source]
isfile()[source]
join(*args)[source]

add a file/name to this PathStr instance

listdir()[source]
load(size)[source]

open and read the file is existent

mkdir(dname=None)[source]
move(dst)[source]

move this file/folder the [dst]

remove(name=None)[source]
rename(new_file_name)[source]
setFiletype(ftype)[source]
fancytools.os.PathStr.raw(text)[source]

Returns a raw string representation of text

fancytools.os.StartMenuEntry module

class fancytools.os.StartMenuEntry.StartMenuEntry(name, target, **kwargs)[source]

Bases: object

this class creates a shortcut for a given target in the start menu of the used os depending either system wide or user specific

kwargs description
icon [path of the program icon]
directory [start dir of the program],
version [version number]
description [of the program]
console False -> hide console (only GUI applications)
categories e.g. “Application;Science;Graphics;Office;” # Linux only
>>> entry = StartMenuEntry('myLittleTest', 'www.python.org')
>>> entry.create()

Now look for the entry in your start menu

>>> entry.remove()

fancytools.os.assignFtypeToPyFile module

fancytools.os.assignFtypeToPyFile.assignFtypeToPyFile(extension, args=(), mimetype=None, showTerminal=True)[source]

Connect a file extension to a python script

Example: We created a python file that can open ‘.da’ files The command we need to execute to open that is is: ‘python MY_PYTH_FILE.py -o MY_DA_FILE.da’

To be able to open these files with a simple double click run:

openExtensionWith(extension=’da’, args=(‘MY_PYTH_FILE.py’, ‘-o’))

OPTIONAL ARGUMENTS: args -> (...) additional arguments to be added after the pyFile

mimetype (str) -> assign a MIMETYPE name to your file extension
e.g. ‘daFile’

showTerminal (bool) -> True: open your program in a terminal

fancytools.os.copyTree module

fancytools.os.copyTree.copyTree(src, dst, symlinks=False, ignore=None)[source]

copy one dir-tree into another combine dirs of the same name replacing files of same name

fancytools.os.countLines module

fancytools.os.countLines.countLines(filename, buf_size=1048576)[source]

fast counting to the lines of a given filename through only reading out a limited buffer

fancytools.os.isAdmin module

fancytools.os.isAdmin.isAdmin()[source]

return True is current os user is administrator

fancytools.os.legalizeFilename module

fancytools.os.legalizeFilename.legalizeFilename(filename)[source]

fancytools.os.runAsAdmin module

fancytools.os.runAsAdmin.runAsAdmin(cmdLine=None, target_dir='', wait=True)[source]

run [cmdLine] as admin specify the location from where the code is executed through [target_dir]

fancytools.os.setup module

fancytools.os.setup.setup(package)[source]

a template for the python setup.py installer routine

  • take setup information from the packages __init__.py file
    • this way these informations, like...
      • __email__
      • __version__
      • __depencies__

      are still available after installation

  • exclude /tests*

  • create scripts from all files in /bin

  • create the long description from
    • /README.rst
    • /CHANGES.rst
    • /AUTHORS.rst
  • remove /build at the end

fancytools.os.userName module

fancytools.os.userName.userName()[source]

return the user-name of the current user