{ "info": { "author": "hayj", "author_email": "hj@hayj.fr", "bugtrack_url": null, "classifiers": [ "Development Status :: 1 - Planning", "License :: OSI Approved :: MIT License", "Natural Language :: English", "Operating System :: OS Independent", "Programming Language :: Python", "Programming Language :: Python :: 3.6", "Topic :: Utilities" ], "description": "\nSystemTools\n===========\n\nThis project gathers some useful Python functions and classes. We organized them in different modules:\n\n\n* **systemtools.duration**\n* **systemtools.logger**\n* **systemtools.location**\n* **systemtools.basics**\n* **systemtools.number**\n* **systemtools.file**\n* **systemtools.system**\n\nTo install all:\n\n.. code-block::\n\n pip install systools\n\n\n\nsystemtools.printer\n-------------------\n\nThis module provide function that beautiful print variables.\n\n.. code-block::\n\n >>> from systemtools.printer import *\n >>> bp(['Some text lorem ipsum dolor sit amet', {'a': 'This is some text that is short.', 'b': 'This is a longer text lorem ipsum dolor sit amet lorem ipsum dolor sit amet lorem ipsum dolor sit amet.'}, 'Here an other text', 8, 9, [2, 3, 4, 5], 10, {1, 2, 3}])\n [\n Some text lorem ipsum dolor sit amet,\n {\n a: This is some text that is short.,\n b: This is a longer text lorem ipsum dolor sit amet lorem ipsum dolor sit amet lorem ipsum dolor sit am\n },\n ...,\n 10,\n { 1, 2, 3 }\n ]\n\n\nYou level as second argument (from 0 to 5) to set the verbosity of the print.\n\nsystemtools.duration\n--------------------\n\nThis module provide some useful class to handle time.\n\n.. code-block::\n\n >>> from systemtools.duration import *\n\n\nTicToc\n^^^^^^\n\nThis class allow an easy print of computation time in your scripts:\n\n.. code-block::\n\n >>> tt = TicToc()\n >>> tt.tic() # Start the timer\n >>> \n >>> tt.tic() # Print the time duration (human readable) since the previous tic()\n tic: 1s\n >>> \n >>> tt.tic()\n tic: 1s\n >>> tt.toc() # Print the total duration\n\ntoc total duration: 2s\n\nYou can give ``msg`` parameter to add a message to the printed duration. You can also choose to do not display anything using ``display=False``.\n\nBoth ``tic`` and ``toc`` methods return the time spent in seconds.\n\nProgressBar\n^^^^^^^^^^^\n\nA light alternative to `tqdm `_. Just wrap your iterables with the ``pb`` funct:\n\n.. code-block:: python\n\n for i in pb(range(iterationAmount)):\n time.sleep(0.01)\n\nThis will display:\n\n.. code-block::\n\n 0% [ ]\n 20% [==== ] (1.6s left)\n 40% [======== ] (1.214s left)\n 60% [============ ] (0.813s left)\n 80% [================ ] (0.404s left)\n 100% [====================] (total duration: 2.03s, mean duration: 0.01s)\n\n\nBy default, ``pb`` will **not** display more than 10 messages to do not display too much progress informations in the case you used the ``nohup`` command, or used a ``Logger`` for example.\n\n``pb`` take same parameters as the ``ProgressBar`` class init parameters. You can use the class directly to handle your progress bar by hand giving an iteration amount and by calling the ``tic()`` method at each iteration:\n\n.. code-block:: python\n\n iterationAmount = 200\n pb = ProgressBar(iterationAmount)\n for i in range(iterationAmount):\n time.sleep(0.01)\n pb.tic(i) # Give a message to the `tic` method to display informations about the current iteration\n\nIf you work on a terminal, it will automatically display informations more frenquently and replace the current line.\n\nInit parameters are (\\ `see the code for more information `_\\ ):\n\n\n* **message**\\ : will display this message at each ``tic()``\n* **printRatio**\\ : display a message at each ``printRatio * iterationAmount`` times you call ``tic()``. Default is 0.1, meaning it will display 10%, 20%...\n\n``tic()`` parameters are:\n\n\n* **extraMessage**\\ : use this message if you want to display informations about the current iteration. \n\n*Tested in Python 3 on Ubuntu.*\n\nTimer\n^^^^^\n\nThis class call a function each n seconds:\n\n.. code-block::\n\n >>> timer = Timer(myFunct, 5)\n >>> timer.start()\n\n\n\nYou can stop it using:\n\n.. code-block::\n\n >>> timer.stop()\n\n\nSet ``sleepFirst=True`` if you don't want to call your funct at the startup of the timer.\n\nsystemtools.logger\n------------------\n\nA Logger class is a wrapper over ``logging``.\n\n.. code-block::\n\n >>> from systemtools.logger import *\n >>> logger = Logger(\"test.log\") # Give a file path\n >>> logger.info(\"a\") # Print infos\n >>> logger.error(\"b\") # Print errors...\n\n\nIf you created a class which contains ``logger`` and ``verbose`` like this one:\n\n.. code-block::\n\n >>> class LoggerTest:\n ... def __init__(self, logger=None, verbose=True):\n ... self.logger = logger\n ... self.verbose = verbose\n\n\nAnd use functions ``log``\\ , ``logError``... this way in a method of your class:\n\n ... log(\"Initialized....\", self)\n\n\nSo the log function will automaticllay check if verbose is True, and if there is no ``logger``\\ , it will simply print your message.\n\nYou can also use ``logException`` this way:\n\n ... logException(e, self) # You can give message (string) and location (string) parameters\n\n\nYou can also give a ``Logger`` instead of a class instance:\n\n.. code-block::\n\n >>> log(\"a\", logger)\n >>> logException(e, logger, verbose=myVerbose)\n >>> ...\n\n\nsystemtools.location\n--------------------\n\nThis module gathers some useful functions on file system location.\n\n.. code-block::\n\n >>> from systemtools.location import *\n\n\n\n* **sortedGlob(regex, caseSensitive=True, sortBy=GlobSortEnum.NAME, reverse=False)**\\ : This function works the same as glob.glob but return an ordered list of files path. glob.glob return (by default) a ordered list which can change across OS or executions and it is prone to errors in your python script. You can use different orders via sortBy: GlobSortEnum. the last one is the same as name but take into account numbers (e.g. test1.txt < test10.txt).\n* **homeDir()** : Return the path of your home dir.\n* **tmpDir(\\ *file*\\ =None, subDir=None)**\\ : Return the path of the tmp dir, If you give ``__file__`` in first param, the tmp dir will be \"tmp\" in the current directory, else it will be ~/tmp. You can set ``subDir`` in parameters.\n* **execDir(\\ *file*\\ =None)**\\ : Get the current directory, it is better to give ``__file__`` in parameter to be sure to get the dir of the current Python script.\n* **isDir(path)**\\ : Return True is the given path is a directory.\n* **isFile(path)**\\ : Return True is the given path is a file.\n* **decomposePath(path)**\\ : Return a tuple (dir, filename, ext, filenameAndExt) of a path.\n\nYou can set the default tmp directory:\n\n.. code-block:: python\n\n from systemtools import config as systConf\n systConf.defaultTmpDir = \"/your/tmp/directory\"\n\nsystemtools.basics\n------------------\n\nThis module gathers some useful basics functions.\n\n.. code-block::\n\n >>> from systemtools.basics import *\n\n\n\n* **listSubstract(a, b)**\\ : Substract all ``b`` items from ``a``.\n* **convertDate(readableDate=None, dateFormat=DATE_FORMAT.datetime)**\\ : Convert a readable date (wrote by a human) in a date format you chose. Warning : utc shift may appear. DATE_FORMAT enum contains \"datetimeString datetime timestamp arrow arrowString humanize\".\n\n * **mergeDicts(dict1, ...)**\\ : shallow copy of all dict and merge into a new dict\n * **reduceDictStr**\\ : See the code for parameters. Reduce all strings of a dict in order to print it.\n * **stripAccents(text)**\\ : Remove all accents of a string.\n * **printLTS(l)**\\ : Pretty print a list or a dict. Use ``listToStr`` internally.\n * **listToStr(l)**\\ : Convert a list or a dict to a pretty string.\n * **floatAsReadable**\\ : Convert a float to a readable string without \"e-X\".\n * **sortByKey(d)**\\ : Sort a dict by the key. Return an ``OrderedDict``.\n * **sortBy(l, desc=False, index=1)**\\ : Sort a list of tuple (or an itemized dict) by the specific index given in parameters.\n * **chunks(l, n)**\\ : return a list of list (of len n) from ``l``. You can also use ``chunksYielder``.\n * **split(l, n)**\\ : split a list in n parts.\n * **splitMaxSized(l, batchMaxSize)**\\ : Split a list in multiple parts in such a way that each part has a max size of batchMaxSize.\n * **normalize(l)**\\ : Normalize (between 0.0 and 1.0) all elements of a list according to the sum of all elements.\n * **getRandomInt(a=None, b=None, seed=None, count=1)**\\ : Return a random int between ``a`` and ``b``.\n * **getRandomFloat(min=0.0, max=1.0, decimalMax=2)**\\ : Return a random float between ``min`` and ``max``.\n * **getRandomStr(digitCount=10, withTimestamp=True)**\\ : Return a random string with a timestamp if enabled.\n * **getRandomName(addInt=True, maxInt=100)**\\ : Return a random name with a random int.\n * **Random class**\\ : This class is useful when you want to seed random values and reset it after the class usage. See the code for more informations.\n * **dictContains(d, key)**\\ : Equivalent to ``key in d and d[key] is not None``.\n * **intersection(lists)**\\ : Return the intersection of all lists.\n * **reduceStr**\\ : Reduce a str, you can set booleans removeNumbers, toLowerCase, removeAccents and removePunct.\n * **varname(p)**\\ : Return the name of p from the Python script.\n * **stripAllLines(text, removeBlank=True)**\\ : Return the text but strip all lines.\n * **byteToStr(b)**\\ : Convert bytes to str.\n * **getDictSubElement(theDict, keys)**\\ : This function browse the dict as a tree and return the value in the path defined by keys which is a list of dict keys. It return None if it doesn't find anything. Example: ``getDictSubElement({'a': {'b': 1}}, ['a', 'b'])`` return ``1``.\n * **objectAsKey(o)**\\ : Convert any object to a key, if if instead call ``str(o)`` or ``repr(o)``\\ , the string can change over executions of your script due to the unordered nature of dictionnaries and sets.\n * **reducedLTS(o, amount=25)**\\ : Same as ``lts(o)`` but keep only ``amount`` elements at the head and the tail of the object if it is a list.\n * **reduceBlank(text, keepNewLines=False) (aslias stripAll, trimAll)**\\ : Strip a string and reduce all blank space to a unique space. If you set keepNewLines as True, it will keep a unique '\\n' at each blank space which contains a '\\n' or a '\\r'.\n * **linearScore(x, x1=0.0, x2=1.0, y1=0.0, y2=1.0, stayBetween0And1=True)**\\ : Give you a score f(x) defined by the linear function line (x1, y1) (x2, y2).\n * **camelCaseToUnderscoreCase(name)**\\ : Convert a string which is formatted as the camelCase norm to the underscore_case norm.\n * **camelCaseToUnderscoreCaseDict(theDict)**\\ : Turn each key of the dict according to ``camelCaseToUnderscoreCase``.\n * **tuplesToDict(tupleList)**\\ : Convert a list of tuples to a dict in such a way that the first element of each tuple will be the key.\n * **findDuplicates(texts, strip=True)**\\ : Return a list a duplicates (indexes of texts in th list).\n * **intByteSize(n)**\\ : Return the size of an integer in bytes.\n\nsystemtools.number\n------------------\n\nThis module gathers some useful basics functions on number parsing.\n\n.. code-block::\n\n >>> from systemtools.number import *\n\n\n\n* **parseNumber(text)**\\ : Return the first number in the given text for any locale.\n* **getAllNumbers(text, removeCommas=False)**\\ : Return all numbers in a string. You can also use ``getFirstNumber``.\n* **getFirstNumber(text)**\\ : Get the first numbers of a string.\n* **removeAllNumbers(text)**\\ : Remove all numbers from a string.\n* **truncateFloat(f, n)**\\ : Truncates/pads a float f to n decimal places without rounding.\n\nsystemtools.file\n----------------\n\nThis module gathers some useful functions on file and directories management.\n\n.. code-block::\n\n >>> from systemtools.file import *\n\n\n\n* **getLastModifiedTimeSpent(path, timeSpentUnit=TIMESPENT_UNIT.HOURS)**\\ : Return the time spent after the last modified event on a path (file or directory).\n* **strToFilename(text)**\\ : Convert a string in a filename (storable on the disk). So it will remove all non permitted chars.\n* **mkdir(path)**\\ : Create a directory if it doesn't already exist.\n* **globRemove(globPattern)**\\ : Remove file according to a glob pattern similar to the glob lib.\n* **removeFile(path)**\\ : Remove a file or a list of files.\n* **fileToStr(path)**\\ : Load a file and return the string in.\n* **fileToStrList**\\ : Load a file and return a list of strings. You can set ``strip`` as ``False`` to don't strip all lines, ``skipBlank`` as ``False`` to keep blank lines, you can choose your comment start indicator using ``commentStart`` (default is \"###\").\n* **strToFile(text, path)**\\ : Store a string in a file.\n* **strToTmpFile(text, name=None, ext=\"\", addRandomStr=False)**\\ : Store a string to a tmp file (using ``tmpDir`` function). Example: strToTmpFile(\"a\", \"test.txt\").\n* **strListToTmpFile**\\ : Use ``strToTmpFile`` but for a list of strings which is concatened.\n* **normalizeNumericalFilePaths(globRegex)**\\ : This function get a glob path and rename all \"file1.json\", \"file2.json\"... \"file20.json\" to \"file01.json\", \"file02.json\"... \"file20.json\" to better sort the folder by file names.\n* **encryptFile(path, key, text=None, remove=True)**\\ : This function encrypt a file, if you give text in ``text`` parameter, the function will create the file. Return True if all is ok. You need to install 7zip using ``sudo apt-get install p7zip-full`` on Linux. Set remove as ``False`` if you don't want to remove the decrypted file.\n* **decryptFile(path, key, remove=True)**\\ : This function decrypt a file and return the text. Set remove as ``False`` if you don't want to remove the encrypted file.\n\nsystemtools.system\n------------------\n\nThis module gathers some useful functions on the OS management.\n\n.. code-block::\n\n >>> from systemtools.system import *\n\n\n\n* **getUsedPorts()**\\ : Return all busy ports on your machine (works on Linux using netstat).\n* **getUser()**\\ : Equivalent to ``getpass.getuser()``\n* **setCallTimeout(timeout) and resetCallTimeout()**\\ : Use ``setCallTimeout`` to set a timeout before calling a function (so you can catch an Exception if the function is too long), then reset the timeout.\n* **getRAMTotal()**\\ : Return the amount of RAM in Go\n* **cpuCount()**\\ : Equivalent to ``multiprocessing.cpu_count()``\n* **isHostname(h)**\\ : Return ``True`` if the hostname of the current computer starts with ``h``.\n* **getHostname()**\\ : Equivalent to ``socket.gethostname()``\n* **randomSleep(min=0.1, max=None)**\\ : Sleep between min and max. If max is None: max = min + 0.2 * min.\n* **getMemoryPercent()**\\ : Return the % of memory usage.\n", "description_content_type": "", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "", "keywords": "", "license": "", "maintainer": "", "maintainer_email": "", "name": "systools", "package_url": "https://pypi.org/project/systools/", "platform": "", "project_url": "https://pypi.org/project/systools/", "project_urls": null, "release_url": "https://pypi.org/project/systools/0.0.93/", "requires_dist": null, "requires_python": "", "summary": "This project gathers some useful basics Python functions and class.", "version": "0.0.93" }, "last_serial": 5752862, "releases": { "0.0.92": [ { "comment_text": "", "digests": { "md5": "0165fdefc08b0dce25f277ec2f0581e9", "sha256": "af299e2dbcc7f9b6a0e6e53ce4d68f14bb8c1a62217c348acdeda0b20d740dbf" }, "downloads": -1, "filename": "systools-0.0.92.tar.gz", "has_sig": false, "md5_digest": "0165fdefc08b0dce25f277ec2f0581e9", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 56695, "upload_time": "2019-08-29T13:56:39", "url": "https://files.pythonhosted.org/packages/6d/5f/3613cf24ebfc2f85196f42a78522db7d2cc995fca2c904a40023ef8b7447/systools-0.0.92.tar.gz" } ], "0.0.93": [ { "comment_text": "", "digests": { "md5": "960c5387cb07d05d4a02bf3d96e8fc77", "sha256": "450167aab9a3132ebe546b834ef5b458d0564e41cf50ef998a35f12ae53a3dee" }, "downloads": -1, "filename": "systools-0.0.93.tar.gz", "has_sig": false, "md5_digest": "960c5387cb07d05d4a02bf3d96e8fc77", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 57138, "upload_time": "2019-08-29T14:08:17", "url": "https://files.pythonhosted.org/packages/f7/72/382e788e420aae32b0118d2a434302a58abd57ddc2c86e0f613372802594/systools-0.0.93.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "960c5387cb07d05d4a02bf3d96e8fc77", "sha256": "450167aab9a3132ebe546b834ef5b458d0564e41cf50ef998a35f12ae53a3dee" }, "downloads": -1, "filename": "systools-0.0.93.tar.gz", "has_sig": false, "md5_digest": "960c5387cb07d05d4a02bf3d96e8fc77", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 57138, "upload_time": "2019-08-29T14:08:17", "url": "https://files.pythonhosted.org/packages/f7/72/382e788e420aae32b0118d2a434302a58abd57ddc2c86e0f613372802594/systools-0.0.93.tar.gz" } ] }