djangofloor.utils

Utility functions

Define some utility functions like warning or walking through modules.

exception djangofloor.utils.RemovedInDjangoFloor110Warning[source]

Used for displaying functions or modules that will be removed in a near future.

exception djangofloor.utils.RemovedInDjangoFloor200Warning[source]

Used for displaying functions or modules that will be removed in a near future.

djangofloor.utils.ensure_dir(path, parent=True)[source]

Ensure that the given directory exists

Parameters:
  • path – the path to check
  • parent – only ensure the existence of the parent directory
djangofloor.utils.get_view_from_string(view_as_str)[source]
djangofloor.utils.guess_version(defined_settings)[source]

Guesss the project version. Expect an installed version (findable with pkg_resources) or __version__ in your_project/__init__.py. If not found

Parameters:defined_settings (dict) – all already defined settings (dict)
Returns:should be something like “1.2.3”
Return type:str
djangofloor.utils.is_package_present(package_name)[source]

Return True is the package_name package is presend in your current Python environment.

djangofloor.utils.remove_arguments_from_help(parser, arguments)[source]
djangofloor.utils.smart_pipfile_url(url: str) → str[source]

Given a pip install URL, return a valid PipFile line.

>>> smart_pipfile_url('git://git.myproject.org/MyProject#egg=MyProject')
"MyProject = { git = 'git://git.myproject.org/MyProject', editable = true }"
>>> smart_pipfile_url('git+http://git.myproject.org/MyProject#egg=MyProject')
"MyProject = { git = 'http://git.myproject.org/MyProject', editable = true }"
>>> smart_pipfile_url('git+https://git.myproject.org/MyProject#egg=MyProject')
"MyProject = { git = 'https://git.myproject.org/MyProject', editable = true }"
>>> smart_pipfile_url('git+ssh://git.myproject.org/MyProject#egg=MyProject')
"MyProject = { git = 'ssh://git.myproject.org/MyProject', editable = true }"
>>> smart_pipfile_url('git+git://git.myproject.org/MyProject#egg=MyProject')
"MyProject = { git = 'git://git.myproject.org/MyProject', editable = true }"
>>> smart_pipfile_url('git+file://git.myproject.org/MyProject#egg=MyProject')
"MyProject = { git = 'file://git.myproject.org/MyProject', editable = true }"
>>> smart_pipfile_url('git+git@git.myproject.org:MyProject#egg=MyProject')
"MyProject = { git = 'git://git@git.myproject.org/MyProject', editable = true }"
>>> smart_pipfile_url('git://git.myproject.org/MyProject.git@master#egg=MyProject')
"MyProject = { git = 'git://git.myproject.org/MyProject.git', ref = 'master', editable = true }"
>>> smart_pipfile_url('git://git.myproject.org/MyProject.git@v1.0#egg=MyProject')
"MyProject = { git = 'git://git.myproject.org/MyProject.git', ref = 'v1.0', editable = true }"
>>> smart_pipfile_url('git://git.myproject.org/MyProject.git@da39a3ee5e6b4b0d3255bfef#egg=MyProject')
"MyProject = { git = 'git://git.myproject.org/MyProject.git', ref = 'da39a3ee5e6b4b0d3255bfef', editable = true }"
>>> smart_pipfile_url('hg+http://hg.myproject.org/MyProject#egg=MyProject')
"MyProject = { hg = 'http://hg.myproject.org/MyProject', editable = true }"
>>> smart_pipfile_url('hg+https://hg.myproject.org/MyProject#egg=MyProject')
"MyProject = { hg = 'https://hg.myproject.org/MyProject', editable = true }"
>>> smart_pipfile_url('hg+ssh://hg.myproject.org/MyProject#egg=MyProject')
"MyProject = { hg = 'ssh://hg.myproject.org/MyProject', editable = true }"
>>> smart_pipfile_url('hg+http://hg.myproject.org/MyProject@da39a3ee5e6b#egg=MyProject')
"MyProject = { hg = 'http://hg.myproject.org/MyProject', ref = 'da39a3ee5e6b', editable = true }"
>>> smart_pipfile_url('svn+svn://svn.myproject.org/svn/MyProject#egg=MyProject')
"MyProject = { svn = 'svn://svn.myproject.org/svn/MyProject', editable = true }"
>>> smart_pipfile_url('svn+http://svn.myproject.org/svn/MyProject/trunk@2019#egg=MyProject')
"MyProject = { svn = 'http://svn.myproject.org/svn/MyProject/trunk', ref = '2019', editable = true }"
>>> smart_pipfile_url('bzr+http://bzr.myproject.org/MyProject/trunk#egg=MyProject')
"MyProject = { bzr = 'http://bzr.myproject.org/MyProject/trunk', editable = true }"
>>> smart_pipfile_url('bzr+sftp://user@myproject.org/MyProject/trunk#egg=MyProject')
"MyProject = { bzr = 'sftp://user@myproject.org/MyProject/trunk', editable = true }"
>>> smart_pipfile_url('bzr+ssh://user@myproject.org/MyProject/trunk#egg=MyProject')
"MyProject = { bzr = 'ssh://user@myproject.org/MyProject/trunk', editable = true }"
>>> smart_pipfile_url('requests[socks]')
"requests = { extras = ['socks'] }"
>>> smart_pipfile_url('requests[socks,all]')
"requests = { extras = ['socks', 'all'] }"
>>> smart_pipfile_url('records>0.5.0')
"records = '>0.5.0'"
>>> smart_pipfile_url('git+https://github.com/django/django.git@1.11.4')
"django = { git = 'https://github.com/django/django.git', ref = '1.11.4', editable = true }"
>>> smart_pipfile_url('https://github.com/divio/django-cms/archive/release/3.4.x.zip')
'"7377c666" = { file = \'https://github.com/divio/django-cms/archive/release/3.4.x.zip\' }'
>>> smart_pipfile_url('pywinusb;python_version<"2.7"')
"pywinusb = '*'"
djangofloor.utils.walk(module_name, dirname, topdown=True)[source]

Copy of os.walk(), please refer to its doc. The only difference is that we walk in a package_resource instead of a plain directory. :type module_name: basestring :param module_name: module to search in :type dirname: basestring :param dirname: base directory :type topdown: bool :param topdown: if True, perform a topdown search.