This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import logging | |
import os | |
SCRIPT_ID = 'name_of_your_script' | |
logger = logging.getLogger(SCRIPT_ID) | |
def setup_logging(filename, loglevel='INFO'): | |
""" | |
Set up logging to a file on disk and with a proper log format. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import shlex | |
import subprocess | |
def run_cmd(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, block=True, *args, **kwargs): | |
""" | |
Run a command using the subprocess module. | |
:param cmd: command to be executed | |
:type cmd: str or list | |
:return: process object |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
def iter_parent_dirs(endpath): | |
previous = '' | |
basepath = endpath | |
while previous != '/': | |
yield basepath | |
previous = basepath | |
basepath, _ = os.path.split(basepath) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def format_duration(seconds): | |
""" | |
Format a duration given in seconds as a string expressing the number of hours, minutes and seconds | |
:param seconds: duration in seconds | |
:type seconds: int or float | |
:returns: str | |
""" | |
minutes = int(seconds / 60) | |
if minutes > 0: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
try: | |
from termcolor import colored | |
except ImportError: | |
def colored(msg, *args, **kwargs): | |
return msg | |
def print_info(msg, color='', *args, **kwargs): | |
if color == '': |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Show hidden characters
// Settings in here override those in "Default/Preferences.sublime-settings", | |
// and are overridden in turn by file type specific settings. | |
{ | |
// Columns in which to display vertical rulers | |
"rulers": [80], | |
// Set to true to turn spell checking on by default | |
"spell_check": true, | |
// The number of spaces a tab is considered equal to |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#-*- coding: utf-8 -*- | |
from django import forms | |
from models import User | |
class PasswordField(forms.CharField): | |
def __init__(self): | |
super(PasswordField, self).__init__(widget=forms.PasswordInput) | |
class LoginForm(forms.Form): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
#-*- coding: utf-8 -*- | |
import sys | |
import os | |
import subprocess | |
import argparse | |
def decode_retval(retval): | |
retval_meanings = { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
all: pdf2 bib pdf open | |
@#@echo -e "\aSe ha generado el PDF." | |
pdf: | |
pdflatex mi_documento | |
pdf2: | |
pdflatex mi_documento | |
pdflatex mi_documento |