Esempio n. 1
0
def _main():
    paths = list(ifilter(exists, argv[1:]))
    if not paths:
        exit1(__doc__[1:-1])

    for path in paths:
        move_to_trash(path)
Esempio n. 2
0
def _main():
    # get movie paths
    # `list(imap(...))` is better than `map(...)`, because it's more py3ish :)
    paths = list(imap(quote, ifilter(isfile, argv[1:])))
    if not paths:
        exit1(__doc__[1:-1])

    if len(paths) == 1:
        print get_duration(paths[0])
    else:
        for path in paths:
            print get_duration(path), path
Esempio n. 3
0
def _main():
    # parse command line arguments
    try:
        extension = argv[1]
    except IndexError:
        exit1(__doc__[1:-1])

    # set format
    if extension == 'tar.bz2':
        format = 'tar'
        pipe = '| bzip2'
    elif extension == 'zip':
        format = 'zip'
        pipe = ''
    else:
        exit1(__doc__[1:-1])

    # check if you are within Git repository
    try:
        Git()
    except EnvironmentError:
        no_repo = True
    else:
        no_repo = False

    # create repository
    if no_repo:
        system('git init --quiet && ' \
               'git add . && ' \
               'git commit --quiet --message="waka waka"')

    # get working directory name and strip initial dot
    directory = basename(realpath('.')).lstrip('.')

    # create archive
    archive = '{directory}.{extension}'.format(**locals())
    system('git archive --format={format} --prefix={directory}/ HEAD ' \
           '{pipe} > {archive} && echo {archive}'.format(**locals()))

    # remove repository
    if no_repo:
        system('rm -rf .git')
Esempio n. 4
0
def _main():
    # read arguments
    try:
        action = argv[1]
        filepath = realpath(expanduser(argv[2]))
    except IndexError:
        exit1(__doc__[1:-1])

    # validate arguments
    if action not in ['copy', 'move']:
        exit1(__doc__[1:-1])
    if not isfile(filepath):
        exit1("'{0}' is not a path to an existing file".format(filepath))

    # do the magic
    if action == 'copy':
        copy_to_public_dropbox(filepath)
    elif action == 'move':
        move_to_public_dropbox(filepath)
Esempio n. 5
0
def _main():
    # take hostage
    try:
        pdf_to_enlarge = quote(realpath(argv[1]))
    except IndexError:
        exit1(__doc__[1:-1])

    # get your gun
    width = 10.5
    height = 14.85

    horizontal_margin = width * (2 - SCALE)
    vertical_margin = height * (2 - SCALE)

    horizontal_line = width * SCALE
    vertical_line = height * SCALE

    tex = Template(r"""
\documentclass{article}

% disable margins
\usepackage{geometry}
\geometry{
    a4paper,
    textheight = 29.7cm,
    textwidth = 21cm
}
\setlength{\parindent}{0}

% allow magic
\usepackage{tikz}

\begin{document}
    % left top
    \begin{tikzpicture}
        \node[inner sep=0pt, above right] {
            \includegraphics*[trim=0 $h $w 0, scale=$scale]{$a4}
        };
        \draw[dashed] (0,0) -- ($hl,0) -- ($hl,$vl);
    \end{tikzpicture}
    \newpage

    % right top
    \begin{tikzpicture}
        \hspace*{$hm}
        \node[inner sep=0pt, above right] {
            \includegraphics*[trim=$w $h 0 0, scale=$scale]{$a4}
        };
        \draw[dashed] (0,$vl) -- (0,0) -- ($hl,0);
    \end{tikzpicture}
    \newpage

    % left bottom
    \vspace*{$vm}
    \begin{tikzpicture}
        \node[inner sep=0pt, above right] {
            \includegraphics*[trim=0 0 $w $h, scale=$scale]{$a4}
        };
        \draw[dashed] (0,$vl) -- ($hl,$vl) -- ($hl,0);
    \end{tikzpicture}
    \newpage

    % right bottom
    \vspace*{$vm}
    \begin{tikzpicture}
        \hspace*{$hm}
        \node[inner sep=0pt, above right] {
            \includegraphics*[trim=$w 0 0 $h, scale=$scale]{$a4}
        };
        \draw[dashed] (0,0) -- (0,$vl) -- ($hl,$vl);
    \end{tikzpicture}
\end{document}
    """).substitute(
        a4=pdf_to_enlarge, scale=SCALE,
        w=cm(width), h=cm(height),
        hm=cm(horizontal_margin), vm=cm(vertical_margin),
        hl=cm(horizontal_line), vl=cm(vertical_line)
    )

    # avoid witnesses
    temp_dir = mkdtemp()

    # know your enemy
    source_pdf = join(temp_dir, 'texput.pdf')
    target_pdf = realpath('a2.pdf')

    # down rodeo
    command = ';'.join([
        'cd ' + temp_dir,
        'echo -n "{0}" | pdflatex'.format(tex),
        'mv {0} {1}'.format(source_pdf, target_pdf)
    ])

    # use silencer
    Popen(command, shell=True, stdout=PIPE).communicate()

    # burn the evidence
    rmtree(temp_dir)