Last change
on this file since 6479b5c was
f298bd7,
checked in by Alex Dehnert <adehnert@…>, 11 years ago
|
Allow using a virtualenv's Python
Rather than starting each script with #!/usr/bin/python, we change to
#!/usr/bin/env python, to allow using Python's supplied by a virtualenv we're
running in.
|
-
Property mode set to
100755
|
File size:
1.1 KB
|
Line | |
---|
1 | #!/usr/bin/env python |
---|
2 | import sys |
---|
3 | import os |
---|
4 | |
---|
5 | if __name__ == '__main__': |
---|
6 | cur_file = os.path.abspath(__file__) |
---|
7 | django_dir = os.path.abspath(os.path.join(os.path.dirname(cur_file), '..')) |
---|
8 | sys.path.append(django_dir) |
---|
9 | os.environ['DJANGO_SETTINGS_MODULE'] = 'settings' |
---|
10 | |
---|
11 | import finance_core.models |
---|
12 | import finance_core.util |
---|
13 | |
---|
14 | if __name__ == '__main__': |
---|
15 | print sys.argv |
---|
16 | if len(sys.argv) > 1: |
---|
17 | base = finance_core.models.BudgetArea.get_by_pathstr(sys.argv[1]) |
---|
18 | accounts = [] |
---|
19 | for line in sys.stdin: |
---|
20 | data = line.strip().split('\t') |
---|
21 | if len(data) == 0: |
---|
22 | # Can this happen? |
---|
23 | # If it does, skip |
---|
24 | pass |
---|
25 | elif len(data) == 1: |
---|
26 | # Just a name. Append None for no account |
---|
27 | data.append(None) |
---|
28 | accounts.append(data) |
---|
29 | elif len(data) == 2: |
---|
30 | name, number = data |
---|
31 | accounts.append((name, int(number))) |
---|
32 | else: |
---|
33 | raise ValueError("Must pass one or two values per line") |
---|
34 | finance_core.util.mass_add_accounts(base, accounts, writeto=sys.stdout) |
---|
Note: See
TracBrowser
for help on using the repository browser.