Skip to content

Commit

Permalink
Merge pull request #2 from Cyperghost/master
Browse files Browse the repository at this point in the history
Replace distutils and optimize rename.py
  • Loading branch information
cdalitz authored Jan 13, 2023
2 parents 54cc49e + 1aa140a commit 6e9bd70
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 32 deletions.
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
build/
dist/
venv/

gamera/toolkits/skeleton/plugins/*.cpp
*.egg-info

# IDEs
.idea/
7 changes: 3 additions & 4 deletions INSTALL
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,10 @@ In addition, your Linux installation should also have:
Standard Build and Install
--------------------------

Gamera toolkits are built using the Python-standard Distutils system. Open a
terminal and type::
Gamera toolkits are can be installed, throw pip. Open a
terminal in the folder and type::

python setup.py build
sudo python setup.py install
pip install .

Mac OS-X
========
Expand Down
4 changes: 2 additions & 2 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ Python package.
Creating a toolkit
------------------

The directory heirarchy
The directory hierarchy
```````````````````````

Toolkits require a number of different files in a directory
heirarchy. Here we assume the toolkit is called ``my_toolkit``.
hierarchy. Here we assume the toolkit is called ``my_toolkit``.

+----------+----------------------------------------------------------------+
| ./ | Basic information files for building the toolkit |
Expand Down
7 changes: 0 additions & 7 deletions build/scripts-3.7/skeleton

This file was deleted.

44 changes: 36 additions & 8 deletions rename.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
#!/usr/bin/env python

from os import rename
from os import rename, walk
from os.path import *
from sys import argv

ignoreFiles = ["rename.py", "turtle.jpg", "__pycache__"]


def change_content(dirname, names):
# ignore some dirs
if basename(dirname) in ignoreFiles:
return

def change_content(change_to, dirname, names):
for name in names:
# ignore some files
if name in ignoreFiles:
continue
full_path = join(dirname, name)
if isfile(full_path):
print("Adjusting content in %s" % full_path)
Expand All @@ -16,22 +25,41 @@ def change_content(change_to, dirname, names):
content = content.replace(change_from, change_to)
open(full_path, "w").write(content)
elif isdir(full_path):
walk(full_path, change_content, change_to)
for baseDir, dirName, fileNames in walk(full_path):
change_content(baseDir, fileNames)


def rename_files(dirname, names):
# ignore some dirs
if basename(dirname) in ignoreFiles:
return

# rename dir
if basename(dirname).__eq__(change_from):
newdirname = dirname.replace(change_from, change_to)
rename(dirname, newdirname)
for baseDir, dirName, fileNames in walk(newdirname):
rename_files(baseDir, fileNames)
return

def rename_files(change_to, dirname, names):
for name in names:
# ignore some files
if name in ignoreFiles:
continue
full_path = join(dirname, name)
if isdir(full_path):
walk(full_path, rename_files, change_to)
for baseDir, dirName, fileNames in walk(full_path):
rename_files(baseDir, fileNames)
if name.find(change_from) != -1:
new_name = name.replace(change_from, change_to)
new_name = name.replace(change_from)
print("Renaming %s to %s" % (full_path, join(dirname, new_name)))
rename(full_path, join(dirname, new_name))


change_from = 'skeleton'
change_to = argv[-1].lower()
print("Changing name of toolkit project to '%s'." % change_to)
walk(".", change_content, change_to)
walk(".", rename_files, change_to)
for directory, dirnames, filenames in walk("."):
change_content(directory, filenames)
for directory, dirnames, filenames in walk("."):
rename_files(directory, filenames)
25 changes: 14 additions & 11 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python
from pathlib import Path

from distutils.core import setup
from setuptools import setup

from gamera import gamera_setup

Expand All @@ -20,12 +20,15 @@
plugins = gamera_setup.get_plugin_filenames(PLUGIN_PATH)
plugin_extensions = gamera_setup.generate_plugins(plugins, PLUGIN_PACKAGE)

# This is a standard distutils setup initializer. If you need to do
# anything more complex here, refer to the Python distutils documentation.
setup(name=TOOLKIT_NAME,
version="3.0.1",
ext_modules=plugin_extensions,
packages=[PACKAGE, PLUGIN_PACKAGE],
scripts=['scripts/skeleton'],
requires=['gamera']
)
# This is a standard setuptools setup initializer. If you need to do
# anything more complex here, refer to the Python setuptools documentation.
if __name__ == "__main__":
setup(name=TOOLKIT_NAME,
version="4.1.0",
ext_modules=plugin_extensions,
packages=[PACKAGE, PLUGIN_PACKAGE],
include_dirs=['include/plugins'],
python_requires='>=3.5',
scripts=['scripts/skeleton'],
install_requires=['gamera>=4.1.0']
)

0 comments on commit 6e9bd70

Please sign in to comment.