Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Save filenames to history

  • Loading branch information...
commit 3816072563c19200386c83c6ef7af10c93fdeec6 1 parent 19a579f
Giles Lavelle authored April 30, 2012
2  readme.md
Source Rendered
@@ -10,7 +10,7 @@ It has only been primarily tested on Windows but most functionality also works o
10 10
 - `up </path/to/file/or/folder> [second file, third file...]`: Upload the specified files and folders.
11 11
 - `snap [-m mode]`: Take a screenshot and upload it. Mode can be `draw` or `screen`. Defaults to `screen`.
12 12
 - `history [-l number_of_records] [-t sort_by] [-b start] [-d direction]`: Show a history of the files you've uploaded previously. Defaults to the last 10 records.
13  
-- `revisit <operation> <id>`: Do something with a previously uploaded file. `id` specifies which file to upload. `operation` can be either `reupload`, `open_remote` or `open_local`.
  13
+- `revisit <operation> <id>`: Do something with a previously uploaded file. `id` specifies which file to upload. `operation` can be either `upload`, `remote` or `local`.
14 14
 - `text [-e extension]`: Share the contents of your clipboard. Currently uploads to Dropbox, support for Github Gists planned. Extenstion defaults to `txt`.
15 15
 
16 16
 ##Options:
2  src/clipcloud.py
@@ -56,7 +56,7 @@ def clipcloud():
56 56
     # Create the parser for options that only apply to revisiting old uploads
57 57
     revisit_parser = subparsers.add_parser('revisit')
58 58
     revisit_parser.add_argument('operation',
59  
-        choices=['open_local', 'open_remote', 'reupload'])
  59
+        choices=['local', 'remote', 'upload'])
60 60
     revisit_parser.add_argument('id', type=int)
61 61
     revisit_parser.set_defaults(func=revisit)
62 62
 
16  src/lib/history.py
@@ -25,7 +25,12 @@ def display(self, limit, sort_by, direction, start):
25 25
         - start: the record number to start at
26 26
         """
27 27
 
28  
-        history = sorted(self.history.doc['history'], key=lambda k: k[sort_by], reverse=direction == 'd')
  28
+        history = self.history.doc['history']
  29
+        if len(history) < 1:
  30
+            print 'No records to display'
  31
+            return
  32
+
  33
+        history = sorted(history, key=lambda k: k[sort_by], reverse=direction == 'd')
29 34
         grid = [['Id', 'URL', 'Local File', 'Date Created']]
30 35
 
31 36
         # iterate through the array of records, parse them and create a new 2d array of the formatted values
@@ -46,7 +51,7 @@ def display(self, limit, sort_by, direction, start):
46 51
 
47 52
         print format_grid(grid, divider_positions=[1], truncatable_column=2)
48 53
 
49  
-    def add(self, path, url):
  54
+    def add(self, path, filename, url):
50 55
         """
51 56
         Write a new record to the history
52 57
 
@@ -58,12 +63,13 @@ def add(self, path, url):
58 63
         history = self.history.doc['history']
59 64
 
60 65
         id_ = 1 if len(history) == 0 else history[-1]['id'] + 1
61  
-
62  
-        history.append({
  66
+        record = {
63 67
             'id': id_,
64 68
             'path': path,
  69
+            'filename': filename,
65 70
             'url': url,
66 71
             'timestamp': time()
67  
-        })
  72
+        }
68 73
 
  74
+        history.append(record)
69 75
         self.history.save()
28  src/lib/main.py
@@ -12,7 +12,7 @@
12 12
 from dbox import Dropbox
13 13
 
14 14
 
15  
-def save_link(link, paths, share_to):
  15
+def save_link(link, paths, filenames, share_to):
16 16
     """
17 17
     Save the details of an uploaded file to the history file and send the link to its destination
18 18
 
@@ -25,8 +25,8 @@ def save_link(link, paths, share_to):
25 25
         return
26 26
 
27 27
     # save a record of it to the history,
28  
-    for path in paths:
29  
-        History().add(path, link)
  28
+    for path, filename in zip(paths, filenames):
  29
+        History().add(path, filename, link)
30 30
 
31 31
     # and then send the link to its destination, be that clipboard or social network.
32 32
     if share_to == 'clipboard':
@@ -112,7 +112,7 @@ def handle_files(paths, filenames, share_to):
112 112
         link = d.get_link('/' + d.final_folder_name)
113 113
         local_paths = [os.path.abspath(file_) for file_ in files]
114 114
 
115  
-    save_link(link, local_paths, share_to)
  115
+    save_link(link, local_paths, filenames, share_to)
116 116
 
117 117
 
118 118
 def screenshot(args):
@@ -133,6 +133,9 @@ def upload(args):
133 133
 def snippet(args):
134 134
     """Upload the contents of the user's clipboard as a text file"""
135 135
 
  136
+    # gist functionality on hold - dropbox works fine for now
  137
+    # from gist import Gist
  138
+
136 139
     clipboard = Clipboard().get()
137 140
     if clipboard is None:
138 141
         return
@@ -147,6 +150,9 @@ def snippet(args):
147 150
 
148 151
         handle_files([path], [filename], args.share)
149 152
 
  153
+    #elif args.text == 'gist':
  154
+    #    Gist().upload(filename, clipboard)
  155
+
150 156
 
151 157
 def history(args):
152 158
     """Display the history of previously uploaded file"""
@@ -167,14 +173,16 @@ def revisit(args):
167 173
         print 'Type clipcloud history to see what files you have saved'
168 174
         return
169 175
 
170  
-    if args.operation == 'reupload':
171  
-        handle_file([record['path']], [record['path']], 'clipboard')
  176
+    path = record['path']
  177
+
  178
+    if args.operation == 'upload':
  179
+        handle_files([path], [record['filename']], 'clipboard')
172 180
 
173  
-    elif args.operation == 'open_local':
  181
+    elif args.operation == 'local':
174 182
         if PLATFORM == 'Windows':
175  
-            Popen(r'explorer /select,"%s"' % record['path'])
  183
+            Popen(r'explorer /select,"%s"' % path)
176 184
         elif PLATFORM == 'Darwin':
177  
-            call(['open', '-R', record['path']])
  185
+            call(['open', '-R', path])
178 186
 
179  
-    elif args.operation == 'open_remote':
  187
+    elif args.operation == 'remote':
180 188
         webbrowser.open(record['url'], new=2)
4  src/lib/pyjson.py
@@ -29,7 +29,7 @@ def __init__(self, path, base={}):
29 29
 
30 30
         if not os.path.exists(path):
31 31
             f = open(path, 'w')
32  
-            f.write(json.dumps(base, sort_keys=True, indent=4))
  32
+            f.write(json.dumps(base, indent=4))
33 33
             f.close()
34 34
 
35 35
         f = open(path, 'r')
@@ -53,5 +53,5 @@ def save(self):
53 53
         """Save a json representation of the Python dictionary to the file"""
54 54
 
55 55
         f = open(self.path, 'w')
56  
-        f.write(json.dumps(self.doc, sort_keys=True, indent=4))
  56
+        f.write(json.dumps(self.doc, indent=4))
57 57
         f.close()

0 notes on commit 3816072

Please sign in to comment.
Something went wrong with that request. Please try again.