Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 05dd366

Browse filesBrowse files
authored
add create manifest function
1 parent af7e5ac commit 05dd366
Copy full SHA for 05dd366

File tree

3 files changed

+75
-4
lines changed
Filter options

3 files changed

+75
-4
lines changed

‎PDL/package/pdlparse/__init__.py

Copy file name to clipboard
+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
#https://www.freecodecamp.org/news/build-your-first-python-package/
22
from parse import scrap_library, get_variable, filter_file, get_strings, get_class, get_type, get_value, get_comments
3-
from library import get_libs, get_lib_info, get_main_lib, read_lib, format_lib, remove_comments
3+
from library import get_libs, get_lib_info, get_main_lib, read_lib, format_lib, remove_comments
4+
from new import create_lib, create_lib_script, create_manifest

‎PDL/package/pdlparse/library.py

Copy file name to clipboardExpand all lines: PDL/package/pdlparse/library.py
+8-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import os, sys
22

33

4-
def get_libs(base_dir):
4+
def get_libs(dir):
5+
# Gets all .pdl files in dir
56
retlist = []
6-
for r, d, f in os.walk(base_dir):
7+
for r, d, f in os.walk(dir):
78
for file in f:
89
if '.pdl' in file:
910
itemobj = os.path.relpath(f'{r}/{file}')
@@ -13,6 +14,7 @@ def get_libs(base_dir):
1314

1415

1516
def get_lib_info(library):
17+
# Returns information on the given library
1618
if not os.path.exists(library):
1719
raise FileNotFoundError(f'ERROR: Package pdlparse cannot find file {library}.')
1820

@@ -31,11 +33,11 @@ def get_lib_info(library):
3133

3234
else:
3335
raise Exception(f'ERROR: Package pdlparse cannot find vars or classes in {library}.')
34-
3536
return f'variable# = {var_count} class# = {class_count}'
3637

3738

3839
def get_main_lib(base_dir):
40+
# Finds main library if there are any
3941
if not os.path.exists(base_dir):
4042
raise FileNotFoundError(f'ERROR: Package pdlparse cannot find file {base_dir}.')
4143

@@ -55,6 +57,7 @@ def get_main_lib(base_dir):
5557

5658

5759
def read_lib(library, aloud=False):
60+
# Reads the given library aloud or returns it
5861
if not os.path.exists(library):
5962
raise FileNotFoundError(f'ERROR: Package pdlparse cannot find file {library}.')
6063

@@ -72,6 +75,7 @@ def read_lib(library, aloud=False):
7275

7376

7477
def format_lib(library):
78+
# Fixes any soft-errors found in library
7579
if not os.path.exists(library):
7680
raise FileNotFoundError(f'ERROR: Package pdlparse cannot find file {library}.')
7781

@@ -130,6 +134,7 @@ def format_lib(library):
130134

131135

132136
def remove_comments(library):
137+
# Removes all comments from a library
133138
if not os.path.exists(library):
134139
raise FileNotFoundError(f'ERROR: Package pdlparse cannot find file {library}.')
135140

‎PDL/package/pdlparse/new.py

Copy file name to clipboard
+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import os, sys
2+
3+
4+
def create_lib(path, name):
5+
if not os.path.exists(path):
6+
raise FileNotFoundError(f'ERROR: Package pdlparse cannot find {path}.')
7+
8+
new_file = f'{path}/{name}.pdl'
9+
with open(new_file, 'w') as file:
10+
file.write('''/*
11+
__KEYWORDS__
12+
class - a place to store variables and data
13+
priv - declares a variable as exclusive to .pdl file
14+
new - creates a copy of variable similar to handle
15+
__TYPES__
16+
str - declares a variable as a string
17+
int - declares a variable as integer
18+
lst - uses brackets and commas to create list's
19+
flt - a floating point number
20+
raw - used to declare all back-slashes to be ignored
21+
bol - true, false, null
22+
__COMMENTS__
23+
// - line comment
24+
*/
25+
\n''')
26+
file.write('class main { \
27+
\n int number = 23 \
28+
\n};')
29+
30+
31+
def create_lib_script(library, script_name):
32+
if not os.path.exists(library):
33+
raise FileNotFoundError(f'ERROR: Package pdlparse cannot find {library}')
34+
file_path = os.path.dirname(library)
35+
if not '.' in script_name:
36+
new_file = f'{file_path}/{script_name}.py'
37+
else:
38+
raise Exception(f'ERROR: Package pdlparse found `.` in {script_name} variable')
39+
40+
with open(new_file, 'w') as new:
41+
new.write("import os, sys \n")
42+
new.write("import pdlparse as pdl \n")
43+
new.write("variables = pdl.parse.scrap_library('test.pdl')")
44+
45+
46+
def create_manifest(dir):
47+
if not os.path.exists(dir):
48+
raise FileNotFoundError(f'ERROR: Package pdlparse cannot find {dir}')
49+
new_file = f'{dir}/MANIFEST'
50+
51+
with open(new_file, 'a') as file:
52+
libs = []
53+
file.write('-_FILES_-\n')
54+
for r, d, f in os.walk(dir):
55+
for item in f:
56+
if 'MANIFEST' in item:
57+
f.remove(item)
58+
if '.pdl' in item:
59+
libs.append(item)
60+
else:
61+
file.write(f'{item}\n')
62+
file.write('-_LIBS_-\n')
63+
for item in libs:
64+
file.write(f'{item}\n')
65+

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.