Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
modelgen
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Taddeüs Kroes
modelgen
Commits
9a81da56
Commit
9a81da56
authored
Jul 07, 2012
by
Taddeüs Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Applied pyflakes and pep8.
parent
aea8b483
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
14 additions
and
10 deletions
+14
-10
generate.py
generate.py
+6
-5
singplur.py
singplur.py
+3
-3
test.py
test.py
+3
-1
tests/test_generate.py
tests/test_generate.py
+2
-1
No files found.
generate.py
View file @
9a81da56
#!/usr/bin/env python
#!/usr/bin/env python
import
re
import
re
import
MySQLdb
as
mysql
import
MySQLdb
as
mysql
from
singplur
import
singularize
,
pluralize
from
singplur
import
singularize
from
itertools
import
combinations
from
itertools
import
combinations
...
@@ -183,7 +183,8 @@ class Model(object):
...
@@ -183,7 +183,8 @@ class Model(object):
if
self
.
options
.
get
(
'create_accessible'
,
True
):
if
self
.
options
.
get
(
'create_accessible'
,
True
):
lines
.
append
(
self
.
php_attr_accessible
())
lines
.
append
(
self
.
php_attr_accessible
())
php
=
classdef
%
'
\
n
'
.
join
([
TAB
+
line
for
line
in
lines
if
line
!=
None
])
php
=
classdef
%
'
\
n
'
.
join
([
TAB
+
line
for
line
in
lines
if
line
is
not
None
])
return
php_block
(
php
)
if
add_php_block
else
php
return
php_block
(
php
)
if
add_php_block
else
php
...
@@ -274,10 +275,10 @@ if __name__ == '__main__':
...
@@ -274,10 +275,10 @@ if __name__ == '__main__':
help
=
'MySQL username'
)
help
=
'MySQL username'
)
parser
.
add_argument
(
'-p'
,
'--password'
,
default
=
'mysql12#$'
,
parser
.
add_argument
(
'-p'
,
'--password'
,
default
=
'mysql12#$'
,
help
=
'MySQL password'
)
help
=
'MySQL password'
)
parser
.
add_argument
(
'--has-one'
,
nargs
=
2
,
dest
=
'opt_has_one'
,
action
=
'append'
,
parser
.
add_argument
(
'--has-one'
,
nargs
=
2
,
dest
=
'opt_has_one'
,
help
=
'one-to-one relationships of the form '
help
=
'one-to-one relationships of the form '
'
\
'
payment-receipt
\
'
, where one payment has one '
'
\
'
payment-receipt
\
'
, where one payment has one '
'receipt'
)
'receipt'
,
action
=
'append'
)
parser
.
add_argument
(
'--namespace'
,
default
=
''
,
dest
=
'opt_namespace'
,
parser
.
add_argument
(
'--namespace'
,
default
=
''
,
dest
=
'opt_namespace'
,
help
=
'PHP namespace to create models classes in'
)
help
=
'PHP namespace to create models classes in'
)
parser
.
add_argument
(
'--create-select'
,
action
=
'store_true'
,
parser
.
add_argument
(
'--create-select'
,
action
=
'store_true'
,
...
...
singplur.py
View file @
9a81da56
...
@@ -9,7 +9,7 @@ SINGULARS = (
...
@@ -9,7 +9,7 @@ SINGULARS = (
(
r'matrices'
,
'matrix'
),
(
r'matrices'
,
'matrix'
),
(
r'([aeiou])ys'
,
'
\
\
1y'
),
(
r'([aeiou])ys'
,
'
\
\
1y'
),
(
r'([^aeiou])ies'
,
'
\
\
1y'
),
(
r'([^aeiou])ies'
,
'
\
\
1y'
),
(
r'([^aeiou])ices$'
,
'
\
\
1ice'
),
(
r'([^aeiou])ices$'
,
'
\
\
1ice'
),
(
r'ices'
,
'ex'
),
(
r'ices'
,
'ex'
),
(
r'([sxz]|[cs]h)es$'
,
'
\
\
1'
),
(
r'([sxz]|[cs]h)es$'
,
'
\
\
1'
),
(
r'eet'
,
'oot'
),
(
r'eet'
,
'oot'
),
...
@@ -55,7 +55,7 @@ def apply_rules(word, rules):
...
@@ -55,7 +55,7 @@ def apply_rules(word, rules):
if
word
in
SAME
:
if
word
in
SAME
:
return
word
return
word
for
pattern
,
replacement
in
rules
:
for
pattern
,
replacement
in
rules
:
word
,
n
=
re
.
subn
(
pattern
+
'$'
,
replacement
,
word
)
word
,
n
=
re
.
subn
(
pattern
+
'$'
,
replacement
,
word
)
if
n
:
if
n
:
...
...
test.py
View file @
9a81da56
#!/usr/bin/env python
#!/usr/bin/env python
import
os
,
re
,
sys
,
unittest
import
os
import
re
import
unittest
TESTS_DIR
=
'tests'
TESTS_DIR
=
'tests'
...
...
tests/test_generate.py
View file @
9a81da56
from
unittest
import
TestCase
from
unittest
import
TestCase
import
MySQLdb
as
mysql
import
MySQLdb
as
mysql
from
generate
import
Model
,
php_value
,
php_assoc
,
flatten
,
read_tables
,
read_fields
from
generate
import
Model
,
php_value
,
php_assoc
,
flatten
,
read_tables
,
\
read_fields
class
GenerateTest
(
TestCase
):
class
GenerateTest
(
TestCase
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment