Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
H
Hdlmake
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
15
Issues
15
List
Board
Labels
Milestones
Merge Requests
4
Merge Requests
4
Wiki
Wiki
image/svg+xml
Discourse
Discourse
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Projects
Hdlmake
Commits
c0e43f40
Commit
c0e43f40
authored
Aug 09, 2016
by
Javier D. Garcia-Lasheras
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor the Fetch package for non duplicated code
parent
65be4a9e
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
47 additions
and
65 deletions
+47
-65
fetcher.py
hdlmake/fetch/fetcher.py
+36
-4
git.py
hdlmake/fetch/git.py
+5
-29
local.py
hdlmake/fetch/local.py
+2
-2
svn.py
hdlmake/fetch/svn.py
+4
-30
No files found.
hdlmake/fetch/fetcher.py
View file @
c0e43f40
...
...
@@ -21,6 +21,13 @@
"""Module providing the base class for the different code fetchers"""
import
os
from
hdlmake.util
import
path
as
path_utils
import
logging
from
tempfile
import
TemporaryFile
from
subprocess
import
Popen
,
PIPE
class
Fetcher
(
object
):
"""Base class for the code fetcher objects"""
...
...
@@ -30,8 +37,33 @@ class Fetcher(object):
pass
@
staticmethod
def
check_id
(
path
):
"""Stub method, this must return a string with the version identifier
for the selected fetcher (revision, commit...)"""
def
check_id
(
path
,
command
):
"""Use the provided command to get the specific ID from
the repository at path"""
cur_dir
=
os
.
getcwd
()
identifier
=
None
stderr
=
TemporaryFile
()
try
:
is_windows
=
path_utils
.
check_windows
()
os
.
chdir
(
path
)
command_out
=
Popen
(
command
,
shell
=
True
,
stdin
=
PIPE
,
stdout
=
PIPE
,
stderr
=
stderr
,
close_fds
=
not
is_windows
)
errmsg
=
stderr
.
readlines
()
if
errmsg
:
logging
.
debug
(
"ID error message (in
%
s):
%
s"
,
path
,
'
\n
'
.
join
(
errmsg
))
try
:
identifier
=
command_out
.
stdout
.
readlines
()[
0
]
.
strip
()
except
IndexError
:
pass
finally
:
os
.
chdir
(
cur_dir
)
stderr
.
close
()
return
identifier
hdlmake/fetch/git.py
View file @
c0e43f40
...
...
@@ -24,7 +24,6 @@
import
os
from
hdlmake.util
import
path
as
path_utils
import
logging
from
tempfile
import
TemporaryFile
from
subprocess
import
Popen
,
PIPE
from
.constants
import
GIT
from
.fetcher
import
Fetcher
...
...
@@ -99,31 +98,8 @@ class Git(Fetcher):
return
success
@
staticmethod
def
check_id
(
path
):
"""Get the commit id for the Git repository at path"""
cur_dir
=
os
.
getcwd
()
commit
=
None
stderr
=
TemporaryFile
()
try
:
is_windows
=
path_utils
.
check_windows
()
os
.
chdir
(
path
)
def
check_git_commit
(
path
):
"""Get the revision number for the Git repository at path"""
git_cmd
=
'git log -1 --format="
%
H" | cut -c1-32'
git_out
=
Popen
(
git_cmd
,
shell
=
True
,
stdin
=
PIPE
,
stdout
=
PIPE
,
stderr
=
stderr
,
close_fds
=
not
is_windows
)
errmsg
=
stderr
.
readlines
()
if
errmsg
:
logging
.
debug
(
"git error message (in
%
s):
%
s"
,
path
,
'
\n
'
.
join
(
errmsg
))
try
:
commit
=
git_out
.
stdout
.
readlines
()[
0
]
.
strip
()
except
IndexError
:
pass
finally
:
os
.
chdir
(
cur_dir
)
stderr
.
close
()
return
commit
return
Fetcher
.
check_id
(
path
,
git_cmd
)
hdlmake/fetch/local.py
View file @
c0e43f40
...
...
@@ -35,7 +35,7 @@ class Local(Fetcher):
pass
@
staticmethod
def
check_
id
(
path
):
"""Get the ID for Local sources"""
def
check_
md5sum
(
path
):
"""Get the ID for Local sources
... maybe sha256 or md5sum?
"""
pass
hdlmake/fetch/svn.py
View file @
c0e43f40
...
...
@@ -23,8 +23,6 @@
import
os
import
logging
from
tempfile
import
TemporaryFile
from
subprocess
import
Popen
,
PIPE
from
hdlmake.util
import
path
as
path_utils
from
.fetcher
import
Fetcher
...
...
@@ -62,32 +60,8 @@ class Svn(Fetcher):
return
success
@
staticmethod
def
check_
id
(
path
):
def
check_
svn_revision
(
path
):
"""Get the revision number for the SVN repository at path"""
cur_dir
=
os
.
getcwd
()
revision
=
None
stderr
=
TemporaryFile
()
try
:
is_windows
=
path_utils
.
check_windows
()
os
.
chdir
(
path
)
svn_cmd
=
"svn info 2>/dev/null | awk '{if(NR == 5) {print $2}}'"
svn_out
=
Popen
(
svn_cmd
,
shell
=
True
,
stdin
=
PIPE
,
stdout
=
PIPE
,
stderr
=
stderr
,
close_fds
=
not
is_windows
)
errmsg
=
stderr
.
readlines
()
if
errmsg
:
logging
.
debug
(
"svn error message (in
%
s):
%
s"
,
path
,
'
\n
'
.
join
(
errmsg
))
try
:
revision
=
svn_out
.
stdout
.
readlines
()[
0
]
.
strip
()
except
IndexError
:
pass
finally
:
os
.
chdir
(
cur_dir
)
stderr
.
close
()
return
revision
return
Fetcher
.
check_id
(
path
,
svn_cmd
)
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