コード例 #1
0
def cdisp(argv):
    try:
        opts, args = getopt.getopt(argv, "c:s:v", ["compress="])
        if len(opts) == 0:
            print(help_msg)
    except getopt.GetoptError:
        print(help_msg)
        sys.exit(2)
    for opt, arg in opts:
        if opt == '-h':
            print(help_msg)
            sys.exit()
            img = core.decode(img_path, color_mode, mode)
        elif opt in ("-c", "--compress"):
            img_path = arg
            color_mode = args[0] if len(args) > 0 else "F"
            mode = args[1] if len(args) > 1 else "D2"
            threshold_1 = float(args[2]) if len(args) > 2 else 0.05
            threshold_2 = float(args[3]) if len(args) > 3 else threshold_1
            threshold_3 = float(args[4]) if len(args) > 4 else threshold_1
            encoded_img = core.encode(img_path, color_mode, mode, [threshold_1,threshold_2, threshold_3])
            img = core.decode(encoded_img,color_mode,mode)
        elif opt in ("-s", "--save"):   #save as image
            core.save(img, arg)
        elif opt == "-v":   #verbose
            core.verbose = True
            print("Verbose: " + str(core.verbose))
コード例 #2
0
ファイル: git.py プロジェクト: dannyfeng/gitGUI
def read_git_file(f):
    if f is None:
        return None
    if is_git_file(f):
        fh = open(f)
        data = core.decode(core.read(fh)).rstrip()
        fh.close()
        if data.startswith('gitdir: '):
            return core.decode(data[len('gitdir: '):])
    return None
コード例 #3
0
ファイル: gitcmds.py プロジェクト: dannyfeng/gitGUI
def commit_diff(sha1, git=git):
    commit = git.show(sha1)
    first_newline = commit.index('\n')
    if commit[first_newline+1:].startswith('Merge:'):
        return (core.decode(commit) + '\n\n' +
                core.decode(diff_helper(commit=sha1,
                                        cached=False,
                                        suppress_header=False)))
    else:
        return core.decode(commit)
コード例 #4
0
ファイル: gitcfg.py プロジェクト: dannyfeng/gitGUI
def _stat_info():
    # Try /etc/gitconfig as a fallback for the system config
    userconfig = os.path.expanduser(os.path.join('~', '.gitconfig'))
    paths = (('system', '/etc/gitconfig'),
             ('user', core.decode(userconfig)),
             ('repo', core.decode(git.instance().git_path('config'))))
    statinfo = []
    for category, path in paths:
        try:
            statinfo.append((category, path, os.stat(path).st_mtime))
        except OSError:
            continue
    return statinfo
コード例 #5
0
ファイル: gitcmds.py プロジェクト: dannyfeng/gitGUI
def all_files():
    """Return the names of all files in the repository"""
    ls_files = git.ls_files(z=True)
    if ls_files:
        return core.decode(ls_files[:-1]).split('\0')
    else:
        return []
コード例 #6
0
ファイル: git_repo.py プロジェクト: dannyfeng/gitGUI
 def set_worktree(self, worktree):
     self.git.set_worktree(worktree)
     is_valid = self.git.is_valid()
     if is_valid:
         basename = os.path.basename(self.git.worktree())
         self.project = core.decode(basename)
     return is_valid
コード例 #7
0
ファイル: git_repo.py プロジェクト: dannyfeng/gitGUI
    def config_dict(self, local=True):
        """parses the lines from git config --list into a dictionary"""

        kwargs = {
            'list': True,
            'global': not local, # global is a python keyword
        }
        config_lines = self.git.config(**kwargs).splitlines()
        newdict = {}
        for line in config_lines:
            try:
                k, v = line.split('=', 1)
            except:
                # value-less entry in .gitconfig
                continue
            v = core.decode(v)
            k = k.replace('.','_') # git -> model
            if v == 'true' or v == 'false':
                v = bool(eval(v.title()))
            try:
                v = int(eval(v))
            except:
                pass
            newdict[k]=v
        return newdict
コード例 #8
0
ファイル: gitcfg.py プロジェクト: dannyfeng/gitGUI
    def read_config(self, path):
        """Return git config data from a path as a dictionary."""
        dest = {}
        args = ('--null', '--file', path, '--list')
        config_lines = self.git.config(*args).split('\0')
        for line in config_lines:
            try:
                k, v = line.split('\n', 1)
            except ValueError:
                # the user has an invalid entry in their git config
                if not line:
                    continue
                k = line
                v = 'true'
            v = core.decode(v)

            if v in ('true', 'yes'):
                v = True
            elif v in ('false', 'no'):
                v = False
            else:
                try:
                    v = int(v)
                except ValueError:
                    pass
            dest[k.lower()] = v
        return dest
コード例 #9
0
ファイル: cmds.py プロジェクト: dannyfeng/gitGUI
 def __init__(self):
     Command.__init__(self)
     diff = self.model.git.diff(self.model.head,
                                unified=_config.get('diff.context', 3),
                                no_color=True,
                                M=True,
                                stat=True)
     self.new_diff_text = core.decode(diff)
     self.new_mode = self.model.mode_worktree
コード例 #10
0
ファイル: cmds.py プロジェクト: dannyfeng/gitGUI
 def __init__(self):
     Command.__init__(self)
     diff = self.model.git.diff(self.model.head,
                                cached=True,
                                no_color=True,
                                patch_with_stat=True,
                                M=True)
     self.new_diff_text = core.decode(diff)
     self.new_mode = self.model.mode_index
コード例 #11
0
ファイル: server.py プロジェクト: kevlubkcm/tenderpotato
    def check_tx(self, tx: bytes) -> ResponseCheckTx:
        try:
            message = decode(tx)
        except (SignatureError, TypeError, UnpicklingError) as e:
            return ResponseCheckTx(code=1, info='%s' % type(e))

        message_type = type(message.data)
        handler = self.handlers.get(message_type)
        if handler is None:
            return ResponseCheckTx(code=1, info='Unrecognized Type: %s' % message_type)

        return ResponseCheckTx(code=0)
コード例 #12
0
ファイル: cmds.py プロジェクト: dannyfeng/gitGUI
 def __init__(self):
     Command.__init__(self)
     untracked = self.model.untracked
     suffix = len(untracked) > 1 and 's' or ''
     io = StringIO()
     io.write('# %s untracked file%s\n' % (len(untracked), suffix))
     if untracked:
         io.write('# possible .gitignore rule%s:\n' % suffix)
         for u in untracked:
             io.write('/'+core.encode(u))
     self.new_diff_text = core.decode(io.getvalue())
     self.new_mode = self.model.mode_untracked
コード例 #13
0
ファイル: gitcmds.py プロジェクト: dannyfeng/gitGUI
def specified_diff_worktree(p):
    modified = []
    submodules = set()

    status, output = git.diff_files(p, z=True, with_status=True)
    if status != 0:
        # handle git init
        ls_files = core.decode(git.ls_files(p, modified=True, z=True))
        if ls_files:
            modified = ls_files[:-1].split('\0')
        return modified, submodules

    while output:
        rest, output = output.split('\0', 1)
        name, output = output.split('\0', 1)
        status = rest[-1]
        name = core.decode(name)
        if '160000' in rest[1:14]:
            submodules.add(name)
        elif status in 'DAMT':
            modified.append(name)

    return modified, submodules
コード例 #14
0
ファイル: gitcmds.py プロジェクト: dannyfeng/gitGUI
def all_refs(split=False, git=git):
    """Return a tuple of (local branches, remote branches, tags)."""
    local_branches = []
    remote_branches = []
    tags = []
    triple = lambda x, y: (x, len(x) + 1, y)
    query = (triple('refs/tags', tags),
             triple('refs/heads', local_branches),
             triple('refs/remotes', remote_branches))
    cmdout = core.decode(git.for_each_ref(format='%(refname)'))
    for ref in cmdout.splitlines():
        for prefix, prefix_len, dst in query:
            if ref.startswith(prefix) and not ref.endswith('/HEAD'):
                dst.append(ref[prefix_len:])
                continue
    if split:
        return local_branches, remote_branches, tags
    else:
        return local_branches + remote_branches + tags
コード例 #15
0
ファイル: gitcmds.py プロジェクト: dannyfeng/gitGUI
def _read_git_head(head, default='master', git=git):
    """Pure-python .git/HEAD reader"""
    # Legacy .git/HEAD symlinks
    if os.path.islink(head):
        refs_heads = os.path.realpath(git.git_path('refs', 'heads'))
        path = os.path.abspath(head).replace('\\', '/')
        if path.startswith(refs_heads + '/'):
            return path[len(refs_heads)+1:]

    # Common .git/HEAD "ref: refs/heads/master" file
    elif os.path.isfile(head):
        data = utils.slurp(core.decode(head)).rstrip()
        ref_prefix = 'ref: '
        if data.startswith(ref_prefix):
            return data[len(ref_prefix):]
        # Detached head
        return data

    return default
コード例 #16
0
ファイル: server.py プロジェクト: kevlubkcm/tenderpotato
 def deliver_tx(self, tx: bytes) -> ResponseDeliverTx:
     message = decode(tx)
     self.state, resp = self.handlers[type(message.data)].deliver_tx(self.state, message)
     return resp
コード例 #17
0
ファイル: client.py プロジェクト: kevlubkcm/tenderpotato
def query() -> State:
    r = requests.get('%s/abci_query' % URL)
    res = r.json()['result']['response']
    return decode(base64.b64decode(res['value'])).data
コード例 #18
0
ファイル: utils.py プロジェクト: dannyfeng/gitGUI
def slurp(path):
    """Slurps a filepath into a string."""
    fh = open(core.encode(path))
    slushy = core.read(fh)
    fh.close()
    return core.decode(slushy)
コード例 #19
0
ファイル: git_repo.py プロジェクト: dannyfeng/gitGUI
 def prev_commitmsg(self, *args):
     """Queries git for the latest commit message."""
     log = self.git.log('-1', no_color=True, pretty='format:%s%n%n%b', *args)
     return core.decode(log)
コード例 #20
0
ファイル: utils.py プロジェクト: dannyfeng/gitGUI
def shell_usplit(s):
    """Returns a unicode list instead of encoded strings"""
    return [core.decode(arg) for arg in shell_split(s)]
コード例 #21
0
checkVersion()

print(header1)
print(mainOption)

try:
    while True:
        choice = input("")

        if choice.lower() == 'c':
            clear()
            print(header1)
            print(mainOption)
        elif choice.lower() == "e" or choice.lower() == "exit":
            sys.exit(Fore.RED + "\nHave a good day ! :)")
            print(Style.RESET_ALL)
        elif choice.lower() == '1':
            clear()
            encode()
            print(header1)
            print(mainOption)
        elif choice.lower() == '2':
            clear()
            decode()
            print(header1)
            print(mainOption)

except KeyboardInterrupt:
    sys.exit(Fore.RED + "\nHave a good day ! :)")
    print(Style.RESET_ALL)
コード例 #22
0
ファイル: gitcmds.py プロジェクト: dannyfeng/gitGUI
def diff_info(sha1, git=git):
    log = git.log('-1', '--pretty=format:%b', sha1)
    decoded = core.decode(log).strip()
    if decoded:
        decoded += '\n\n'
    return decoded + sha1_diff(sha1)
コード例 #23
0
ファイル: gitcmds.py プロジェクト: dannyfeng/gitGUI
def specified_untracked_files(p):
    """Returns a sorted list of untracked files."""
    ls_files = git.ls_files(p, z=True, others=True, exclude_standard=True)
    if ls_files:
        return core.decode(ls_files[:-1]).split('\0')
    return []
コード例 #24
0
ファイル: gitcmds.py プロジェクト: dannyfeng/gitGUI
def eval_path(path):
    """handles quoted paths."""
    if path.startswith('"') and path.endswith('"'):
        return core.decode(eval(path))
    else:
        return core.decode(path)
コード例 #25
0
ファイル: gitcmds.py プロジェクト: dannyfeng/gitGUI
def for_each_ref_basename(refs, git=git):
    """Return refs starting with 'refs'."""
    git_output = git.for_each_ref(refs, format='%(refname)')
    output = core.decode(git_output).splitlines()
    non_heads = filter(lambda x: not x.endswith('/HEAD'), output)
    return map(lambda x: x[len(refs) + 1:], non_heads)
コード例 #26
0
ファイル: gitcmds.py プロジェクト: dannyfeng/gitGUI
def _parse_diff_filenames(diff_zstr):
    if diff_zstr:
        return core.decode(diff_zstr[:-1]).split('\0')
    else:
        return []
コード例 #27
0
ファイル: cmds.py プロジェクト: dannyfeng/gitGUI
 def __init__(self, txt):
     """Perform a git-grep."""
     Command.__init__(self)
     self.new_mode = self.model.mode_grep
     self.new_diff_text = core.decode(self.model.git.grep(txt, n=True))
コード例 #28
0
ファイル: gitcmds.py プロジェクト: dannyfeng/gitGUI
def diff_helper(commit=None,
                ref=None,
                endref=None,
                filename=None,
                cached=True,
                head=None,
                amending=False,
                with_diff_header=False,
                suppress_header=True,
                reverse=False,
                git=git):
    "Invokes git diff on a filepath."
    encode = core.encode
    if commit:
        ref, endref = commit+'^', commit
    argv = []
    if ref and endref:
        argv.append('%s..%s' % (ref, endref))
    elif ref:
        for r in utils.shell_split(ref.strip()):
            argv.append(r)
    elif head and amending and cached:
        argv.append(head)

    if filename:
        argv.append('--')
        if type(filename) is list:
            argv.extend(filename)
        else:
            argv.append(filename)

    start = False
    del_tag = 'deleted file mode '

    headers = []
    if filename is not None:
        deleted = cached and not os.path.exists(encode(filename))
    else:
        deleted = False

    status, diffoutput = git.diff(R=reverse, M=True, cached=cached,
                                  with_status=True,
                                  *argv, **_common_diff_opts())
    if status != 0:
        # git init
        if with_diff_header:
            return ('', '')
        else:
            return ''

    if diffoutput.startswith('Submodule'):
        if with_diff_header:
            return ('', diffoutput)
        else:
            return diffoutput

    output = StringIO()

    diff = core.decode(diffoutput).split('\n')
    for line in diff:
        if not start and '@@' == line[:2] and '@@' in line[2:]:
            start = True
        if start or (deleted and del_tag in line):
            output.write(encode(line) + '\n')
        else:
            if with_diff_header:
                headers.append(encode(line))
            elif not suppress_header:
                output.write(encode(line) + '\n')

    result = core.decode(output.getvalue())
    output.close()

    if with_diff_header:
        return('\n'.join(headers), result)
    else:
        return result
コード例 #29
0
ファイル: gitcmds.py プロジェクト: dannyfeng/gitGUI
def sha1_diff(sha1, git=git):
    return core.decode(git.diff(sha1 + '^!', **_common_diff_opts()))