Skip to content

Commit 57b0ea2

Browse files
author
osfunapps
committed
first commit
1 parent 41c27b4 commit 57b0ea2

File tree

7 files changed

+188
-0
lines changed

7 files changed

+188
-0
lines changed

LICENSE.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2018 YOUR NAME
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

ostools/FileHandler.py

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
###########################################################################
2+
#
3+
# this module meant to provide file handling functions
4+
#
5+
###########################################################################
6+
7+
import os
8+
import shutil
9+
10+
# will return the content of a directory (full paths)
11+
def get_dir_content(dir_path, ignored_files_arr=['.DS_Store']):
12+
f = []
13+
for path, dirs, files in os.walk(dir_path):
14+
for filename in files:
15+
f.append(os.path.join(path, filename))
16+
break
17+
18+
f = list(filter(lambda x: get_file_name_from_path(x) not in ignored_files_arr, f))
19+
return f
20+
21+
22+
# will return the name of the last dir name from a path
23+
def get_dir_name(dir_path):
24+
return os.path.basename(os.path.normpath(dir_path))
25+
26+
27+
# will split path to arr of dirs
28+
def split_path(path):
29+
path = os.path.normpath(path)
30+
return path.split(os.sep)
31+
32+
33+
# will return the extension of a file from a file path
34+
def get_extension_from_file(file):
35+
_, file_extension = os.path.splitext(file)
36+
return file_extension
37+
38+
39+
# will return the file name from a file path
40+
def get_file_name_from_path(file):
41+
import ntpath
42+
return ntpath.basename(file)
43+
44+
45+
# will remove a directory
46+
def remove_dir(path):
47+
if (os.path.isdir(path)):
48+
shutil.rmtree(path)
49+
50+
51+
# will copy a directory
52+
def copy_dir(src, dst):
53+
from distutils.dir_util import copy_tree
54+
copy_tree(src, dst)
55+
56+
57+
# will copy a file to a dest
58+
def copy_file(src, dst):
59+
shutil.copyfile(src, dst)
60+
61+
62+
# will search for a file in a path
63+
def search_file(path_to_search, file_name):
64+
from pathlib import Path
65+
files = []
66+
for filename in Path(path_to_search).glob('**/' + file_name):
67+
files.append(filename)
68+
return files
69+
70+
71+
# will replace a text in a line in a file with other line
72+
def replace_line_in_line(file, line_in_line_dict):
73+
lines = []
74+
with open(file, "r") as f:
75+
for line in f:
76+
appended = False
77+
for key, val in line_in_line_dict.items():
78+
if key in line:
79+
lines.append(val + '\n')
80+
appended = True
81+
if not appended:
82+
lines.append(line)
83+
84+
with open(file, "w") as f:
85+
f.writelines(lines)

ostools/Tools.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
###########################################################################
2+
#
3+
# this module meant to provide general handling to python files
4+
#
5+
###########################################################################
6+
7+
8+
# will print an array
9+
def print_arr(arr, divider='\n'):
10+
print(divider.join(arr))

ostools/XmlFileHandler.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import xml.etree.ElementTree as ET
2+
3+
4+
###########################################################################
5+
#
6+
# this module meant to provide intuitive functions to work with xml files
7+
#
8+
###########################################################################
9+
10+
# will return a node specified by an attribute key and an attribute value
11+
def get_node_from_xml(xml_file, node_tag, node_att_name, node_att_val):
12+
root = xml_file.getroot()
13+
found = root.findall(node_tag + "/[@" + node_att_name + "='" + node_att_val + "']")
14+
return found
15+
16+
17+
# will return the text (inner html) of a given node
18+
def get_text_from_node(node):
19+
return node.text
20+
21+
22+
# will set the text (inner html) in a given node
23+
def set_text_in_node(node, text):
24+
node.text = text
25+
26+
27+
# will return the value of a given att from a desired node
28+
def get_att_value_from_node(node, att_name):
29+
return node.get(att_name)
30+
31+
32+
# will return an xml file
33+
def read_xml_file(xml_path):
34+
return ET.parse(xml_path)
35+
36+
37+
# will save the changes made in an xml file
38+
def save_xml_file(xml_file, xml_path):
39+
xml_file.write(xml_path)

ostools/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import ostools.FileHandler
2+
import ostools.Tools
3+
import ostools.XmlFileHandler

setup.cfg

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Inside of setup.cfg
2+
# [metadata]
3+
# description-file = README.md

setup.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
from distutils.core import setup
2+
setup(
3+
name = 'os-tools', # How you named your package folder (MyLib)
4+
packages = ['ostools'], # Choose the same as "name"
5+
version = '1.0', # Start with a small number and increase it with every change you make
6+
license='MIT', # Chose a license from here: https://help.github.com/articles/licensing-a-repository
7+
description = 'py tools for os', # Give a short description about your library
8+
author = 'Oz Shabat', # Type in your name
9+
author_email = 'osfunapps@gmail.com', # Type in your E-Mail
10+
url = 'https://github.com/osfunapps', # Provide either the link to your github or to your website
11+
download_url = 'https://github.com/osfunapps/os-xcode-tools-py/archive/v1.01.tar.gz', # I explain this later on
12+
keywords = ['python', 'osfunapps', 'files', 'tools', 'xcode', 'swift', 'apple', 'utils'], # Keywords that define your package best
13+
install_requires=[],
14+
classifiers=[
15+
'Development Status :: 5 - Production/Stable', # Chose either "3 - Alpha", "4 - Beta" or "5 - Production/Stable" as the current state of your package
16+
17+
'Intended Audience :: Developers', # Define that your audience are developers
18+
'Topic :: Software Development :: Build Tools',
19+
20+
'License :: OSI Approved :: MIT License', # Again, pick a license
21+
22+
'Programming Language :: Python :: 3', #Specify which pyhton versions that you want to support
23+
'Programming Language :: Python :: 3.4',
24+
'Programming Language :: Python :: 3.5',
25+
'Programming Language :: Python :: 3.6',
26+
],
27+
)

0 commit comments

Comments
 (0)