Skip to content

Commit be4c3b9

Browse files
committed
update_change is now smarter
1 parent 4f4e07d commit be4c3b9

File tree

5 files changed

+121
-101
lines changed

5 files changed

+121
-101
lines changed

syncboostnote/bns.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
BOOSTNOTE_PATH: default # default: /home/$USER/Boostnote
2-
FREQUENCY: hourly # ["hourly", "daily", "weekly", "onchange", "manual"]
2+
FREQUENCY: manual # ["hourly", "daily", "weekly", "onchange", "manual"] Others will be implemented soon.
33
SHIELDS: true
4-
SHIELDS_TYPE: for-the-badge # default: for-the-badge
5-
TIME: 1200
4+
SHIELDS_TYPE: for-the-badge # ['plastic' , 'flat', 'flat-square', 'for-the-badge', 'popout', 'popout-square', 'social']
5+
# TIME: 1200 Not recommended

syncboostnote/cli.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import yaml
1212
from colorama import Fore, init
1313

14-
from .config import Config, config_reader, interactive
14+
from .config import Config, config_reader, interactive, generate_config
1515
from .utils import initialize
1616
from .test import sync
1717

@@ -41,12 +41,12 @@ def options():
4141
help="Location of the BoostNotes local storage.",
4242
default=os.path.join(home, 'Boostnote'))
4343

44-
ap.add_argument(
45-
"-ini",
46-
"--init",
47-
required=False,
48-
help="Initialise the CLI",
49-
default=False)
44+
# ap.add_argument(
45+
# "-ini",
46+
# "--init",
47+
# required=False,
48+
# help="Initialise the CLI",
49+
# default=False)
5050

5151
ap.add_argument(
5252
"--sync",
@@ -55,18 +55,18 @@ def options():
5555
)
5656

5757
ap.add_argument(
58-
"-cus",
59-
"--custom",
58+
"-co",
59+
"--config",
6060
required=False,
6161
help="Location of the config.yaml/config.yml file",
6262
default=False)
6363

6464
ap.add_argument(
6565
"-g",
6666
"--generate",
67-
required=False,
6867
help="Generate config.yaml file for ya",
69-
default=False)
68+
action='store_true'
69+
)
7070

7171
ap.add_argument(
7272
"-i",
@@ -85,8 +85,10 @@ def starter(args):
8585
'''
8686
if args['sync']:
8787
sync()
88+
elif args['generate']:
89+
return generate_config()
90+
8891
elif args['interactive']:
89-
print('>>> Interactive <<<')
9092
return interactive()
9193

9294
elif args['location']:

syncboostnote/config.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,15 @@ def hook():
5858
return result
5959

6060

61-
def create_config(location='.'):
61+
def generate_config():
6262
'''
6363
Creates a default config for users to see.
6464
'''
65-
yaml.dump(
66-
Config,
67-
open(os.path.join(location, 'bns.yaml'), 'w+')
68-
)
69-
70-
71-
# create_config()
65+
open(
66+
'config.yaml', 'w+'
67+
).write('''BOOSTNOTE_PATH: default # default: /home/$USER/Boostnote
68+
FREQUENCY: manual # ["hourly", "daily", "weekly", "onchange", "manual"] Others will be implemented soon.
69+
SHIELDS: true
70+
SHIELDS_TYPE: for-the-badge # ['plastic' , 'flat', 'flat-square', 'for-the-badge', 'popout', 'popout-square', 'social']
71+
# TIME: 1200 Not recommended
72+
''')

syncboostnote/test.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,18 @@ def sync(
2424
os.system("git push origin master")
2525
else:
2626
print("Adding all the things")
27-
os.system("git add -A")
27+
p = subprocess.Popen(
28+
"git add -A", shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
29+
2830
# print("Commiting all the things")
29-
os.system("git commit -m '.'")
31+
p1 = subprocess.Popen(
32+
f"git commit -m '{datetime.now()}'", shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
33+
for line in p1.stdout.readlines()[2:]:
34+
print(line.decode("utf-8"))
35+
3036
# print("Pushing all the things")
31-
os.system("git push origin master")
37+
p2 = subprocess.Popen(
38+
"git push origin master", shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
3239

3340
retval = p.wait()
3441

syncboostnote/utils.py

Lines changed: 85 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from glob import glob
99

1010
import cson
11-
11+
import subprocess
1212
from .test import git_update
1313

1414
home = os.path.expanduser("~")
@@ -21,7 +21,7 @@ def initialize(config):
2121
- Make directory for storing notes.
2222
- Create History
2323
# ! - Initialize the git repo.
24-
------------------------------------
24+
-----------------s-------------------
2525
called:
2626
- Is called upon using --initialize flag of the CLI
2727
'''
@@ -120,22 +120,22 @@ def ultimate(config):
120120
- updates the .md files, which require it.
121121
-----------------------------------------------
122122
'''
123-
print("Searching for BOOSTNOTE_PATH", end='\r')
124-
sys.stdout.flush()
123+
# print("Searching for BOOSTNOTE_PATH", end='\r')
124+
# sys.stdout.flush()
125125
if not os.path.isfile(os.path.join(config['BOOSTNOTE_PATH'], 'history.json')):
126126

127127
# Create the History json again.
128128
create_history(config['BOOSTNOTE_PATH'])
129129
if boostnote_exists(config['BOOSTNOTE_PATH']):
130130

131131
# Creating History again, as this will track if new files have been added.
132-
sys.stdout.flush()
133-
print("Creating History.json file", end='\r')
132+
# sys.stdout.flush()
133+
# print("Creating History.json file", end='\r')
134134

135135
create_history(config['BOOSTNOTE_PATH'])
136136

137-
sys.stdout.flush()
138-
print("Creation done!", end='\r')
137+
# sys.stdout.flush()
138+
# print("Creation done!", end='\r')
139139

140140
history_json = json.load(open(os.path.join(
141141
config['BOOSTNOTE_PATH'], 'history.json'), 'r'))
@@ -175,7 +175,8 @@ def cson_reader(location):
175175
data = cson.load(open(location, 'r'))
176176
return data
177177
else:
178-
raise FileNotFoundError(f'The cson file at {location} was not found')
178+
return 0
179+
# raise FileNotFoundError(f'The cson file at {location} was not found')
179180

180181

181182
def customshield(
@@ -210,67 +211,67 @@ def markdown_writer(things, location, shields=True,
210211
The dict{} which contains shit that was read via the cson
211212
212213
'''
214+
if things:
215+
embels = ['isStarred', 'isTrashed',
216+
'updatedAt', 'type', 'folder', 'tags']
217+
shelds = []
218+
if shields:
219+
for key in embels:
220+
x = None
221+
if things[key]:
222+
if key == 'isStarred':
223+
shelds.append(customshield(
224+
key, '⭐', color='black', style=options['style']))
213225

214-
embels = ['isStarred', 'isTrashed',
215-
'updatedAt', 'type', 'folder', 'tags']
216-
shelds = []
217-
if shields:
218-
for key in embels:
219-
x = None
220-
if things[key]:
221-
if key == 'isStarred':
222-
shelds.append(customshield(
223-
key, '⭐', color='black', style=options['style']))
224-
225-
if key == 'isTrashed':
226-
shelds.append(customshield(
227-
key, '🗑', color='black', style=options['style']))
228-
229-
elif key == 'updatedAt':
230-
shelds.append(customshield(
231-
key, things[key].split(':')[0][:-3].replace('-', '/'), color='green', style=options['style']))
232-
233-
elif key in ['type', 'folder']:
234-
shelds.append(customshield(
235-
key, things[key], color='blue', style=options['style']))
236-
237-
elif key == 'tags':
238-
if options['option']:
239-
# OPTION 1: {tag| gay} {tag| notgay}
240-
for tag in things[key]:
241-
shelds.append(
242-
customshield(label='tag', message=tag,
243-
color='purple', style=options['style'])
244-
)
245-
else:
246-
# OPTION 2: {tag| gay, notgay}
247-
tags = []
248-
for tag in things[key]:
249-
tags.append(tag)
226+
if key == 'isTrashed':
250227
shelds.append(customshield(
251-
label='tags', message='_'.join(tags), color='blueviolet', style=options['style']))
228+
key, '🗑', color='black', style=options['style']))
252229

253-
file = open(os.path.join(location,
254-
f"{things['title']}.md"), 'w+')
230+
elif key == 'updatedAt':
231+
shelds.append(customshield(
232+
key, things[key].split(':')[0][:-3].replace('-', '/'), color='green', style=options['style']))
255233

256-
for count, shield in enumerate(shelds):
257-
if count != len(shelds) - 1:
258-
file.write(shield)
259-
file.write(' ')
260-
else:
261-
file.write(shield)
262-
file.write('\n')
234+
elif key in ['type', 'folder']:
235+
shelds.append(customshield(
236+
key, things[key], color='blue', style=options['style']))
237+
238+
elif key == 'tags':
239+
if options['option']:
240+
# OPTION 1: {tag| gay} {tag| notgay}
241+
for tag in things[key]:
242+
shelds.append(
243+
customshield(label='tag', message=tag,
244+
color='purple', style=options['style'])
245+
)
246+
else:
247+
# OPTION 2: {tag| gay, notgay}
248+
tags = []
249+
for tag in things[key]:
250+
tags.append(tag)
251+
shelds.append(customshield(
252+
label='tags', message='_'.join(tags), color='blueviolet', style=options['style']))
253+
254+
file = open(os.path.join(location,
255+
f"{things['title']}.md"), 'w+')
256+
257+
for count, shield in enumerate(shelds):
258+
if count != len(shelds) - 1:
259+
file.write(shield)
260+
file.write(' ')
261+
else:
262+
file.write(shield)
263+
file.write('\n')
263264

264-
try:
265-
file.write(things['content'])
265+
try:
266+
file.write(things['content'])
266267

267-
except:
268-
pass
269-
try:
270-
file.write(things['snippets'])
268+
except:
269+
pass
270+
try:
271+
file.write(things['snippets'])
271272

272-
except:
273-
pass
273+
except:
274+
pass
274275

275276

276277
def get_changes(
@@ -289,7 +290,7 @@ def get_changes(
289290
files = []
290291
os.chdir(location)
291292
p = subprocess.Popen(
292-
git_commands.status, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
293+
"git status", shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
293294
for line in p.stdout.readlines():
294295
# Putting checks to see if any rendered file is deleted.
295296
if '.md' in line.decode("utf-8"):
@@ -309,7 +310,7 @@ def get_changes(
309310
def update_changes(
310311
location=os.path.join(home, 'Boostnote')
311312
):
312-
create_history(location)
313+
# create_history(location)
313314
changed_files = get_changes()
314315
history_json = json.load(open(os.path.join(
315316
location, 'history.json'), 'r'))
@@ -352,16 +353,25 @@ def update_changes(
352353
def create_history(
353354
location=os.path.join(home, 'Boostnote')
354355
):
355-
files = {}
356-
for note in get_notes():
357-
files[note.split('/')[-1]] = {
358-
'title': cson.load(open(note, 'r'))['title'],
359-
'updated': False
360-
}
361-
json.dump(
362-
files,
363-
open(os.path.join(location, 'history.json'), 'w+')
364-
)
356+
if os.path.isfile(
357+
os.path.join(location, 'history.json')
358+
):
359+
# FIle already exists, check for changes.
360+
update_changes()
361+
print(1)
362+
363+
else:
364+
print(3)
365+
files = {}
366+
for note in get_notes():
367+
files[note.split('/')[-1]] = {
368+
'title': cson.load(open(note, 'r'))['title'],
369+
'updated': False
370+
}
371+
json.dump(
372+
files,
373+
open(os.path.join(location, 'history.json'), 'w+')
374+
)
365375

366376

367377
def create_readme(config):

0 commit comments

Comments
 (0)