Code Duplication    Length = 31-31 lines in 2 locations

versioneer.py 1 location

@@ 436-466 (lines=31) @@
433
    return decorate
434
435
436
def run_command(commands, args, cwd=None, verbose=False, hide_stderr=False):
437
    assert isinstance(commands, list)
438
    p = None
439
    for c in commands:
440
        try:
441
            dispcmd = str([c] + args)
442
            # remember shell=False, so use git.cmd on windows, not just git
443
            p = subprocess.Popen([c] + args, cwd=cwd, stdout=subprocess.PIPE,
444
                                 stderr=(subprocess.PIPE if hide_stderr
445
                                         else None))
446
            break
447
        except EnvironmentError:
448
            e = sys.exc_info()[1]
449
            if e.errno == errno.ENOENT:
450
                continue
451
            if verbose:
452
                print("unable to run %s" % dispcmd)
453
                print(e)
454
            return None
455
    else:
456
        if verbose:
457
            print("unable to find command, tried %s" % (commands,))
458
        return None
459
    stdout = p.communicate()[0].strip()
460
    if sys.version_info[0] >= 3:
461
        stdout = stdout.decode()
462
    if p.returncode != 0:
463
        if verbose:
464
            print("unable to run %s (error)" % dispcmd)
465
        return None
466
    return stdout
467
LONG_VERSION_PY['git'] = '''
468
# This file helps to compute a version number in source trees obtained from
469
# git-archive tarball (such as those provided by githubs download-from-tag

binstar_client/_version.py 1 location

@@ 63-93 (lines=31) @@
60
    return decorate
61
62
63
def run_command(commands, args, cwd=None, verbose=False, hide_stderr=False):
64
    assert isinstance(commands, list)
65
    p = None
66
    for c in commands:
67
        try:
68
            dispcmd = str([c] + args)
69
            # remember shell=False, so use git.cmd on windows, not just git
70
            p = subprocess.Popen([c] + args, cwd=cwd, stdout=subprocess.PIPE,
71
                                 stderr=(subprocess.PIPE if hide_stderr
72
                                         else None))
73
            break
74
        except EnvironmentError:
75
            e = sys.exc_info()[1]
76
            if e.errno == errno.ENOENT:
77
                continue
78
            if verbose:
79
                print("unable to run %s" % dispcmd)
80
                print(e)
81
            return None
82
    else:
83
        if verbose:
84
            print("unable to find command, tried %s" % (commands,))
85
        return None
86
    stdout = p.communicate()[0].strip()
87
    if sys.version_info[0] >= 3:
88
        stdout = stdout.decode()
89
    if p.returncode != 0:
90
        if verbose:
91
            print("unable to run %s (error)" % dispcmd)
92
        return None
93
    return stdout
94
95
96
def versions_from_parentdir(parentdir_prefix, root, verbose):