Skip to content

Commit

Permalink
Merge pull request #272 from 6WIND/version-mgmt
Browse files Browse the repository at this point in the history
enhance version management
  • Loading branch information
p-l- committed Sep 5, 2016
2 parents a2e8bb5 + 4f71027 commit 1c7e836
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
*.pyc
*.pyo
dist/
build/
MANIFEST
*.egg-info/
scapy/VERSION
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ include run_scapy
recursive-include bin *
recursive-include doc *
recursive-include test *
include scapy/VERSION
1 change: 1 addition & 0 deletions README
67 changes: 67 additions & 0 deletions scapy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,80 @@
## Copyright (C) Philippe Biondi <phil@secdev.org>
## This program is published under a GPLv2 license

from __future__ import with_statement

"""
Scapy: create, send, sniff, dissect and manipulate network packets.
Usable either from an interactive console or as a Python library.
http://www.secdev.org/projects/scapy
"""

import os
import re
import subprocess


_SCAPY_PKG_DIR = os.path.dirname(__file__)

def _version_from_git_describe():
"""
Read the version from ``git describe``. It returns the latest tag with an
optional suffix if the current directory is not exactly on the tag.
Example::
$ git describe --always
v2.3.2-346-g164a52c075c8
The tag prefix (``v``) and the git commit sha1 (``-g164a52c075c8``) are
removed if present.
If the current directory is not exactly on the tag, a ``.devN`` suffix is
appended where N is the number of commits made after the last tag.
Example::
>>> _version_from_git_describe()
'2.3.2.dev346'
"""
p = subprocess.Popen(['git', 'describe', '--always'], cwd=_SCAPY_PKG_DIR,
stdout=subprocess.PIPE, stderr=subprocess.PIPE)

out, err = p.communicate()

if p.returncode == 0:
tag = out.strip()
match = re.match(r'^v?(.+?)-(\d+)-g[a-f0-9]+$', tag)
if match:
# remove the 'v' prefix and add a '.devN' suffix
return '%s.dev%s' % (match.group(1), match.group(2))
else:
# just remove the 'v' prefix
return re.sub(r'^v', '', tag)
else:
raise subprocess.CalledProcessError(p.returncode, err)

def _version():
version_file = os.path.join(_SCAPY_PKG_DIR, 'VERSION')
try:
tag = _version_from_git_describe()
# successfully read the tag from git, write it in VERSION for
# installation and/or archive generation.
with open(version_file, 'w') as f:
f.write(tag)
return tag
except:
# failed to read the tag from git, try to read it from a VERSION file
try:
with open(version_file, 'r') as f:
tag = f.read()
return tag
except:
return 'unknown.version'

VERSION = _version()

if __name__ == "__main__":
from scapy.main import interact
interact()
3 changes: 2 additions & 1 deletion scapy/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import os,time,socket,sys

from scapy import VERSION
from scapy.data import *
from scapy import base_classes
from scapy import themes
Expand Down Expand Up @@ -319,7 +320,7 @@ class Conf(ConfClass):
AS_resolver: choose the AS resolver class to use
extensions_paths: path or list of paths where extensions are to be looked for
"""
version = "2.3.2-dev"
version = VERSION
session = ""
interactive = False
interactive_shell = ""
Expand Down
5 changes: 5 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
[metadata]
description-file = README.md

[sdist]
formats=gztar
owner=root
group=root
5 changes: 4 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def make_ezipfile(base_name, base_dir, verbose=0, dry_run=0, **kwargs):

setup(
name='scapy',
version='2.3.2-dev',
version=__import__('scapy').VERSION,
packages=[
'scapy',
'scapy/arch',
Expand All @@ -62,6 +62,9 @@ def make_ezipfile(base_name, base_dir, verbose=0, dry_run=0, **kwargs):
],
scripts=SCRIPTS,
data_files=[('share/man/man1', ["doc/scapy.1.gz"])],
package_data={
'scapy': ['VERSION'],
},

# Metadata
author='Philippe BIONDI',
Expand Down

0 comments on commit 1c7e836

Please sign in to comment.