Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Fukász Rómeó Ervin
/
cloud
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
A prog2-höz tartozó friss repo anyagok itt elérhetőek:
https://git.iit.bme.hu/
Commit
b1fe6a20
authored
Apr 29, 2014
by
Dudás Ádám
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
common: better tools for activity code manipulation
parent
ab55fbae
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
41 additions
and
0 deletions
+41
-0
circle/common/models.py
+41
-0
No files found.
circle/common/models.py
View file @
b1fe6a20
from
collections
import
deque
from
contextlib
import
contextmanager
from
hashlib
import
sha224
from
itertools
import
chain
,
imap
from
logging
import
getLogger
from
time
import
time
...
...
@@ -39,12 +40,52 @@ activity_context = contextmanager(activitycontextimpl)
activity_code_separator
=
'.'
def
has_prefix
(
activity_code
,
*
prefixes
):
"""Determine whether the activity code has the specified prefix.
E.g.: has_prefix('foo.bar.buz', 'foo.bar') == True
has_prefix('foo.bar.buz', 'foo', 'bar') == True
has_prefix('foo.bar.buz', 'foo.bar', 'buz') == True
has_prefix('foo.bar.buz', 'foo', 'bar', 'buz') == True
has_prefix('foo.bar.buz', 'foo', 'buz') == False
"""
equal
=
lambda
a
,
b
:
a
==
b
act_code_parts
=
split_activity_code
(
activity_code
)
prefixes
=
chain
(
*
imap
(
split_activity_code
,
prefixes
))
return
all
(
imap
(
equal
,
act_code_parts
,
prefixes
))
def
has_suffix
(
activity_code
,
*
suffixes
):
"""Determine whether the activity code has the specified suffix.
E.g.: has_suffix('foo.bar.buz', 'bar.buz') == True
has_suffix('foo.bar.buz', 'bar', 'buz') == True
has_suffix('foo.bar.buz', 'foo.bar', 'buz') == True
has_suffix('foo.bar.buz', 'foo', 'bar', 'buz') == True
has_suffix('foo.bar.buz', 'foo', 'buz') == False
"""
equal
=
lambda
a
,
b
:
a
==
b
act_code_parts
=
split_activity_code
(
activity_code
)
suffixes
=
chain
(
*
imap
(
split_activity_code
,
suffixes
))
return
all
(
imap
(
equal
,
reversed
(
act_code_parts
),
reversed
(
suffixes
)))
def
join_activity_code
(
*
args
):
"""Join the specified parts into an activity code.
:returns: Activity code string.
"""
return
activity_code_separator
.
join
(
args
)
def
split_activity_code
(
activity_code
):
"""Split the specified activity code into its parts.
:returns: A list of activity code parts.
"""
return
activity_code
.
split
(
activity_code_separator
)
class
ActivityModel
(
TimeStampedModel
):
activity_code
=
CharField
(
max_length
=
100
,
verbose_name
=
_
(
'activity code'
))
parent
=
ForeignKey
(
'self'
,
blank
=
True
,
null
=
True
,
related_name
=
'children'
)
...
...
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