Changeset 10677


Ignore:
Timestamp:
31 Oct 2013, 17:58:03 (11 years ago)
Author:
uli
Message:

PEP8.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.kofa/trunk/src/waeup/kofa/utils/helpers.py

    r10676 r10677  
    1818"""General helper functions for Kofa.
    1919"""
    20 import unicodecsv as csv # XXX: csv ops should move to dedicated module.
     20import unicodecsv as csv  # XXX: csv ops should move to dedicated module.
    2121import datetime
    2222import imghdr
     
    4343BUFSIZE = 8 * 1024
    4444
     45
    4546def remove_file_or_directory(filepath):
    4647    """Remove a file or directory.
     
    5859        os.unlink(filepath)
    5960    return
     61
    6062
    6163def copy_filesystem_tree(src, dst, overwrite=False, del_old=False):
     
    8688    for item in os.listdir(src):
    8789        if item.startswith('.'):
    88             continue # We do not copy hidden stuff...
     90            continue  # We do not copy hidden stuff...
    8991        itemsrc = os.path.join(src, item)
    9092        itemdst = os.path.join(dst, item)
     
    151153    return html_code
    152154
     155
    153156class FactoryBase(grok.GlobalUtility):
    154157    """A factory for things.
     
    226229
    227230    """
    228     grok.baseclass() # Do not grok this class, do not register us.
     231    grok.baseclass()  # Do not grok this class, do not register us.
    229232    grok.implements(IFactory)
    230233    # You can override any of the following attributes in derived
     
    246249        # Required by IFactory
    247250        return implementedBy(self.factory)
     251
    248252
    249253def ReST2HTML_w_warnings(source_string):
     
    324328    if warning_msgs:
    325329        # Render again, this time with no warnings inline...
    326         fulldoc =  publish_string(
     330        fulldoc = publish_string(
    327331        source_string, writer_name='html4css1',
    328332        settings_overrides={
     
    337341        result = result.decode('utf-8')
    338342    return result, warning_msgs
     343
    339344
    340345def ReST2HTML(source_string):
     
    384389    return html
    385390
     391
    386392def attrs_to_fields(cls, omit=[]):
    387393    """Turn the attributes of a class into FieldProperty instances.
     
    399405    return cls
    400406
     407
    401408def get_current_principal():
    402409    """Get the 'current' principal.
     
    416423    except NoInteraction:
    417424        return None
    418     except IndexError: # No participations present
     425    except IndexError:  # No participations present
    419426        return None
    420427    return principal
     428
    421429
    422430def cmp_files(file_descr1, file_descr2):
     
    435443            return True
    436444
     445
    437446def string_from_bytes(number):
    438447    """Turn a number into some textual representation.
     
    455464    if number < 1024:
    456465        return u'%s byte(s)' % (str(number),)
    457     elif number < 1024**2:
     466    elif number < 1024 ** 2:
    458467        return u'%s KB' % (number / 1024,)
    459     elif number < 1024**3:
    460         return u'%.2f MB' % (number / 1024**2,)
    461     return u'%.2f GB' % (number / 1024**3,)
     468    elif number < 1024 ** 3:
     469        return u'%.2f MB' % (number / 1024 ** 2,)
     470    return u'%.2f GB' % (number / 1024 ** 3,)
     471
    462472
    463473def file_size(file_like_obj):
     
    480490    if hasattr(file_like_obj, 'fileno'):
    481491        return os.fstat(file_like_obj.fileno())[6]
    482     file_like_obj.seek(0, 2) # seek to last position in file
     492    file_like_obj.seek(0, 2)  # seek to last position in file
    483493    return file_like_obj.tell()
     494
    484495
    485496def get_user_account(request):
     
    490501    account = authenticator.getAccount(principal_id)
    491502    return account
     503
    492504
    493505def iface_names(iface, omit=[], exclude_attribs=True, exclude_methods=True):
     
    531543    return result
    532544
     545
    533546def get_sorted_preferred(tuples_iterable, preferred_list):
    534547    """Get a list of tuples (<TITLE>,<TOKEN>) with values in
     
    573586    return tuple(result)
    574587
     588
    575589def now(tz=None):
    576590    """Get current datetime in timezone of `tz`.
     
    581595    """
    582596    return to_timezone(datetime.datetime.utcnow(), tz=tz)
     597
    583598
    584599def to_timezone(dt, tz=None):
     
    600615        dt = pytz.utc.localize(dt)
    601616    return tz.normalize(dt.tzinfo.normalize(dt).astimezone(tz))
     617
    602618
    603619def get_fileformat(path, bytestream=None):
     
    633649    return img_type
    634650
     651
    635652def check_pdf(bytestream, file):
    636653    """Tell whether a file or bytestream is a PDF file.
     
    650667if check_pdf not in imghdr.tests:
    651668    imghdr.tests.append(check_pdf)
     669
    652670
    653671def merge_csv_files(path1, path2):
     
    685703    wp, tmp_path = tempfile.mkstemp()
    686704    writer = csv.DictWriter(os.fdopen(wp, 'wb'), fieldnames)
    687     writer.writerow(dict((x,x) for x in fieldnames)) # header
     705    writer.writerow(dict((x, x) for x in fieldnames)) # header
    688706    for row in reader1:
    689707        writer.writerow(row)
     
    691709        writer.writerow(row)
    692710    return tmp_path
     711
    693712
    694713def product(sequence, start=1):
     
    703722        result *= item
    704723    return result
     724
    705725
    706726class NullHandler(logging.Handler):
Note: See TracChangeset for help on using the changeset viewer.