about summary refs log tree commit diff stats
path: root/counters.mu
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2015-03-10 12:16:28 -0700
committerKartik K. Agaram <vc@akkartik.com>2015-03-10 12:16:28 -0700
commitf00fc595cb7127727061e643090c8c38ab727f85 (patch)
tree4177d3e937308af5f0cde7e19762b301bf63ea1d /counters.mu
parentab67ac1354e82b4843c9b68df05bfb65f67f54d0 (diff)
downloadmu-f00fc595cb7127727061e643090c8c38ab727f85.tar.gz
880 - new personal convention: capitalize names in prose
Diffstat (limited to 'counters.mu')
0 files changed, 0 insertions, 0 deletions
href='/akspecs/ranger/blame/ranger/core/linemode.py?h=v1.9.3&id=76791a70467d7223a966aa9f12f5583b01d704a8'>^
fcfea319 ^
6b7b9d5d ^
fc3a9e97 ^
0270a123 ^
19ee5a74 ^

19ee5a74 ^





















916c2390 ^
19ee5a74 ^


916c2390 ^
3374b0e7 ^



bbfecf0a ^


3374b0e7 ^



19ee5a74 ^


b3d031a9 ^
19ee5a74 ^

916c2390 ^

19ee5a74 ^
19ee5a74 ^





916c2390 ^
dff0e71b ^
19ee5a74 ^

84a22ae0 ^
19ee5a74 ^
916c2390 ^
19ee5a74 ^










916c2390 ^
51ec08da ^

19ee5a74 ^
916c2390 ^
19ee5a74 ^
1b5c7bd5 ^




916c2390 ^

1b5c7bd5 ^
916c2390 ^

b3d031a9 ^
c8471088 ^
d07c60e4 ^
c8471088 ^

1b5c7bd5 ^


fcfea319 ^
ab41c776 ^
fcfea319 ^


916c2390 ^

fcfea319 ^
916c2390 ^
9f5c0d63 ^

916c2390 ^
fcfea319 ^
ab41c776 ^
fcfea319 ^


916c2390 ^

fcfea319 ^
916c2390 ^
9f5c0d63 ^

916c2390 ^

6f3dd655 ^

fc3a9e97 ^

6f3dd655 ^






fc3a9e97 ^
6f3dd655 ^

fc3a9e97 ^

6f3dd655 ^







fc3a9e97 ^
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
                       


                                                                 
 
                                                                  
 
                                                         
                             
 
                                                                         
                            

                             





















                                                                                
                                        


                                                
                                         



                                                                    


                                                                     



                                                                  


                                 
                                                                       

                     

                                        
 





                                  
                                        
                             

                                                    
                   
 
                                         










                                                                     
                                        

                                                                                    
 
                                         
                 




                                     

                                        
 

                                         
                                                     
                
                                                                                 

                                      


                                     
 
 


                                  

                                        
 
                                         

                             
                                                                                    
 
 


                                      

                                        
 
                                         

                             

                                                                                                

 

                                               






                                         
                                                      

 

                                                   







                                         
                                                                          
# -*- coding: utf-8 -*-
# This file is part of ranger, the console file manager.
# License: GNU GPL version 3, see the file "AUTHORS" for details.
# Author: Wojciech Siewierski <wojciech.siewierski@onet.pl>, 2015

from __future__ import (absolute_import, division, print_function)

from abc import ABCMeta, abstractproperty, abstractmethod
from datetime import datetime

from ranger.ext.human_readable import human_readable, human_readable_time
from ranger.ext import spawn

DEFAULT_LINEMODE = "filename"


class LinemodeBase(object):
    """Supplies the file line contents for BrowserColumn.

    Attributes:
        name (required!) - Name by which the linemode is referred to by the user

        uses_metadata - True if metadata should to be loaded for this linemode

        required_metadata -
            If any of these metadata fields are absent, fall back to
            the default linemode
    """
    __metaclass__ = ABCMeta

    uses_metadata = False
    required_metadata = []

    name = abstractproperty()

    @abstractmethod
    def filetitle(self, fobj, metadata):
        """The left-aligned part of the line."""
        raise NotImplementedError

    def infostring(self, fobj, metadata):
        """The right-aligned part of the line.

        If `NotImplementedError' is raised (e.g. this method is just
        not implemented in the actual linemode), the caller should
        provide its own implementation (which in this case means
        displaying the hardlink count of the directories, size of the
        files and additionally a symlink marker for symlinks). Useful
        because only the caller (BrowserColumn) possesses the data
        necessary to display that information.

        """
        raise NotImplementedError


class DefaultLinemode(LinemodeBase):  # pylint: disable=abstract-method
    name = "filename"

    def filetitle(self, fobj, metadata):
        return fobj.relative_path


class TitleLinemode(LinemodeBase):
    name = "metatitle"
    uses_metadata = True
    required_metadata = ["title"]

    def filetitle(self, fobj, metadata):
        name = metadata.title
        if metadata.year:
            return "%s - %s" % (metadata.year, name)
        return name

    def infostring(self, fobj, metadata):
        if metadata.authors:
            authorstring = metadata.authors
            if ',' in authorstring:
                authorstring = authorstring[0:authorstring.find(",")]
            return authorstring
        return ""


class PermissionsLinemode(LinemodeBase):
    name = "permissions"

    def filetitle(self, fobj, metadata):
        return "%s %s %s %s" % (
            fobj.get_permission_string(), fobj.user, fobj.group, fobj.relative_path)

    def infostring(self, fobj, metadata):
        return ""


class FileInfoLinemode(LinemodeBase):
    name = "fileinfo"

    def filetitle(self, fobj, metadata):
        return fobj.relative_path

    def infostring(self, fobj, metadata):
        if not fobj.is_directory:
            from subprocess import CalledProcessError
            try:
                fileinfo = spawn.check_output(["file", "-Lb", fobj.path]).strip()
            except CalledProcessError:
                return "unknown"
            return fileinfo
        else:
            raise NotImplementedError


class MtimeLinemode(LinemodeBase):
    name = "mtime"

    def filetitle(self, fobj, metadata):
        return fobj.relative_path

    def infostring(self, fobj, metadata):
        if fobj.stat is None:
            return '?'
        return datetime.fromtimestamp(fobj.stat.st_mtime).strftime("%Y-%m-%d %H:%M")


class SizeMtimeLinemode(LinemodeBase):
    name = "sizemtime"

    def filetitle(self, fobj, metadata):
        return fobj.relative_path

    def infostring(self, fobj, metadata):
        if fobj.stat is None:
            return '?'
        return "%s %s" % (human_readable(fobj.size),
                          datetime.fromtimestamp(fobj.stat.st_mtime).strftime("%Y-%m-%d %H:%M"))


class HumanReadableMtimeLinemode(LinemodeBase):
    name = "humanreadablemtime"

    def filetitle(self, fobj, metadata):
        return fobj.relative_path

    def infostring(self, fobj, metadata):
        if fobj.stat is None:
            return '?'
        return human_readable_time(fobj.stat.st_mtime)


class SizeHumanReadableMtimeLinemode(LinemodeBase):
    name = "sizehumanreadablemtime"

    def filetitle(self, fobj, metadata):
        return fobj.relative_path

    def infostring(self, fobj, metadata):
        if fobj.stat is None:
            return '?'
        size = human_readable(fobj.size)
        return "%s %11s" % (size, human_readable_time(fobj.stat.st_mtime))