-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpickler.py
More file actions
56 lines (44 loc) · 1.65 KB
/
pickler.py
File metadata and controls
56 lines (44 loc) · 1.65 KB
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
# pickler.py
# Created by frankV
# this file is part of PythonPubCrawler
# https://github.com/frankV/pythonpubcrawl
""" pickler.py -- archive serializer """
import os, collections
import cPickle as pickle
# ---------------------------------------------------------------------------- #
# function - pickleDump
# saves "files" and "extensions" dict to a file
# ---------------------------------------------------------------------------- #
def pickleDump():
global files, extensions
print 'pickling...'
pickle.dump( files, open( "filesdict.p", "wb" ) )
pickle.dump( extensions, open( "extensionsdict.p", "wb" ) )
# ---------------------------------------------------------------------------- #
# function - pickleLoad
# loads "files" and "extensions" dict from a file
# ---------------------------------------------------------------------------- #
def pickleLoad():
files = {}
extensions = collections.defaultdict(int)
cwd = os.getcwd()
fileDictPickle = str(cwd) + '/filesdict.p'
extDictPickle = str(cwd) + '/extensionsdict.p'
print 'Loading files...'
files = pickle.load( open( fileDictPickle, "rb" ) )
print 'Loading extensions...'
extensions = pickle.load( open( extDictPickle, "rb" ) )
# ---------------------------------------------------------------------------- #
# function - pickleTry
# checks to see if pickled files already exist
# ---------------------------------------------------------------------------- #
def pickleTry():
cwd = os.getcwd()
try:
with open(cwd+'/filesdict.p') as f:
pass
print 'pickle found'
return True
except IOError as e:
print 'pickle not found'
return False