Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
caosdb-pylib
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
caosdb
Software
caosdb-pylib
Commits
a9c09d73
Commit
a9c09d73
authored
May 15, 2023
by
florian
Browse files
Options
Downloads
Plain Diff
Merge branch 'dev' into f-check-merge-entities
parents
4ebec82b
08a4e13f
Branches
Branches containing commit
Tags
Tags containing commit
2 merge requests
!107
ENH: add entity getters and cached functions
,
!103
Improving the compare_entities functions
Pipeline
#36809
canceled
May 15, 2023
Stage: code_style
Stage: linting
Stage: test
Stage: deploy
Changes
3
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
CHANGELOG.md
+3
-0
3 additions, 0 deletions
CHANGELOG.md
src/caosdb/apiutils.py
+27
-44
27 additions, 44 deletions
src/caosdb/apiutils.py
src/caosdb/utils/git_utils.py
+84
-0
84 additions, 0 deletions
src/caosdb/utils/git_utils.py
with
114 additions
and
44 deletions
CHANGELOG.md
+
3
−
0
View file @
a9c09d73
...
@@ -19,6 +19,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
...
@@ -19,6 +19,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Deprecated ###
### Deprecated ###
-
getOriginUrlIn, getDiffIn, getBranchIn, getCommitIn (formerly apiutils) have been
moved to caosdb.utils.git_utils
### Removed ###
### Removed ###
### Fixed ###
### Fixed ###
...
...
This diff is collapsed.
Click to expand it.
src/caosdb/apiutils.py
+
27
−
44
View file @
a9c09d73
...
@@ -27,21 +27,20 @@
...
@@ -27,21 +27,20 @@
"""
"""
import
logging
import
logging
import
sys
import
tempfile
import
warnings
import
warnings
from
collections.abc
import
Iterable
from
collections.abc
import
Iterable
from
subprocess
import
call
from
typing
import
Any
,
Dict
,
List
from
typing
import
Optional
,
Any
,
Dict
,
List
from
caosdb.common.datatype
import
(
BOOLEAN
,
DATETIME
,
DOUBLE
,
FILE
,
INTEGER
,
from
caosdb.common.datatype
import
is_reference
REFERENCE
,
TEXT
,
is_reference
)
from
caosdb.common.models
import
(
Container
,
Entity
,
File
,
Property
,
from
caosdb.common.models
import
(
Container
,
Entity
,
File
,
Property
,
Query
,
Record
,
RecordType
,
execute_query
,
Record
,
RecordType
,
execute_query
,
get_config
,
SPECIAL_ATTRIBUTES
)
SPECIAL_ATTRIBUTES
)
from
caosdb.exceptions
import
CaosDBException
from
caosdb.exceptions
import
CaosDBException
from
caosdb.utils.git_utils
import
(
get_origin_url_in
,
get_diff_in
,
get_branch_in
,
get_commit_in
)
logger
=
logging
.
getLogger
(
__name__
)
logger
=
logging
.
getLogger
(
__name__
)
...
@@ -148,51 +147,35 @@ def retrieve_entities_with_ids(entities):
...
@@ -148,51 +147,35 @@ def retrieve_entities_with_ids(entities):
def
getOriginUrlIn
(
folder
):
def
getOriginUrlIn
(
folder
):
"""
return the Fetch URL of the git repository in the given folder.
"""
warnings
.
warn
(
"""
with
tempfile
.
NamedTemporaryFile
(
delete
=
False
,
mode
=
"
w
"
)
as
t
:
This function is deprecated and will be removed with the next release.
call
([
"
git
"
,
"
remote
"
,
"
show
"
,
"
origin
"
],
stdout
=
t
,
cwd
=
folder
)
Please use the caosdb.utils.git_utils.get_origin_url_in instead.
"""
,
with
open
(
t
.
name
,
"
r
"
)
as
t
:
DeprecationWarning
)
urlString
=
"
Fetch URL:
"
return
get_origin_url_in
(
folder
)
for
line
in
t
.
readlines
():
if
urlString
in
line
:
return
line
[
line
.
find
(
urlString
)
+
len
(
urlString
):].
strip
()
return
None
def
getDiffIn
(
folder
,
save_dir
=
None
):
def
getDiffIn
(
folder
,
save_dir
=
None
):
"""
returns the name of a file where the out put of
"
git diff
"
in the given
warnings
.
warn
(
"""
folder is stored.
"""
This function is deprecated and will be removed with the next release.
with
tempfile
.
NamedTemporaryFile
(
delete
=
False
,
mode
=
"
w
"
,
dir
=
save_dir
)
as
t
:
Please use the caosdb.utils.git_utils.get_diff_in instead.
"""
,
call
([
"
git
"
,
"
diff
"
],
stdout
=
t
,
cwd
=
folder
)
DeprecationWarning
)
return
get_diff_in
(
folder
,
save_dir
)
return
t
.
name
def
getBranchIn
(
folder
):
def
getBranchIn
(
folder
):
"""
returns the current branch of the git repository in the given folder.
warnings
.
warn
(
"""
This function is deprecated and will be removed with the next release.
The command
"
git branch
"
is called in the given folder and the
Please use the caosdb.utils.git_utils.get_branch_in instead.
"""
,
output is returned
DeprecationWarning
)
"""
return
get_branch_in
(
folder
)
with
tempfile
.
NamedTemporaryFile
(
delete
=
False
,
mode
=
"
w
"
)
as
t
:
call
([
"
git
"
,
"
rev-parse
"
,
"
--abbrev-ref
"
,
"
HEAD
"
],
stdout
=
t
,
cwd
=
folder
)
with
open
(
t
.
name
,
"
r
"
)
as
t
:
return
t
.
readline
().
strip
()
def
getCommitIn
(
folder
):
def
getCommitIn
(
folder
):
"""
returns the commit hash in of the git repository in the given folder.
warnings
.
warn
(
"""
This function is deprecated and will be removed with the next release.
The command
"
git log -1 --format=%h
"
is called in the given folder
Please use the caosdb.utils.git_utils.get_commit_in instead.
"""
,
and the output is returned
DeprecationWarning
)
"""
return
get_commit_in
(
folder
)
with
tempfile
.
NamedTemporaryFile
(
delete
=
False
,
mode
=
"
w
"
)
as
t
:
call
([
"
git
"
,
"
log
"
,
"
-1
"
,
"
--format=%h
"
],
stdout
=
t
,
cwd
=
folder
)
with
open
(
t
.
name
,
"
r
"
)
as
t
:
return
t
.
readline
().
strip
()
def
compare_entities
(
old_entity
:
Entity
,
new_entity
:
Entity
,
def
compare_entities
(
old_entity
:
Entity
,
new_entity
:
Entity
,
...
...
This diff is collapsed.
Click to expand it.
src/caosdb/utils/git_utils.py
0 → 100644
+
84
−
0
View file @
a9c09d73
# -*- coding: utf-8 -*-
#
# This file is a part of the CaosDB Project.
#
# Copyright (C) 2018 Research Group Biomedical Physics,
# Max-Planck-Institute for Dynamics and Self-Organization Göttingen
# Copyright (C) 2020 Timm Fitschen <t.fitschen@indiscale.com>
# Copyright (C) 2020-2022 IndiScale GmbH <info@indiscale.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
# ** end header
#
"""
git-utils: Some functions for retrieving information about git repositories.
"""
import
logging
import
tempfile
from
subprocess
import
call
logger
=
logging
.
getLogger
(
__name__
)
def
get_origin_url_in
(
folder
:
str
):
"""
return the Fetch URL of the git repository in the given folder.
"""
with
tempfile
.
NamedTemporaryFile
(
delete
=
False
,
mode
=
"
w
"
)
as
t
:
call
([
"
git
"
,
"
remote
"
,
"
show
"
,
"
origin
"
],
stdout
=
t
,
cwd
=
folder
)
with
open
(
t
.
name
,
"
r
"
)
as
t
:
urlString
=
"
Fetch URL:
"
for
line
in
t
.
readlines
():
if
urlString
in
line
:
return
line
[
line
.
find
(
urlString
)
+
len
(
urlString
):].
strip
()
return
None
def
get_diff_in
(
folder
:
str
,
save_dir
=
None
):
"""
returns the name of a file where the out put of
"
git diff
"
in the given
folder is stored.
"""
with
tempfile
.
NamedTemporaryFile
(
delete
=
False
,
mode
=
"
w
"
,
dir
=
save_dir
)
as
t
:
call
([
"
git
"
,
"
diff
"
],
stdout
=
t
,
cwd
=
folder
)
return
t
.
name
def
get_branch_in
(
folder
:
str
):
"""
returns the current branch of the git repository in the given folder.
The command
"
git branch
"
is called in the given folder and the
output is returned
"""
with
tempfile
.
NamedTemporaryFile
(
delete
=
False
,
mode
=
"
w
"
)
as
t
:
call
([
"
git
"
,
"
rev-parse
"
,
"
--abbrev-ref
"
,
"
HEAD
"
],
stdout
=
t
,
cwd
=
folder
)
with
open
(
t
.
name
,
"
r
"
)
as
t
:
return
t
.
readline
().
strip
()
def
get_commit_in
(
folder
:
str
):
"""
returns the commit hash in of the git repository in the given folder.
The command
"
git log -1 --format=%h
"
is called in the given folder
and the output is returned
"""
with
tempfile
.
NamedTemporaryFile
(
delete
=
False
,
mode
=
"
w
"
)
as
t
:
call
([
"
git
"
,
"
log
"
,
"
-1
"
,
"
--format=%h
"
],
stdout
=
t
,
cwd
=
folder
)
with
open
(
t
.
name
,
"
r
"
)
as
t
:
return
t
.
readline
().
strip
()
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment